Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 10 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 11 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 11 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 11 gadiem
pirms 10 gadiem
pirms 12 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 12 gadiem
pirms 10 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 13 gadiem
pirms 12 gadiem
pirms 13 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 11 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
pirms 10 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433
  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Commentary:
  3. ;;; Code:
  4. ;; (and (file-readable-p "~/.dotfiles/emacs.el")
  5. ;; (load-file "~/.dotfiles/emacs.el"))
  6. ;; make directories
  7. (unless (file-directory-p (expand-file-name user-emacs-directory))
  8. (make-directory (expand-file-name user-emacs-directory)))
  9. (let ((d (expand-file-name (concat user-emacs-directory
  10. "lisp"))))
  11. (unless (file-directory-p d)
  12. (make-directory d))
  13. (add-to-list 'load-path d))
  14. (eval-when-compile
  15. (require 'cl nil t))
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17. ;; download library from web
  18. (defun fetch-library (url &optional byte-compile-p force-download-p)
  19. "Download a library from URL and locate it in \"~/emacs.d/lisp/\".
  20. Return nil if library unfound and failed to download,
  21. otherwise the path where the library installed.
  22. If BYTE-COMPILE-P is t byte compile the file after downloading.
  23. If FORCE-DOWNLOAD-P it t ignore exisiting library and always download."
  24. (let* ((dir (expand-file-name (concat user-emacs-directory "lisp/")))
  25. (lib (file-name-sans-extension (file-name-nondirectory url)))
  26. (lpath (concat dir lib ".el"))
  27. (locate-p (locate-library lib)))
  28. (if (or force-download-p (not locate-p))
  29. (if (progn (message "Downloading %s..."
  30. url)
  31. (download-file url
  32. lpath
  33. t))
  34. (progn (message "Downloading %s...done"
  35. url)
  36. (when (and byte-compile-p
  37. (require 'bytecomp nil t))
  38. (and (file-exists-p (byte-compile-dest-file lpath))
  39. (delete-file (byte-compile-dest-file lpath)))
  40. (byte-compile-file lpath)))
  41. (progn (and (file-writable-p lpath)
  42. (delete-file lpath))
  43. (message "Downloading %s...failed"
  44. url))))
  45. (locate-library lib)))
  46. (defun download-file (url path &optional ok-if-already-exists)
  47. "Download file from URL and output to PATH.
  48. IF OK-IF-ALREADY-EXISTS is true force download."
  49. (or
  50. (let ((curl (executable-find "curl")))
  51. (when curl
  52. (if (and (not ok-if-already-exists)
  53. (file-exists-p path))
  54. nil
  55. (and (eq 0
  56. (call-process curl
  57. nil
  58. nil
  59. nil
  60. "--output"
  61. path
  62. url
  63. ))
  64. path))))
  65. (ignore-errors
  66. (require 'url)
  67. (url-copy-file url
  68. path
  69. ok-if-already-exists)
  70. path)))
  71. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  72. ;; package
  73. (defvar my-package-list nil
  74. "Package list just for me.")
  75. (setq my-package-list
  76. '(
  77. markdown-mode
  78. yaml-mode
  79. ;; ack
  80. color-moccur
  81. gtags
  82. )
  83. )
  84. (when (require 'package nil t)
  85. (add-to-list 'package-archives
  86. '("ELPA" . "http://tromey.com/elpa/"))
  87. (add-to-list 'package-archives
  88. '("melpa" . "http://melpa.milkbox.net/packages/")
  89. t)
  90. (add-to-list 'package-archives
  91. '("marmalade" . "http://marmalade-repo.org/packages/"))
  92. (package-initialize)
  93. ;; (package-refresh-contents)
  94. (defun my-auto-install-package ()
  95. "Install packages semi-automatically."
  96. (interactive)
  97. (mapc (lambda (pkg)
  98. (or (package-installed-p pkg)
  99. (locate-library (symbol-name pkg))
  100. (package-install pkg)))
  101. my-package-list))
  102. )
  103. ;; (lazy-load-eval 'sudoku)
  104. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  105. ;; autoload
  106. (defmacro lazy-load-eval (feature &optional functions &rest body)
  107. "Define autoloading FEATURE that defines FUNCTIONS.
  108. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  109. the function same as FEATURE is defined as autoloaded function. BODY is passed
  110. to `eval-after-load'.
  111. When this macro is evaluated, this returns the path to library if FEATURE
  112. found, otherwise returns nil."
  113. (let* ((libname (symbol-name (eval feature)))
  114. (libpath (locate-library libname)))
  115. (and libpath
  116. `(progn
  117. ,@(mapcar (lambda (f)
  118. (unless (fboundp f)
  119. `(progn
  120. (message "Autoloaded function `%S' defined (%s)"
  121. (quote ,f)
  122. ,libpath)
  123. (autoload (quote ,f)
  124. ,libname
  125. ,(concat "Autoloaded function defined in \""
  126. libpath
  127. "\".")
  128. t))))
  129. (or (eval functions)
  130. `(,(eval feature))))
  131. (eval-after-load ,feature
  132. (quote (progn
  133. ,@body)))
  134. (locate-library ,libname)))))
  135. (put 'lazy-load-eval 'lisp-indent-function 2)
  136. (when (lazy-load-eval 'tetris nil
  137. (message "Tetris loaded!"))
  138. (message "Tetris found!"))
  139. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  140. ;; my-idle-hook
  141. (defvar my-idle-hook nil
  142. "Hook run when idle for several secs.")
  143. (defvar my-idle-hook-sec 5
  144. "Second to run `my-idle-hook'.")
  145. (run-with-idle-timer my-idle-hook-sec
  146. t
  147. (lambda ()
  148. (run-hooks 'my-idle-hook)))
  149. ;; (add-hook 'my-idle-hook
  150. ;; (lambda ()
  151. ;; (message "idle hook message")))
  152. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  153. ;; start and quit
  154. (setq inhibit-startup-message t)
  155. (setq confirm-kill-emacs 'y-or-n-p)
  156. (setq gc-cons-threshold (* 1024 1024 4))
  157. (when window-system
  158. (add-to-list 'default-frame-alist '(cursor-type . box))
  159. (add-to-list 'default-frame-alist '(background-color . "white"))
  160. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  161. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  162. ;; does not work?
  163. )
  164. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  165. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  166. (and (fboundp 'tool-bar-mode)
  167. (tool-bar-mode 0))
  168. (and (fboundp 'set-scroll-bar-mode)
  169. (set-scroll-bar-mode nil))
  170. (add-hook 'kill-emacs-hook
  171. ;; load init file when terminating emacs to ensure file is not broken
  172. 'reload-init-file)
  173. (add-hook 'after-init-hook
  174. (lambda ()
  175. (message "%s %s" invocation-name emacs-version)
  176. (message "%s was taken to initialize emacs." (emacs-init-time))
  177. (switch-to-buffer "*Messages*")
  178. ))
  179. (cd ".") ; when using windows use / instead of \ in `default-directory'
  180. ;; locale
  181. (set-language-environment "Japanese")
  182. (set-default-coding-systems 'utf-8-unix)
  183. (prefer-coding-system 'utf-8-unix)
  184. (setq system-time-locale "C")
  185. ;; my prefix map
  186. (defvar my-prefix-map nil
  187. "My prefix map.")
  188. (define-prefix-command 'my-prefix-map)
  189. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  190. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  191. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  192. ;; (comint-show-maximum-output)
  193. ;; kill scratch
  194. (add-hook 'after-init-hook
  195. (lambda ()
  196. (kill-buffer "*scratch*")))
  197. ;; modifier keys
  198. ;; (setq mac-option-modifier 'control)
  199. ;; display
  200. (setq redisplay-dont-pause t)
  201. (setq visible-bell t)
  202. (setq ring-bell-function 'ignore)
  203. (mouse-avoidance-mode 'banish)
  204. (and window-system
  205. (fetch-library
  206. "https://raw.github.com/10sr/emacs-lisp/master/save-window-size.el"
  207. t)
  208. (require 'save-window-size nil t))
  209. (defun reload-init-file ()
  210. "Reload Emacs init file."
  211. (interactive)
  212. (when (file-readable-p user-init-file)
  213. (load-file user-init-file)))
  214. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  215. ;; for windows
  216. (defun start-ckw-bash ()
  217. "Start ckw in windows."
  218. (interactive)
  219. (start-process
  220. "ckw_bash"
  221. nil
  222. "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe"))
  223. ;; command seems to have to be in c drive
  224. (defun my-w32-add-export-path (&rest args)
  225. "Add pathes ARGS for windows."
  226. (mapc (lambda (path)
  227. (add-to-list 'exec-path (expand-file-name path)))
  228. (reverse args))
  229. (setenv "PATH"
  230. (mapconcat 'convert-standard-filename
  231. exec-path
  232. ";")))
  233. (when (eq system-type 'windows-nt)
  234. ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i")
  235. ;; (setq python-python-command "c:/Python26/python.exe")
  236. ;; (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash)
  237. (my-w32-add-export-path "c:/Windows/system"
  238. "c:/Windows/System32"
  239. "c:/Program Files/Git/bin"
  240. "c:/MinGW/bin"
  241. "c:/MinGW/mingw32/bin"
  242. (expand-file-name "~/.local/bin")
  243. (expand-file-name "~/dbx/apps/bin"))
  244. (when window-system
  245. (setq w32-enable-synthesized-fonts t))
  246. (setq w32-apps-modifier 'meta)
  247. (setq file-name-coding-system 'sjis))
  248. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  249. ;; global keys
  250. (global-set-key (kbd "<up>") (lambda() (interactive) (scroll-down 1)))
  251. (global-set-key (kbd "<down>") (lambda() (interactive) (scroll-up 1)))
  252. (global-set-key (kbd "<left>") 'scroll-down)
  253. (global-set-key (kbd "<right>") 'scroll-up)
  254. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  255. (global-set-key (kbd "C-\\") help-map)
  256. (define-key ctl-x-map (kbd "DEL") help-map)
  257. (define-key ctl-x-map (kbd "C-h") help-map)
  258. (define-key help-map "a" 'apropos)
  259. ;; disable annoying keys
  260. (global-set-key [prior] 'ignore)
  261. (global-set-key (kbd "<next>") 'ignore)
  262. (global-set-key [menu] 'ignore)
  263. (global-set-key [down-mouse-1] 'ignore)
  264. (global-set-key [down-mouse-2] 'ignore)
  265. (global-set-key [down-mouse-3] 'ignore)
  266. (global-set-key [mouse-1] 'ignore)
  267. (global-set-key [mouse-2] 'ignore)
  268. (global-set-key [mouse-3] 'ignore)
  269. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  270. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  271. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  272. ;; title and mode-line
  273. (when (fetch-library
  274. "https://raw.github.com/10sr/emacs-lisp/master/terminal-title.el"
  275. t)
  276. (require 'terminal-title nil t)
  277. ;; if TERM is not screen use default value
  278. (if (getenv "TMUX")
  279. ;; if use tmux locally just basename of current dir
  280. (setq terminal-title-format
  281. '((file-name-nondirectory (directory-file-name
  282. default-directory))))
  283. (when (equal (car (split-string (frame-parameter nil
  284. 'tty-type)
  285. "-"))
  286. "screen")
  287. (if (getenv "SSH_CONNECTION")
  288. ;; TMUX is not set but TERM is screen:
  289. ;; it seems that TMUX is used by locally and ssh to remote host
  290. (setq terminal-title-format
  291. `("em:"
  292. ,user-login-name
  293. "@"
  294. ,(car (split-string system-name
  295. "\\."))
  296. ":"
  297. (file-name-nondirectory (directory-file-name
  298. default-directory))))
  299. ;; this wont happen? (TMUX is not set, TERM is screen, not ssh-ed)
  300. (setq terminal-title-format
  301. '((file-name-nondirectory (directory-file-name
  302. default-directory)))))))
  303. (terminal-title-mode))
  304. (setq eol-mnemonic-dos "\\r\\n")
  305. (setq eol-mnemonic-mac "\\r")
  306. (setq eol-mnemonic-unix "\\n")
  307. (which-function-mode 0)
  308. (line-number-mode 0)
  309. (column-number-mode 0)
  310. (size-indication-mode 0)
  311. (setq mode-line-position
  312. '(:eval (format "L%%l/%d,C%%c"
  313. (count-lines (point-max)
  314. (point-min)))))
  315. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  316. ;; display date
  317. (add-hook 'after-init-hook
  318. (lambda ()
  319. (when display-time-mode
  320. (display-time-update))
  321. ))
  322. (when (require 'time nil t)
  323. (setq display-time-interval 29)
  324. (setq display-time-day-and-date t)
  325. (setq display-time-format "%a, %d %b %Y %T")
  326. (if window-system
  327. (display-time-mode 0)
  328. (display-time-mode 1)))
  329. ;; ;; current directory
  330. ;; (let ((ls (member 'mode-line-buffer-identification
  331. ;; mode-line-format)))
  332. ;; (setcdr ls
  333. ;; (cons '(:eval (concat " ("
  334. ;; (abbreviate-file-name default-directory)
  335. ;; ")"))
  336. ;; (cdr ls))))
  337. ;; ;; display last modified time
  338. ;; (let ((ls (member 'mode-line-buffer-identification
  339. ;; mode-line-format)))
  340. ;; (setcdr ls
  341. ;; (cons '(:eval (concat " "
  342. ;; my-buffer-file-last-modified-time))
  343. ;; (cdr ls))))
  344. (defun buffer-list-not-start-with-space ()
  345. "Return a list of buffers that not start with whitespaces."
  346. (let ((bl (buffer-list))
  347. b nbl)
  348. (while bl
  349. (setq b (pop bl))
  350. (unless (string-equal " "
  351. (substring (buffer-name b)
  352. 0
  353. 1))
  354. (add-to-list 'nbl b)))
  355. nbl))
  356. ;; http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/
  357. ;; (add-to-list 'minor-mode-alist
  358. ;; '(global-whitespace-mode ""))
  359. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  360. ;; system info
  361. (defun my-message-current-info ()
  362. "Echo current login name, hostname and directory."
  363. (interactive)
  364. (message "%s@%s:%s"
  365. user-login-name
  366. system-name
  367. (abbreviate-file-name default-directory)))
  368. ;; (run-with-idle-timer 3
  369. ;; t
  370. ;; 'my-message-current-info)
  371. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  372. ;; minibuffer
  373. (setq insert-default-directory t)
  374. (setq completion-ignore-case t
  375. read-file-name-completion-ignore-case t
  376. read-buffer-completion-ignore-case t)
  377. (setq resize-mini-windows t)
  378. (temp-buffer-resize-mode 1)
  379. (savehist-mode 1)
  380. (fset 'yes-or-no-p 'y-or-n-p)
  381. ;; complete symbol when `eval'
  382. (define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol)
  383. (define-key minibuffer-local-map (kbd "C-u")
  384. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  385. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  386. ;; letters, font-lock mode and fonts
  387. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  388. ;; (set-window-margins (selected-window) 1 1)
  389. (and (or (eq system-type 'Darwin)
  390. (eq system-type 'darwin))
  391. (fboundp 'mac-set-input-method-parameter)
  392. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  393. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  394. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  395. (boundp 'input-method-inactivate-hook))
  396. (add-hook 'input-method-activate-hook
  397. (lambda () (set-cursor-color "red")))
  398. (add-hook 'input-method-inactivate-hook
  399. (lambda () (set-cursor-color "black"))))
  400. (when (require 'paren nil t)
  401. (show-paren-mode 1)
  402. (setq show-paren-delay 0.5
  403. show-paren-style 'parenthesis) ; mixed is hard to read
  404. (set-face-background 'show-paren-match
  405. (face-foreground 'default))
  406. (set-face-inverse-video-p 'show-paren-match
  407. t))
  408. (transient-mark-mode 1)
  409. (global-font-lock-mode 1)
  410. (setq font-lock-global-modes
  411. '(not
  412. help-mode
  413. eshell-mode
  414. term-mode
  415. Man-mode))
  416. ;; (standard-display-ascii ?\n "$\n")
  417. (defvar my-eol-face
  418. '(("\n" . (0 font-lock-comment-face t nil)))
  419. )
  420. (defvar my-tab-face
  421. '(("\t" . '(0 highlight t nil))))
  422. (defvar my-jspace-face
  423. '(("\u3000" . '(0 highlight t nil))))
  424. (add-hook 'font-lock-mode-hook
  425. (lambda ()
  426. ;; (font-lock-add-keywords nil my-eol-face)
  427. (font-lock-add-keywords nil my-jspace-face)
  428. ))
  429. (when (require 'whitespace nil t)
  430. (add-to-list 'whitespace-display-mappings ; not work
  431. `(tab-mark ?\t ,(vconcat "^I\t")))
  432. (add-to-list 'whitespace-display-mappings
  433. `(newline-mark ?\n ,(vconcat "$\n")))
  434. (setq whitespace-style '(face
  435. trailing ; trailing blanks
  436. newline ; newlines
  437. newline-mark ; use display table for newline
  438. ;; tab-mark
  439. empty ; empty lines at beg or end of buffer
  440. lines-tail ; lines over 80
  441. ))
  442. ;; (setq whitespace-newline 'font-lock-comment-face)
  443. (global-whitespace-mode t)
  444. (when (eq (display-color-cells)
  445. 256)
  446. (set-face-foreground 'whitespace-newline "brightblack")))
  447. (and nil
  448. (fetch-library
  449. "http://www.emacswiki.org/emacs/download/fill-column-indicator.el"
  450. t)
  451. (require 'fill-column-indicator nil t)
  452. (setq fill-column-indicator))
  453. ;; highlight current line
  454. ;; http://wiki.riywo.com/index.php?Meadow
  455. (defface my-hl-line
  456. '((((min-colors 256)
  457. (background dark))
  458. (:background "color-234"))
  459. (((min-colors 256)
  460. (background light))
  461. (:background "color-234"))
  462. (t
  463. (:underline "black")))
  464. "*Face used by hl-line.")
  465. (setq hl-line-face 'my-hl-line) ;; (setq hl-line-face nil)
  466. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  467. (setq hl-line-global-modes
  468. '(not
  469. term-mode))
  470. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  471. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  472. ;; fonts
  473. (defun my-set-ascii-and-jp-font (list)
  474. "Set font configuration List."
  475. (let ((fspec1 (if (> emacs-major-version 22)
  476. ;; font spec is available in emacs23 and later
  477. (font-spec :family (nth 2 list) :size (nth 3 list))
  478. (cons (nth 2 list) "jisx0208.*")))
  479. (fspec2 (if (> emacs-major-version 22)
  480. (font-spec :family (nth 2 list) :size (nth 3 list))
  481. (cons (nth 2 list) "jisx0201.*"))))
  482. (set-face-attribute 'default nil
  483. :family (nth 0 list)
  484. :height (nth 1 list))
  485. (set-fontset-font "fontset-default"
  486. 'japanese-jisx0208
  487. fspec1)
  488. (set-fontset-font "fontset-default"
  489. 'katakana-jisx0201
  490. fspec2)))
  491. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 90 "takaogothic" 13))
  492. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "takaogothic" 14))
  493. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "ms gothic" 14))
  494. ;; (my-set-ascii-and-jp-font '("monaco" 75 "takaogothic" 11))
  495. ;; (my-set-ascii-and-jp-font '("monaco" 90 "takaogothic" 13))
  496. ;; (my-set-ascii-and-jp-font '("ProggyCleanTTSZ" 120 "takaogothic" 11))
  497. ;; あ a
  498. (and (fetch-library
  499. "https://raw.github.com/10sr/emacs-lisp/master/set-modeline-color.el"
  500. t)
  501. (progn
  502. (require 'set-modeline-color nil t)))
  503. (let ((fg (face-foreground 'default))
  504. (bg (face-background 'default)))
  505. (set-face-background 'mode-line-inactive
  506. (if (face-inverse-video-p 'mode-line) fg bg))
  507. (set-face-foreground 'mode-line-inactive
  508. (if (face-inverse-video-p 'mode-line) bg fg)))
  509. (set-face-underline 'mode-line-inactive
  510. t)
  511. (set-face-underline 'vertical-border
  512. nil)
  513. (and (fetch-library
  514. "https://raw.github.com/tarao/elisp/master/end-mark.el"
  515. t)
  516. (require 'end-mark nil t)
  517. (global-end-mark-mode))
  518. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  519. ;; file handling
  520. (setq revert-without-query '(".+"))
  521. ;; save cursor position
  522. (setq save-place-file (concat user-emacs-directory
  523. "places"))
  524. (when (require 'saveplace nil t)
  525. (setq-default save-place t))
  526. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  527. (setq make-backup-files t)
  528. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  529. (setq backup-directory-alist
  530. (cons (cons "\\.*$" (expand-file-name "~/.emacs.d/backup"))
  531. backup-directory-alist))
  532. (setq version-control 'never)
  533. (setq delete-old-versions t)
  534. (setq auto-save-list-file-prefix (expand-file-name "~/.emacs.d/auto-save/"))
  535. (setq delete-auto-save-files t)
  536. (add-to-list 'completion-ignored-extensions ".bak")
  537. ;; (setq delete-by-moving-to-trash t
  538. ;; trash-directory "~/.emacs.d/trash")
  539. (add-hook 'after-save-hook
  540. 'executable-make-buffer-file-executable-if-script-p)
  541. (setq bookmark-default-file "~/.emacs.d/bmk")
  542. (add-hook 'recentf-load-hook
  543. (lambda ()
  544. (add-to-list 'recentf-exclude
  545. (regexp-quote bookmark-default-file))))
  546. (and (fetch-library
  547. "https://raw.github.com/10sr/emacs-lisp/master/read-only-only-mode.el"
  548. t)
  549. (lazy-load-eval 'read-only-only-mode))
  550. (and (fetch-library
  551. "https://raw.github.com/10sr/emacs-lisp/master/smart-revert.el"
  552. t)
  553. (require 'smart-revert nil t)
  554. (smart-revert-on))
  555. ;; autosave
  556. (and (fetch-library
  557. "https://raw.github.com/10sr/emacs-lisp/master/autosave.el"
  558. t)
  559. (require 'autosave nil t)
  560. (autosave-set 2))
  561. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  562. ;; editting
  563. (defun my-copy-whole-line ()
  564. "Copy whole line."
  565. (interactive)
  566. (kill-new (concat (buffer-substring (point-at-bol)
  567. (point-at-eol))
  568. "\n")))
  569. (setq require-final-newline t)
  570. (setq kill-whole-line t)
  571. (setq scroll-conservatively 35
  572. scroll-margin 2
  573. scroll-step 0)
  574. (setq-default major-mode 'text-mode)
  575. (setq next-line-add-newlines nil)
  576. (setq kill-read-only-ok t)
  577. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  578. ;; (setq-default line-spacing 0.2)
  579. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  580. (setq-default tab-width 4)
  581. (setq-default indent-tabs-mode nil)
  582. (setq-default indent-line-function nil)
  583. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  584. (delete-selection-mode 1)
  585. (cua-mode 0)
  586. (setq line-move-visual nil)
  587. ;; key bindings
  588. ;; moving around
  589. ;; (global-set-key (kbd "M-j") 'next-line)
  590. ;; (global-set-key (kbd "M-k") 'previous-line)
  591. ;; (global-set-key (kbd "M-h") 'backward-char)
  592. ;; (global-set-key (kbd "M-l") 'forward-char)
  593. ;;(keyboard-translate ?\M-j ?\C-j)
  594. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  595. (define-key esc-map "p" 'backward-paragraph)
  596. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  597. (define-key esc-map "n" 'forward-paragraph)
  598. (global-set-key (kbd "C-<up>") (lambda () (interactive)(scroll-down 1)))
  599. (global-set-key (kbd "C-<down>") (lambda () (interactive)(scroll-up 1)))
  600. (global-set-key (kbd "C-<left>") 'scroll-down)
  601. (global-set-key (kbd "C-<right>") 'scroll-up)
  602. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  603. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  604. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  605. ;; C-h and DEL
  606. (global-set-key (kbd "C-h") (kbd "DEL"))
  607. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  608. (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  609. (define-key esc-map "k" 'my-copy-whole-line)
  610. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  611. (define-key esc-map "u" 'undo)
  612. (define-key esc-map "i" (kbd "ESC TAB"))
  613. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  614. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  615. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  616. (define-key my-prefix-map (kbd "C-o") 'occur)
  617. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  618. ;; japanese input method
  619. (defun my-load-scim ()
  620. "Use scim-bridge.el as japanese im."
  621. ;; Load scim-bridge.
  622. (when (require 'scim-bridge nil t)
  623. ;; Turn on scim-mode automatically after loading .emacs
  624. (add-hook 'after-init-hook 'scim-mode-on)
  625. (setq scim-cursor-color "red")
  626. (scim-define-preedit-key ?\^h t)
  627. (scim-define-common-key ?\* nil)
  628. (scim-define-common-key ?\^/ nil)))
  629. (defun my-load-anthy ()
  630. "Use anthy.el as japanese im."
  631. ;; anthy
  632. (when (require 'anthy nil t)
  633. (global-set-key
  634. (kbd "<muhenkan>") (lambda () (interactive) (anthy-mode-off)))
  635. (global-set-key (kbd "<henkan>") (lambda () (interactive) (anthy-mode-on)))
  636. (when (>= emacs-major-version 23)
  637. (setq anthy-accept-timeout 1))))
  638. ;; quail
  639. ;; aproposs input-method for some information
  640. ;; (setq default-input-method "japanese")
  641. (defun my-load-mozc-el ()
  642. "Use mozc.el as japanese im."
  643. (setq mozc-leim-title "[MZ]")
  644. (when (require 'mozc nil t)
  645. (setq defauit-input-method "japanese-mozc")
  646. ))
  647. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  648. ;; gmail
  649. (setq mail-interactive t
  650. send-mail-function 'smtpmail-send-it
  651. ;; message-send-mail-function 'smtpmail-send-it
  652. smtpmail-smtp-server "smtp.gmail.com"
  653. smtpmail-smtp-service 587
  654. smtpmail-starttls-credentials '(("smtp.gmail.com" 587
  655. "8.slashes@gmail.com" nil))
  656. smtpmail-auth-credentials '(("smtp.gmail.com" 587
  657. "8.slashes@gmail.com" nil))
  658. user-mail-address "8.slashes@gmail.com")
  659. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  660. ;; buffer killing
  661. ;; (defun my-delete-window-killing-buffer () nil)
  662. (defun my-query-kill-current-buffer ()
  663. "Interactively kill current buffer."
  664. (interactive)
  665. (if (y-or-n-p (concat "kill current buffer? :"))
  666. (kill-buffer (current-buffer))))
  667. (substitute-key-definition 'kill-buffer
  668. 'my-query-kill-current-buffer
  669. global-map)
  670. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  671. (defun my-kill-buffers ()
  672. "Kill buffers that visit files."
  673. (interactive)
  674. (mapcar (lambda (buf)
  675. (when (buffer-file-name buf)
  676. (kill-buffer buf)))
  677. (buffer-list)))
  678. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  679. ;; share clipboard with x
  680. ;; this page describes this in details, but only these sexps seem to be needed
  681. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  682. (and (not window-system)
  683. (not (eq window-system 'mac))
  684. (getenv "DISPLAY")
  685. (not (equal (getenv "DISPLAY") ""))
  686. (executable-find "xclip")
  687. ;; (< emacs-major-version 24)
  688. (fetch-library "http://www.emacswiki.org/emacs/download/xclip.el" t)
  689. (require 'xclip nil t)
  690. (turn-on-xclip))
  691. (and (eq system-type 'darwin)
  692. (fetch-library
  693. "https://raw.github.com/10sr/emacs-lisp/master/pasteboard.el"
  694. t)
  695. (require 'pasteboard nil t)
  696. (turn-on-pasteboard)
  697. (getenv "TMUX")
  698. (pasteboard-enable-rtun))
  699. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  700. ;; https://github.com/lunaryorn/flycheck
  701. (when (require 'flycheck nil t)
  702. (add-hook 'after-init-hook 'global-flycheck-mode))
  703. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  704. ;; window
  705. (and (fetch-library
  706. "https://raw.github.com/10sr/emacs-lisp/master/window-organizer.el"
  707. t)
  708. (lazy-load-eval 'window-organizer)
  709. (define-key ctl-x-map (kbd "w") 'window-organizer))
  710. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  711. ;; some modes and hooks
  712. (and (fetch-library
  713. "https://raw.github.com/10sr/emacs-lisp/master/remember-major-modes-mode.el"
  714. t)
  715. (require 'remember-major-modes-mode nil t)
  716. (remember-major-modes-mode 1)
  717. )
  718. ;; Detect file type from shebang and set major-mode.
  719. (add-to-list 'interpreter-mode-alist
  720. '("python3" . python-mode))
  721. (add-to-list 'interpreter-mode-alist
  722. '("python2" . python-mode))
  723. ;; http://fukuyama.co/foreign-regexp
  724. '(and (fetch-library
  725. "https://raw.github.com/k-talo/foreign-regexp.el/master/foreign-regexp.el"
  726. t)
  727. (require 'foreign-regexp nil t)
  728. (progn
  729. (setq foreign-regexp/regexp-type 'perl)
  730. '(setq reb-re-syntax 'foreign-regexp)
  731. ))
  732. (require 'session nil t)
  733. (lazy-load-eval 'sql '(sql-mode)
  734. (require 'sql-indent nil t))
  735. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/gtkbm.el"
  736. t)
  737. (lazy-load-eval 'gtkbm)
  738. (global-set-key (kbd "C-x C-d") 'gtkbm))
  739. (and (fetch-library
  740. "https://raw.github.com/10sr/emacs-lisp/master/git-command.el"
  741. t)
  742. (lazy-load-eval 'git-command
  743. nil
  744. (add-to-list 'git-command-major-mode-alist
  745. '("di" . diff-mode))
  746. (add-to-list 'git-command-major-mode-alist
  747. '("graph" . fundamental-mode))
  748. (add-to-list 'git-command-major-mode-alist
  749. '("log" . fundamental-mode)))
  750. ;; (setq git-command-default-options "-c color.ui=always")
  751. (define-key ctl-x-map "g" 'git-command))
  752. (and (fetch-library
  753. "http://www.emacswiki.org/emacs/download/sl.el"
  754. t)
  755. (lazy-load-eval 'sl))
  756. (defalias 'qcalc 'quick-calc)
  757. (require 'simple nil t)
  758. (add-hook 'makefile-mode-hook
  759. (lambda ()
  760. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  761. ;; this functions is set in write-file-functions, i cannot find any
  762. ;; good way to remove this.
  763. (fset 'makefile-warn-suspicious-lines 'ignore)
  764. ))
  765. (add-hook 'verilog-mode-hook
  766. (lambda ()
  767. (define-key verilog-mode-map ";" 'self-insert-command)))
  768. (setq diff-switches "-u")
  769. (add-hook 'diff-mode-hook
  770. (lambda ()
  771. (view-mode 1)
  772. (set-face-attribute 'diff-header nil
  773. :foreground nil
  774. :background nil
  775. :weight 'bold)
  776. (set-face-attribute 'diff-file-header nil
  777. :foreground nil
  778. :background nil
  779. :weight 'bold)
  780. (set-face-foreground 'diff-index-face "blue")
  781. (set-face-attribute 'diff-hunk-header nil
  782. :foreground "cyan"
  783. :weight 'normal)
  784. (set-face-attribute 'diff-context nil
  785. ;; :foreground "white"
  786. :foreground nil
  787. :weight 'normal)
  788. (set-face-foreground 'diff-removed-face "red")
  789. (set-face-foreground 'diff-added-face "green")
  790. (set-face-background 'diff-removed-face nil)
  791. (set-face-background 'diff-added-face nil)
  792. (set-face-attribute 'diff-changed nil
  793. :foreground "magenta"
  794. :weight 'normal)
  795. ))
  796. ;; (ffap-bindings)
  797. (add-hook 'sh-mode-hook
  798. (lambda ()
  799. (define-key sh-mode-map
  800. (kbd "C-x C-e")
  801. 'my-execute-shell-command-current-line)))
  802. (setq sh-here-document-word "__EOC__")
  803. (defun my-execute-shell-command-current-line ()
  804. "Run current line as shell command."
  805. (interactive)
  806. (shell-command (buffer-substring-no-properties (point-at-bol)
  807. (point))))
  808. (setq auto-mode-alist
  809. `(("autostart\\'" . sh-mode)
  810. ("xinitrc\\'" . sh-mode)
  811. ("xprograms\\'" . sh-mode)
  812. ("PKGBUILD\\'" . sh-mode)
  813. ,@auto-mode-alist))
  814. (and (lazy-load-eval 'pkgbuild-mode)
  815. (setq auto-mode-alist (append '(("PKGBUILD\\'" . pkgbuild-mode))
  816. auto-mode-alist)))
  817. (add-hook 'html-mode-hook
  818. (lambda ()
  819. (define-key html-mode-map (kbd "C-m")
  820. 'reindent-then-newline-and-indent)))
  821. (add-hook 'text-mode-hook
  822. (lambda ()
  823. (define-key text-mode-map (kbd "C-m") 'newline)))
  824. (add-to-list 'Info-default-directory-list
  825. (expand-file-name "~/.info/emacs-ja"))
  826. (add-hook 'apropos-mode-hook
  827. (lambda ()
  828. (define-key apropos-mode-map "n" 'next-line)
  829. (define-key apropos-mode-map "p" 'previous-line)
  830. ))
  831. (add-hook 'isearch-mode-hook
  832. (lambda ()
  833. ;; (define-key isearch-mode-map
  834. ;; (kbd "C-j") 'isearch-other-control-char)
  835. ;; (define-key isearch-mode-map
  836. ;; (kbd "C-k") 'isearch-other-control-char)
  837. ;; (define-key isearch-mode-map
  838. ;; (kbd "C-h") 'isearch-other-control-char)
  839. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  840. (define-key isearch-mode-map (kbd "M-r")
  841. 'isearch-query-replace-regexp)))
  842. (add-hook 'outline-mode-hook
  843. (lambda ()
  844. (if (string-match "\\.md\\'" buffer-file-name)
  845. (set (make-local-variable 'outline-regexp) "#+ "))))
  846. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  847. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  848. (when (fetch-library
  849. "http://jblevins.org/projects/markdown-mode/markdown-mode.el"
  850. t)
  851. (lazy-load-eval 'markdown-mode)
  852. (setq markdown-command (or (executable-find "markdown")
  853. (executable-find "markdown.pl")))
  854. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'markdown-mode))
  855. (add-hook 'markdown-mode-hook
  856. (lambda ()
  857. (outline-minor-mode 1)
  858. (flyspell-mode)
  859. (set (make-local-variable 'comment-start) ";"))))
  860. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  861. ;; c-mode
  862. ;; (setq c-default-style "bsd")
  863. (add-hook 'c-mode-common-hook
  864. (lambda ()
  865. (setq c-basic-offset 4
  866. indent-tabs-mode nil)
  867. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  868. (c-toggle-hungry-state -1)
  869. ;; (and (require 'gtags nil t)
  870. ;; (gtags-mode 1))
  871. ))
  872. (when (fetch-library
  873. "https://raw.github.com/mooz/js2-mode/master/js2-mode.el"
  874. t)
  875. (lazy-load-eval 'js2-mode)
  876. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  877. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  878. (add-hook 'js2-mode-hook
  879. (lambda ()
  880. (define-key js2-mode-map (kbd "C-m") (lambda ()
  881. (interactive)
  882. (js2-enter-key)
  883. (indent-for-tab-command)))
  884. ;; (add-hook (kill-local-variable 'before-save-hook)
  885. ;; 'js2-before-save)
  886. ;; (add-hook 'before-save-hook
  887. ;; 'my-indent-buffer
  888. ;; nil
  889. ;; t)
  890. )))
  891. (require 'js-doc nil t)
  892. (when (require 'uniquify nil t)
  893. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  894. (setq uniquify-ignore-buffers-re "*[^*]+*")
  895. (setq uniquify-min-dir-content 1))
  896. (add-hook 'view-mode-hook
  897. (lambda()
  898. (define-key view-mode-map "j"
  899. (lambda() (interactive) (scroll-up 1)))
  900. (define-key view-mode-map "k"
  901. (lambda() (interactive) (scroll-down 1)))
  902. (define-key view-mode-map "v" 'toggle-read-only)
  903. (define-key view-mode-map "q" 'bury-buffer)
  904. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  905. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  906. ;; (define-key view-mode-map
  907. ;; "n" 'nonincremental-repeat-search-forward)
  908. ;; (define-key view-mode-map
  909. ;; "N" 'nonincremental-repeat-search-backward)
  910. (define-key view-mode-map "/" 'isearch-forward-regexp)
  911. (define-key view-mode-map "?" 'isearch-backward-regexp)
  912. (define-key view-mode-map "n" 'isearch-repeat-forward)
  913. (define-key view-mode-map "N" 'isearch-repeat-backward)
  914. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point)
  915. ))
  916. (global-set-key "\M-r" 'view-mode)
  917. (setq view-read-only t)
  918. ;; (defun my-view-mode-search-word (word)
  919. ;; "Search for word current directory and subdirectories.
  920. ;; If called intearctively, find word at point."
  921. ;; (interactive (list (thing-at-point 'symbol)))
  922. ;; (if word
  923. ;; (if (and (require 'gtags nil t)
  924. ;; (gtags-get-rootpath))
  925. ;; (gtags-goto-tag word "s")
  926. ;; (my-rgrep word))
  927. ;; (message "No word at point.")
  928. ;; nil))
  929. (add-hook 'Man-mode-hook
  930. (lambda ()
  931. (view-mode 1)
  932. (setq truncate-lines nil)))
  933. (setq Man-notify-method (if window-system
  934. 'newframe
  935. 'aggressive))
  936. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  937. ;; python
  938. (when (lazy-load-eval 'python '(python-mode))
  939. (setq python-python-command (or (executable-find "python3")
  940. (executable-find "python")))
  941. ;; (defun my-python-run-as-command ()
  942. ;; ""
  943. ;; (interactive)
  944. ;; (shell-command (concat python-python-command " " buffer-file-name)))
  945. (defun my-python-display-python-buffer ()
  946. ""
  947. (interactive)
  948. (set-window-text-height (display-buffer python-buffer
  949. t)
  950. 7))
  951. (add-hook 'python-mode-hook
  952. (lambda ()
  953. (define-key python-mode-map
  954. (kbd "C-c C-e") 'my-python-run-as-command)
  955. (define-key python-mode-map
  956. (kbd "C-c C-b") 'my-python-display-python-buffer)
  957. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)))
  958. (add-hook 'inferior-python-mode-hook
  959. (lambda ()
  960. (my-python-display-python-buffer)
  961. (define-key inferior-python-mode-map
  962. (kbd "<up>") 'comint-previous-input)
  963. (define-key inferior-python-mode-map
  964. (kbd "<down>") 'comint-next-input))))
  965. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  966. ;; GNU GLOBAL(gtags)
  967. ;; http://uguisu.skr.jp/Windows/gtags.html
  968. ;; http://eigyr.dip.jp/gtags.html
  969. ;; http://cha.la.coocan.jp/doc/gnu_global.html
  970. (let ((d "/opt/local/share/gtags/"))
  971. (and (file-directory-p d)
  972. (add-to-list 'load-path
  973. d)))
  974. (when (lazy-load-eval 'gtags '(gtags-mode))
  975. (add-hook 'gtags-mode-hook
  976. (lambda ()
  977. (view-mode gtags-mode)
  978. (setq gtags-select-buffer-single t)
  979. ;; (local-set-key "\M-t" 'gtags-find-tag)
  980. ;; (local-set-key "\M-r" 'gtags-find-rtag)
  981. ;; (local-set-key "\M-s" 'gtags-find-symbol)
  982. ;; (local-set-key "\C-t" 'gtags-pop-stack)
  983. (define-key gtags-mode-map (kbd "C-x t h")
  984. 'gtags-find-tag-from-here)
  985. (define-key gtags-mode-map (kbd "C-x t t") 'gtags-find-tag)
  986. (define-key gtags-mode-map (kbd "C-x t r") 'gtags-find-rtag)
  987. (define-key gtags-mode-map (kbd "C-x t s") 'gtags-find-symbol)
  988. (define-key gtags-mode-map (kbd "C-x t p") 'gtags-find-pattern)
  989. (define-key gtags-mode-map (kbd "C-x t f") 'gtags-find-file)
  990. (define-key gtags-mode-map (kbd "C-x t b") 'gtags-pop-stack) ;back
  991. ))
  992. (add-hook 'gtags-select-mode-hook
  993. (lambda ()
  994. (define-key gtags-select-mode-map (kbd "C-m") 'gtags-select-tag)
  995. ))
  996. )
  997. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  998. ;; term mode
  999. ;; (setq multi-term-program shell-file-name)
  1000. (and (fetch-library "http://www.emacswiki.org/emacs/download/multi-term.el"
  1001. t)
  1002. (lazy-load-eval 'multi-term)
  1003. (progn
  1004. (setq multi-term-switch-after-close nil)
  1005. (setq multi-term-dedicated-select-after-open-p t)
  1006. (setq multi-term-dedicated-window-height 20)))
  1007. (when (lazy-load-eval 'term '(term ansi-term))
  1008. (defun my-term-quit-or-send-raw ()
  1009. ""
  1010. (interactive)
  1011. (if (get-buffer-process (current-buffer))
  1012. (call-interactively 'term-send-raw)
  1013. (kill-buffer)))
  1014. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  1015. ;; (setq term-ansi-default-program shell-file-name)
  1016. (add-hook 'term-setup-hook
  1017. (lambda ()
  1018. (setq term-display-table (make-display-table))))
  1019. (add-hook 'term-mode-hook
  1020. (lambda ()
  1021. (unless (memq (current-buffer)
  1022. (and (featurep 'multi-term)
  1023. ;; current buffer is not multi-term buffer
  1024. (multi-term-list)))
  1025. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  1026. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  1027. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  1028. ;; (define-key term-raw-map "\C-f" 'forward-char)
  1029. ;; (define-key term-raw-map "\C-b" 'backward-char)
  1030. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  1031. (define-key term-raw-map
  1032. "\C-x" (lookup-key (current-global-map) "\C-x"))
  1033. (define-key term-raw-map
  1034. "\C-z" (lookup-key (current-global-map) "\C-z"))
  1035. )
  1036. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  1037. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  1038. (define-key term-raw-map (kbd "<up>")
  1039. (lambda () (interactive) (scroll-down 1)))
  1040. (define-key term-raw-map (kbd "<down>")
  1041. (lambda () (interactive) (scroll-up 1)))
  1042. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  1043. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  1044. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  1045. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  1046. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  1047. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  1048. (define-key term-raw-map [delete] 'term-send-raw)
  1049. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  1050. (define-key term-raw-map "\C-y" 'term-paste)
  1051. (define-key term-raw-map
  1052. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  1053. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  1054. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  1055. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  1056. ;; (define-key term-raw-map "\C-d" 'delete-char)
  1057. (set (make-local-variable 'scroll-margin) 0)
  1058. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  1059. ;; (cua-mode 0)
  1060. ;; (and cua-mode
  1061. ;; (local-unset-key (kbd "C-c")))
  1062. ;; (define-key cua--prefix-override-keymap
  1063. ;;"\C-c" 'term-interrupt-subjob)
  1064. (set (make-local-variable 'hl-line-range-function)
  1065. (lambda ()
  1066. '(0 . 0)))
  1067. ))
  1068. ;; (add-hook 'term-exec-hook 'forward-char)
  1069. )
  1070. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1071. ;; buffer switching
  1072. (when (lazy-load-eval 'bs '(bs-show)
  1073. ;; (add-to-list 'bs-configurations
  1074. ;; '("processes" nil get-buffer-process ".*" nil nil))
  1075. (add-to-list 'bs-configurations
  1076. '("this-frame" nil (lambda (buf)
  1077. (memq buf (my-frame-buffer-get)))
  1078. ".*" nil nil))
  1079. (add-to-list 'bs-configurations
  1080. '("files-and-terminals" nil nil nil
  1081. (lambda (buf)
  1082. (and (bs-visits-non-file buf)
  1083. (save-excursion
  1084. (set-buffer buf)
  1085. (not (memq major-mode
  1086. '(term-mode
  1087. eshell-mode))))))))
  1088. ;; (setq bs-configurations (list
  1089. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1090. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1091. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1092. )
  1093. ;; (global-set-key "\C-x\C-b" 'bs-show)
  1094. (defalias 'list-buffers 'bs-show)
  1095. (setq bs-default-configuration "files-and-terminals")
  1096. (setq bs-default-sort-name "by nothing")
  1097. (add-hook 'bs-mode-hook
  1098. (lambda ()
  1099. ;; (setq bs-default-configuration "files")
  1100. ;; (and bs--show-all
  1101. ;; (call-interactively 'bs-toggle-show-all))
  1102. (set (make-local-variable 'scroll-margin) 0))))
  1103. (iswitchb-mode 1)
  1104. (defun iswitchb-buffer-display-other-window ()
  1105. "Do iswitchb in other window."
  1106. (interactive)
  1107. (let ((iswitchb-default-method 'display))
  1108. (call-interactively 'iswitchb-buffer)))
  1109. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1110. ;; sdic
  1111. (when (lazy-load-eval 'sdic '(sdic-describe-word-at-point))
  1112. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  1113. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo)
  1114. (defun sdic-describe-word-at-point-echo ()
  1115. ""
  1116. (interactive)
  1117. (save-window-excursion
  1118. (sdic-describe-word-at-point))
  1119. (save-excursion
  1120. (set-buffer sdic-buffer-name)
  1121. (message (buffer-substring (point-min)
  1122. (progn (goto-char (point-min))
  1123. (or (and (re-search-forward "^\\w"
  1124. nil
  1125. t
  1126. 4)
  1127. (progn (previous-line) t)
  1128. (point-at-eol))
  1129. (point-max)))))))
  1130. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  1131. (setq sdic-waei-dictionary-list
  1132. '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  1133. (setq sdic-disable-select-window t)
  1134. (setq sdic-window-height 7))
  1135. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1136. ;; vc
  1137. ;; (require 'vc)
  1138. (setq vc-handled-backends '())
  1139. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1140. ;; gauche-mode
  1141. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  1142. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  1143. (when (and (fetch-library
  1144. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  1145. t)
  1146. (lazy-load-eval 'gauche-mode '(gauche-mode run-scheme)))
  1147. (let ((s (executable-find "gosh")))
  1148. (setq scheme-program-name s
  1149. gauche-program-name s))
  1150. (defun run-gauche-other-window ()
  1151. "Run gauche on other window"
  1152. (interactive)
  1153. (switch-to-buffer-other-window
  1154. (get-buffer-create "*scheme*"))
  1155. (run-gauche))
  1156. (defun run-gauche ()
  1157. "run gauche"
  1158. (run-scheme gauche-program-name)
  1159. )
  1160. (defun scheme-send-buffer ()
  1161. ""
  1162. (interactive)
  1163. (scheme-send-region (point-min) (point-max))
  1164. (my-scheme-display-scheme-buffer)
  1165. )
  1166. (defun my-scheme-display-scheme-buffer ()
  1167. ""
  1168. (interactive)
  1169. (set-window-text-height (display-buffer scheme-buffer
  1170. t)
  1171. 7))
  1172. (add-hook 'scheme-mode-hook
  1173. (lambda ()
  1174. nil))
  1175. (add-hook 'inferior-scheme-mode-hook
  1176. (lambda ()
  1177. ;; (my-scheme-display-scheme-buffer)
  1178. ))
  1179. (setq auto-mode-alist
  1180. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1181. (setq auto-mode-alist
  1182. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1183. (add-hook 'gauche-mode-hook
  1184. (lambda ()
  1185. (define-key gauche-mode-map
  1186. (kbd "C-c C-z") 'run-gauche-other-window)
  1187. (define-key scheme-mode-map
  1188. (kbd "C-c C-c") 'scheme-send-buffer)
  1189. (define-key scheme-mode-map
  1190. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer))))
  1191. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1192. ;; recentf-mode
  1193. (setq recentf-save-file (expand-file-name "~/.emacs.d/recentf")
  1194. recentf-max-menu-items 20
  1195. recentf-max-saved-items 30
  1196. recentf-show-file-shortcuts-flag nil)
  1197. (when (require 'recentf nil t)
  1198. (add-to-list 'recentf-exclude (regexp-quote recentf-save-file))
  1199. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1200. (add-hook 'find-file-hook
  1201. 'recentf-save-list
  1202. t) ; save to file immediately after adding file to recentf list
  1203. (add-hook 'kill-emacs-hook
  1204. 'recentf-load-list)
  1205. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1206. ;; (add-hook 'find-file-hook
  1207. ;; (lambda ()
  1208. ;; (recentf-add-file default-directory)))
  1209. (and (fetch-library
  1210. "https://raw.github.com/10sr/emacs-lisp/master/recentf-show.el"
  1211. t)
  1212. (lazy-load-eval 'recentf-show)
  1213. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1214. (add-hook 'recentf-show-before-listing-hook
  1215. 'recentf-load-list))
  1216. (recentf-mode 1)
  1217. (add-hook 'recentf-dialog-mode-hook
  1218. (lambda ()
  1219. ;; (recentf-save-list)
  1220. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1221. ;; 'my-recentf-cd-and-find-file)
  1222. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1223. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1224. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1225. (define-key recentf-dialog-mode-map "n" 'next-line)
  1226. (cd "~/"))))
  1227. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1228. ;; dired
  1229. (when (lazy-load-eval 'dired nil)
  1230. (defun my-dired-echo-file-head (arg)
  1231. ""
  1232. (interactive "P")
  1233. (let ((f (dired-get-filename)))
  1234. (message "%s"
  1235. (with-temp-buffer
  1236. (insert-file-contents f)
  1237. (buffer-substring-no-properties
  1238. (point-min)
  1239. (progn (goto-line (if arg
  1240. (prefix-numeric-value arg)
  1241. 10))
  1242. (point-at-eol)))))))
  1243. (defun my-dired-diff ()
  1244. ""
  1245. (interactive)
  1246. (let ((files (dired-get-marked-files nil nil nil t)))
  1247. (if (eq (car files)
  1248. t)
  1249. (diff (cadr files) (dired-get-filename))
  1250. (message "One files must be marked!"))))
  1251. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1252. "pop up buffer using `display-buffer' and return that buffer."
  1253. (let ((bf (get-buffer-create buffer-or-name)))
  1254. (with-current-buffer bf
  1255. (cd ".")
  1256. (erase-buffer))
  1257. (display-buffer bf)
  1258. bf))
  1259. (defun my-replace-nasi-none ()
  1260. ""
  1261. (save-excursion
  1262. (let ((buffer-read-only nil))
  1263. (goto-char (point-min))
  1264. (while (search-forward "なし" nil t)
  1265. (replace-match "none")))))
  1266. (defun dired-get-file-info ()
  1267. "dired get file info"
  1268. (interactive)
  1269. (let ((f (shell-quote-argument (dired-get-filename t))))
  1270. (if (file-directory-p f)
  1271. (progn
  1272. (message "Calculating disk usage...")
  1273. (shell-command (concat "du -hsD "
  1274. f)))
  1275. (shell-command (concat "file "
  1276. f)))))
  1277. (defun my-dired-scroll-up ()
  1278. ""
  1279. (interactive)
  1280. (my-dired-previous-line (- (window-height) 1)))
  1281. (defun my-dired-scroll-down ()
  1282. ""
  1283. (interactive)
  1284. (my-dired-next-line (- (window-height) 1)))
  1285. ;; (defun my-dired-forward-line (arg)
  1286. ;; ""
  1287. ;; (interactive "p"))
  1288. (defun my-dired-previous-line (arg)
  1289. ""
  1290. (interactive "p")
  1291. (if (> arg 0)
  1292. (progn
  1293. (if (eq (line-number-at-pos)
  1294. 1)
  1295. (goto-char (point-max))
  1296. (forward-line -1))
  1297. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1298. (dired-get-subdir))
  1299. (- arg 1)
  1300. arg)))
  1301. (dired-move-to-filename)))
  1302. (defun my-dired-next-line (arg)
  1303. ""
  1304. (interactive "p")
  1305. (if (> arg 0)
  1306. (progn
  1307. (if (eq (point)
  1308. (point-max))
  1309. (goto-char (point-min))
  1310. (forward-line 1))
  1311. (my-dired-next-line (if (or (dired-get-filename nil t)
  1312. (dired-get-subdir))
  1313. (- arg 1)
  1314. arg)))
  1315. (dired-move-to-filename)))
  1316. (defun my-dired-print-current-dir-and-file ()
  1317. (message "%s %s"
  1318. default-directory
  1319. (buffer-substring-no-properties (point-at-bol)
  1320. (point-at-eol))))
  1321. (defun dired-do-execute-as-command ()
  1322. ""
  1323. (interactive)
  1324. (let ((file (dired-get-filename t)))
  1325. (if (file-executable-p file)
  1326. (start-process file nil file)
  1327. (when (y-or-n-p
  1328. "this file cant be executed. mark as executable and go? : ")
  1329. (set-file-modes file
  1330. (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1331. (start-process file nil file)))))
  1332. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1333. (defun my-dired-x-open ()
  1334. ""
  1335. (interactive)
  1336. (my-x-open (dired-get-filename t t)))
  1337. (if (eq window-system 'mac)
  1338. (setq dired-listing-switches "-lhF")
  1339. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1340. )
  1341. (setq dired-listing-switches "-lhF")
  1342. (put 'dired-find-alternate-file 'disabled nil)
  1343. ;; when using dired-find-alternate-file
  1344. ;; reuse current dired buffer for the file to open
  1345. (setq dired-ls-F-marks-symlinks t)
  1346. (when (require 'ls-lisp nil t)
  1347. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1348. (setq ls-lisp-dirs-first t)
  1349. (setq ls-lisp-use-localized-time-format t)
  1350. (setq ls-lisp-format-time-list
  1351. '("%Y-%m-%d %H:%M"
  1352. "%Y-%m-%d ")))
  1353. (setq dired-dwim-target t)
  1354. ;; (add-hook 'dired-after-readin-hook
  1355. ;; 'my-replace-nasi-none)
  1356. ;; (add-hook 'after-init-hook
  1357. ;; (lambda ()
  1358. ;; (dired ".")))
  1359. (add-hook 'dired-mode-hook
  1360. (lambda ()
  1361. (define-key dired-mode-map "o" 'my-dired-x-open)
  1362. (define-key dired-mode-map "i" 'dired-get-file-info)
  1363. (define-key dired-mode-map "f" 'find-file)
  1364. (define-key dired-mode-map "!" 'shell-command)
  1365. (define-key dired-mode-map "&" 'async-shell-command)
  1366. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1367. (define-key dired-mode-map "=" 'my-dired-diff)
  1368. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1369. (define-key dired-mode-map "b" 'gtkbm)
  1370. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1371. (define-key dired-mode-map "@" (lambda ()
  1372. (interactive) (my-x-open ".")))
  1373. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1374. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1375. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1376. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1377. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1378. (substitute-key-definition 'dired-next-line
  1379. 'my-dired-next-line dired-mode-map)
  1380. (substitute-key-definition 'dired-previous-line
  1381. 'my-dired-previous-line dired-mode-map)
  1382. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1383. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1384. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1385. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1386. (let ((file "._Icon\015"))
  1387. (when nil (file-readable-p file)
  1388. (delete-file file)))))
  1389. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/pack.el"
  1390. t)
  1391. (lazy-load-eval 'pack '(dired-do-pack-or-unpack pack))
  1392. (add-hook 'dired-mode-hook
  1393. (lambda ()
  1394. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack))))
  1395. (and (fetch-library
  1396. "https://raw.github.com/10sr/emacs-lisp/master/dired-list-all-mode.el"
  1397. t)
  1398. (lazy-load-eval 'dired-list-all-mode)
  1399. (setq dired-listing-switches "-lhF")
  1400. (add-hook 'dired-mode-hook
  1401. (lambda ()
  1402. (define-key dired-mode-map "a" 'dired-list-all-mode)
  1403. )))
  1404. ) ; when dired locate
  1405. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1406. (defun my-dired-toggle-mark()
  1407. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1408. (t dired-marker-char))))
  1409. (delete-char 1)
  1410. (insert cur)))
  1411. (defun my-dired-mark (arg)
  1412. "Toggle mark the current (or next ARG) files.
  1413. If on a subdir headerline, mark all its files except `.' and `..'.
  1414. Use \\[dired-unmark-all-files] to remove all marks
  1415. and \\[dired-unmark] on a subdir to remove the marks in
  1416. this subdir."
  1417. (interactive "P")
  1418. (if (dired-get-subdir)
  1419. (save-excursion (dired-mark-subdir-files))
  1420. (let ((inhibit-read-only t))
  1421. (dired-repeat-over-lines
  1422. (prefix-numeric-value arg)
  1423. 'my-dired-toggle-mark))))
  1424. (defun my-dired-mark-backward (arg)
  1425. "In Dired, move up lines and toggle mark there.
  1426. Optional prefix ARG says how many lines to unflag; default is one line."
  1427. (interactive "p")
  1428. (my-dired-mark (- arg)))
  1429. (add-hook 'dired-mode-hook
  1430. (lambda ()
  1431. (local-set-key (kbd "SPC") 'my-dired-mark)
  1432. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1433. )
  1434. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1435. ;; eshell
  1436. (lazy-load-eval 'eshell nil
  1437. (defun my-eshell-backward-delete-char ()
  1438. (interactive)
  1439. (when (< (save-excursion
  1440. (eshell-bol)
  1441. (point))
  1442. (point))
  1443. (backward-delete-char 1)))
  1444. (defun my-file-owner-p (file)
  1445. "t if FILE is owned by me."
  1446. (eq (user-uid) (nth 2 (file-attributes file))))
  1447. "http://www.bookshelf.jp/pukiwiki/pukiwiki.php\
  1448. ?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9"
  1449. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1450. ;; (defun eshell/less (&rest args)
  1451. ;; "Invoke `view-file' on the file.
  1452. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1453. ;; (if args
  1454. ;; (while args
  1455. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1456. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1457. ;; (file (pop args)))
  1458. ;; (view-file file)
  1459. ;; (goto-line line))
  1460. ;; (view-file (pop args))))))
  1461. (defun eshell/o (&optional file)
  1462. (my-x-open (or file ".")))
  1463. ;; (defun eshell/vi (&rest args)
  1464. ;; "Invoke `find-file' on the file.
  1465. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1466. ;; (while args
  1467. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1468. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1469. ;; (file (pop args)))
  1470. ;; (find-file file)
  1471. ;; (goto-line line))
  1472. ;; (find-file (pop args)))))
  1473. (defun eshell/clear ()
  1474. "Clear the current buffer, leaving one prompt at the top."
  1475. (interactive)
  1476. (let ((inhibit-read-only t))
  1477. (erase-buffer)))
  1478. (defun eshell-clear ()
  1479. (interactive)
  1480. (let ((inhibit-read-only t))
  1481. (erase-buffer)
  1482. (insert (funcall eshell-prompt-function))))
  1483. (defun eshell/d (&optional dirname switches)
  1484. "if first arg is omitted open current directory."
  1485. (dired (or dirname ".") switches))
  1486. (defun eshell/v ()
  1487. (view-mode 1))
  1488. ;; (defun eshell/aaa (&rest args)
  1489. ;; (message "%S"
  1490. ;; args))
  1491. (defvar eshell/git-cat-command
  1492. nil
  1493. "List of git commands that cat just return strings as results.")
  1494. (setq eshell/git-cat-command
  1495. '("status" "st" "b" "branch" "ls" "ls-files")
  1496. )
  1497. (defun eshell/git (&rest args)
  1498. (if (member (car args)
  1499. eshell/git-cat-command)
  1500. (shell-command-to-string (mapconcat 'shell-quote-argument
  1501. `("git"
  1502. "-c"
  1503. "color.ui=always"
  1504. ,@args)
  1505. " "))
  1506. ;; (eshell-git-shell-command-to-string args)
  1507. (if (require 'git-command nil t)
  1508. (git-command (mapconcat 'shell-quote-argument
  1509. args
  1510. " "))
  1511. (apply 'eshell-exec-visual "git" args))))
  1512. ;; (defun eshell-git-shell-command-to-string (args)
  1513. ;; "Return string of output of ARGS."
  1514. ;; (let ((sargs (mapconcat 'shell-quote-argument
  1515. ;; args
  1516. ;; " ")))
  1517. ;; (if (require 'ansi-color nil t)
  1518. ;; (identity
  1519. ;; (shell-command-to-string (concat "git "
  1520. ;; "-c color.ui=always "
  1521. ;; sargs)))
  1522. ;; (shell-command-to-string (concat "git "
  1523. ;; sargs)))))
  1524. (defalias 'eshell/g 'eshell/git)
  1525. (defalias 'eshell/: 'ignore)
  1526. (defalias 'eshell/type 'eshell/which)
  1527. ;; (defalias 'eshell/vim 'eshell/vi)
  1528. (defalias 'eshell/ff 'find-file)
  1529. (defalias 'eshell/q 'eshell/exit)
  1530. (defun eshell-goto-prompt ()
  1531. ""
  1532. (interactive)
  1533. (goto-char (point-max)))
  1534. (defun eshell-delete-char-or-logout (n)
  1535. (interactive "p")
  1536. (if (equal (eshell-get-old-input)
  1537. "")
  1538. (progn
  1539. (insert "exit")
  1540. (eshell-send-input))
  1541. (delete-char n)))
  1542. (defun eshell-kill-input ()
  1543. (interactive)
  1544. (delete-region (point)
  1545. (progn (eshell-bol)
  1546. (point))))
  1547. (defalias 'eshell/logout 'eshell/exit)
  1548. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1549. "open eshell and change wd
  1550. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1551. (interactive)
  1552. (let ((dir (expand-file-name default-directory)))
  1553. (switch-to-buffer (or eshell-buffer-or-name
  1554. (eshell t)))
  1555. (unless (equal dir (expand-file-name default-directory))
  1556. ;; (cd dir)
  1557. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1558. ;; (eshell-emit-prompt)
  1559. (goto-char (point-max))
  1560. (eshell-kill-input)
  1561. (insert "cd " dir)
  1562. (eshell-send-input))))
  1563. (defadvice eshell-next-matching-input-from-input
  1564. ;; do not cycle history
  1565. (around eshell-history-do-not-cycle activate)
  1566. (if (= 0
  1567. (or eshell-history-index
  1568. 0))
  1569. (progn
  1570. (delete-region eshell-last-output-end (point))
  1571. (insert-and-inherit eshell-matching-input-from-input-string)
  1572. (setq eshell-history-index nil))
  1573. ad-do-it))
  1574. (setq eshell-directory-name "~/.emacs.d/eshell/")
  1575. (setq eshell-term-name "eterm-color")
  1576. (setq eshell-scroll-to-bottom-on-input t)
  1577. (setq eshell-cmpl-ignore-case t)
  1578. (setq eshell-cmpl-cycle-completions nil)
  1579. (setq eshell-highlight-prompt nil)
  1580. (setq eshell-ls-initial-args '("-hCFG"
  1581. "--color=auto"
  1582. "--time-style=long-iso")) ; "-hF")
  1583. (setq eshell-prompt-function
  1584. (lambda ()
  1585. (with-temp-buffer
  1586. (let (p1 p2 p3 p4)
  1587. (insert ":: [")
  1588. (setq p1 (point))
  1589. (insert user-login-name
  1590. "@"
  1591. system-name
  1592. )
  1593. (setq p2 (point))
  1594. (insert ":")
  1595. (setq p3 (point))
  1596. (insert (abbreviate-file-name default-directory))
  1597. (setq p4 (point))
  1598. (insert "]")
  1599. (insert "\n:: ")
  1600. (unless (eq 0
  1601. eshell-last-command-status)
  1602. (insert (format "[STATUS:%d] "
  1603. eshell-last-command-status)))
  1604. (insert (if (= (user-uid)
  1605. 0)
  1606. "# "
  1607. "$ "))
  1608. (add-text-properties p1
  1609. p2
  1610. '(face underline))
  1611. (add-text-properties p3
  1612. p4
  1613. '(face underline))
  1614. (buffer-substring (point-min)
  1615. (point-max))))))
  1616. (add-hook 'eshell-mode-hook
  1617. (lambda ()
  1618. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1619. ;; (interactive)
  1620. ;; (switch-to-buffer (other-buffer))))
  1621. ;; (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1622. ;; (interactive)
  1623. ;; (eshell-goto-prompt)
  1624. ;; (keyboard-quit)))
  1625. (define-key eshell-mode-map (kbd "C-u")
  1626. 'eshell-kill-input)
  1627. (define-key eshell-mode-map (kbd "C-d")
  1628. 'eshell-delete-char-or-logout)
  1629. ;; (define-key eshell-mode-map (kbd "C-l")
  1630. ;; 'eshell-clear)
  1631. (define-key eshell-mode-map (kbd "DEL")
  1632. 'my-eshell-backward-delete-char)
  1633. (define-key eshell-mode-map
  1634. (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1635. (define-key eshell-mode-map
  1636. (kbd "C-n") 'eshell-next-matching-input-from-input)
  1637. (apply 'eshell/addpath exec-path)
  1638. (set (make-local-variable 'scroll-margin) 0)
  1639. ;; (eshell/export "GIT_PAGER=")
  1640. ;; (eshell/export "GIT_EDITOR=")
  1641. (eshell/export "LC_MESSAGES=C")
  1642. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1643. (set (make-local-variable 'hl-line-range-function)
  1644. (lambda ()
  1645. '(0 . 0)))
  1646. (add-to-list 'eshell-virtual-targets
  1647. '("/dev/less"
  1648. (lambda (str)
  1649. (if str
  1650. (with-current-buffer nil)))
  1651. nil))
  1652. ))
  1653. (add-hook 'eshell-mode-hook
  1654. (lambda ()
  1655. (add-to-list 'eshell-visual-commands "vim")
  1656. ;; (add-to-list 'eshell-visual-commands "git")
  1657. (add-to-list 'eshell-output-filter-functions
  1658. 'eshell-truncate-buffer)
  1659. (mapcar (lambda (alias)
  1660. (add-to-list 'eshell-command-aliases-list
  1661. alias))
  1662. '(
  1663. ; ("ll" "ls -l $*")
  1664. ; ("la" "ls -a $*")
  1665. ; ("lla" "ls -al $*")
  1666. ("eless"
  1667. (concat "cat >>> (with-current-buffer "
  1668. "(get-buffer-create \"*eshell output\") "
  1669. "(erase-buffer) "
  1670. "(setq buffer-read-only nil) "
  1671. "(current-buffer)) "
  1672. "(view-buffer (get-buffer \"*eshell output*\"))")
  1673. ))
  1674. )))
  1675. ) ; eval after load eshell
  1676. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1677. ;; frame buffer
  1678. ;; todo: work well when opening files already opened on another window
  1679. (add-hook 'after-make-frame-functions
  1680. (lambda (f)
  1681. (set-window-buffer (frame-selected-window f)
  1682. "*Messages*")))
  1683. (defun make-frame-command-with-name (name)
  1684. "Make frame with NAME specified."
  1685. (interactive "sName for new frame: ")
  1686. (set-frame-parameter (make-frame-command)
  1687. 'name
  1688. name))
  1689. (defvar my-frame-buffer-plist nil)
  1690. (defun my-frame-buffer-add (&optional buf frame)
  1691. "Add BUF to buffer list for FRAME."
  1692. (setq my-frame-buffer-plist
  1693. (plist-put my-frame-buffer-plist
  1694. (or frame
  1695. (selected-frame))
  1696. (let ((lst (my-frame-buffer-get frame)))
  1697. (if lst
  1698. (add-to-list 'lst
  1699. (or buf
  1700. (current-buffer)))
  1701. (list (or buf
  1702. (current-buffer))))))))
  1703. (defun my-frame-buffer-remove (&optional buf frame)
  1704. "Remove BUF from bufferlist for FRAME."
  1705. (setq my-frame-buffer-plist
  1706. (plist-put my-frame-buffer-plist
  1707. (or frame
  1708. (selected-frame))
  1709. (delq (or buf
  1710. (current-buffer))
  1711. (my-frame-buffer-get frame)))))
  1712. (defun my-frame-buffer-get (&optional frame)
  1713. "Get buffer list for FRAME."
  1714. (plist-get my-frame-buffer-plist
  1715. (or frame
  1716. (selected-frame))))
  1717. (defun my-frame-buffer-kill-all-buffer (&optional frame)
  1718. "Kill all buffer of FRAME."
  1719. (mapcar 'kill-buffer
  1720. (my-frame-buffer-get frame)))
  1721. (add-hook 'find-file-hook
  1722. 'my-frame-buffer-add)
  1723. ;; (add-hook 'term-mode-hook
  1724. ;; 'my-frame-buffer-add)
  1725. (add-hook 'eshell-mode-hook
  1726. 'my-frame-buffer-add)
  1727. (add-hook 'Man-mode-hook
  1728. 'my-frame-buffer-add)
  1729. (add-hook 'kill-buffer-hook
  1730. 'my-frame-buffer-remove)
  1731. (add-hook 'delete-frame-functions
  1732. 'my-frame-buffer-kill-all-buffer)
  1733. (defvar my-desktop-terminal "roxterm")
  1734. (defun my-execute-terminal ()
  1735. "Invole terminal program."
  1736. (interactive)
  1737. (if (and (or (eq system-type 'windows-nt)
  1738. window-system)
  1739. my-desktop-terminal
  1740. )
  1741. (let ((process-environment (cons "TERM=xterm" process-environment)))
  1742. (start-process "terminal"
  1743. nil
  1744. my-desktop-terminal))
  1745. (my-term)))
  1746. (defun my-delete-frame-or-kill-emacs ()
  1747. "Delete frame when opening multiple frame, kill Emacs when only one."
  1748. (interactive)
  1749. (if (eq 1
  1750. (length (frame-list)))
  1751. (save-buffers-kill-emacs)
  1752. (delete-frame)))
  1753. ;; (define-key my-prefix-map (kbd "C-s") 'my-execute-terminal)
  1754. (define-key my-prefix-map (kbd "C-f") 'make-frame-command-with-name)
  1755. (global-set-key (kbd "C-x C-c") 'my-delete-frame-or-kill-emacs)
  1756. (define-key my-prefix-map (kbd "C-x C-c") 'save-buffers-kill-emacs)
  1757. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1758. ;; my-term
  1759. (defvar my-term nil
  1760. "My terminal buffer.")
  1761. (defvar my-term-function nil
  1762. "Function to create terminal buffer.
  1763. This function accept no argument and return newly created buffer of terminal.")
  1764. (defun my-term (&optional arg)
  1765. "Open terminal buffer and return that buffer.
  1766. ARG is ignored."
  1767. (interactive "P")
  1768. (if (and my-term
  1769. (buffer-name my-term))
  1770. (pop-to-buffer my-term)
  1771. (setq my-term
  1772. (save-window-excursion
  1773. (funcall my-term-function)))
  1774. (and my-term
  1775. (my-term))))
  1776. ;; (setq my-term-function
  1777. ;; (lambda ()
  1778. ;; (if (eq system-type 'windows-nt)
  1779. ;; (eshell)
  1780. ;; (if (require 'multi-term nil t)
  1781. ;; (multi-term)
  1782. ;; (ansi-term shell-file-name)))))
  1783. (setq my-term-function 'eshell)
  1784. (define-key my-prefix-map (kbd "C-s") 'my-term)
  1785. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1786. ;; x open
  1787. (defvar my-filer nil)
  1788. (setq my-filer (or (executable-find "pcmanfm")
  1789. (executable-find "nautilus")))
  1790. (defun my-x-open (file)
  1791. "open FILE."
  1792. (interactive "FOpen File: ")
  1793. (setq file (expand-file-name file))
  1794. (message "Opening %s..." file)
  1795. (cond ((eq system-type 'windows-nt)
  1796. (call-process "cmd.exe" nil 0 nil
  1797. "/c" "start" "" (convert-standard-filename file)))
  1798. ((eq system-type 'darwin)
  1799. (call-process "open" nil 0 nil file))
  1800. ((getenv "DISPLAY")
  1801. (call-process (or my-filer "xdg-open") nil 0 nil file))
  1802. (t
  1803. (find-file file))
  1804. )
  1805. ;; (recentf-add-file file)
  1806. (message "Opening %s...done" file))
  1807. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1808. ;; misc funcs
  1809. (defun memo (&optional dir)
  1810. "Open memo.txt in DIR."
  1811. (interactive)
  1812. (pop-to-buffer (find-file-noselect (concat (if dir
  1813. (file-name-as-directory dir)
  1814. "")
  1815. "memo.txt"))))
  1816. (defvar my-rgrep-alist
  1817. `(
  1818. ;; gnu global
  1819. ("global"
  1820. (and (require 'gtags nil t)
  1821. (gtags-get-rootpath))
  1822. "global --result grep ")
  1823. ;; git grep
  1824. ("gitgrep"
  1825. (eq 0
  1826. (shell-command "git rev-parse --git-dir"))
  1827. "git --no-pager -c color.grep=false grep -nH -e ")
  1828. ;; the silver searcher
  1829. ("ag"
  1830. (executable-find "ag")
  1831. "ag --nocolor --nogroup --nopager ")
  1832. ;; ack
  1833. ("ack"
  1834. (executable-find "ack")
  1835. "ack --nocolor --nogroup --nopager ")
  1836. ;; grep
  1837. ("grep"
  1838. t
  1839. ,(concat "find . "
  1840. "-path '*/.git' -prune -o "
  1841. "-path '*/.svn' -prune -o "
  1842. "-type f -print0 | "
  1843. "xargs -0 grep -nH -e "))
  1844. )
  1845. "Alist of rgrep command.
  1846. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1847. condition to choose COMMAND when evaluated.")
  1848. (defvar my-rgrep-default nil
  1849. "Default command name for my-rgrep.")
  1850. (defun my-rgrep-grep-command (&optional name alist)
  1851. "Return recursive grep command for current directory or nil.
  1852. If NAME is given, use that without testing.
  1853. Commands are searched from ALIST."
  1854. (if alist
  1855. (if name
  1856. ;; if name is given search that from alist and return the command
  1857. (nth 2 (assoc name
  1858. alist))
  1859. ;; if name is not given try test in 1th elem
  1860. (let ((car (car alist))
  1861. (cdr (cdr alist)))
  1862. (if (eval (nth 1 car))
  1863. ;; if the condition is true return the command
  1864. (nth 2 car)
  1865. ;; try next one
  1866. (and cdr
  1867. (my-rgrep-grep-command name cdr)))))
  1868. ;; if alist is not given set default value
  1869. (my-rgrep-grep-command name my-rgrep-alist)))
  1870. (my-rgrep-grep-command "ag" nil)
  1871. (defun my-rgrep (command-args)
  1872. "My recursive grep. Run COMMAND-ARGS."
  1873. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  1874. nil)))
  1875. (if cmd
  1876. (list (read-shell-command "grep command: "
  1877. cmd
  1878. 'grep-find-history))
  1879. (error "my-rgrep: Command for rgrep not found")
  1880. )))
  1881. (compilation-start command-args
  1882. 'grep-mode))
  1883. ;; (defun my-rgrep-symbol-at-point (command-args)
  1884. ;; "My recursive grep. Run COMMAND-ARGS."
  1885. ;; (interactive (list (read-shell-command "grep command: "
  1886. ;; (concat (my-rgrep-grep-command)
  1887. ;; " "
  1888. ;; (thing-at-point 'symbol))
  1889. ;; 'grep-find-history)))
  1890. ;; (compilation-start command-args
  1891. ;; 'grep-mode))
  1892. (defun my-rgrep-ack ()
  1893. "My recursive grep by ack."
  1894. (interactive)
  1895. (let ((my-rgrep-default "ack"))
  1896. (if (called-interactively-p 'any)
  1897. (call-interactively 'my-rgrep)
  1898. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1899. (defun my-rgrep-ag ()
  1900. "My recursive grep by ack."
  1901. (interactive)
  1902. (let ((my-rgrep-default "ag"))
  1903. (if (called-interactively-p 'any)
  1904. (call-interactively 'my-rgrep)
  1905. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1906. (defun my-rgrep-gitgrep ()
  1907. "My recursive grep by ack."
  1908. (interactive)
  1909. (let ((my-rgrep-default "gitgrep"))
  1910. (if (called-interactively-p 'any)
  1911. (call-interactively 'my-rgrep)
  1912. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1913. (defun my-rgrep-grep ()
  1914. "My recursive grep by ack."
  1915. (interactive)
  1916. (let ((my-rgrep-default "grep"))
  1917. (if (called-interactively-p 'any)
  1918. (call-interactively 'my-rgrep)
  1919. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1920. (defun my-rgrep-global ()
  1921. "My recursive grep by ack."
  1922. (interactive)
  1923. (let ((my-rgrep-default "global"))
  1924. (if (called-interactively-p 'any)
  1925. (call-interactively 'my-rgrep)
  1926. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1927. (define-key ctl-x-map "s" 'my-rgrep)
  1928. ;; (defun make ()
  1929. ;; "Run \"make -k\" in current directory."
  1930. ;; (interactive)
  1931. ;; (compile "make -k"))
  1932. (defalias 'make 'compile)
  1933. (defvar sed-in-place-history nil
  1934. "History of `sed-in-place'.")
  1935. (defvar sed-in-place-command "sed --in-place=.bak -e")
  1936. (defun sed-in-place (command)
  1937. "Issue sed in place COMMAND."
  1938. (interactive (list (read-shell-command "sed in place: "
  1939. (concat sed-in-place-command " ")
  1940. 'sed-in-place-history)))
  1941. (shell-command command
  1942. "*sed in place*"))
  1943. (defun dired-do-sed-in-place (&optional arg)
  1944. "Issue sed in place dired. If ARG is given, use the next ARG files."
  1945. (interactive "p")
  1946. (require 'dired-aux)
  1947. (let* ((files (dired-get-marked-files t arg))
  1948. (expr (dired-mark-read-string "Run sed-in-place for %s: "
  1949. nil
  1950. 'sed-in-place
  1951. arg
  1952. files)))
  1953. (if (equal expr
  1954. "")
  1955. (error "No expression specified")
  1956. (shell-command (concat sed-in-place-command
  1957. " '"
  1958. expr
  1959. "' "
  1960. (mapconcat 'shell-quote-argument
  1961. files
  1962. " "))
  1963. "*sed in place*"))))
  1964. (defun dir-show (&optional dir)
  1965. "Show DIR list."
  1966. (interactive)
  1967. (let ((bf (get-buffer-create "*dir show*"))
  1968. (list-directory-brief-switches "-C"))
  1969. (with-current-buffer bf
  1970. (list-directory (or nil
  1971. default-directory)
  1972. nil))
  1973. ))
  1974. (defun my-convmv-sjis2utf8-test ()
  1975. "Run `convmv -r -f sjis -t utf8 *'.
  1976. this is test, does not rename files."
  1977. (interactive)
  1978. (shell-command "convmv -r -f sjis -t utf8 *"))
  1979. (defun my-convmv-sjis2utf8-notest ()
  1980. "Run `convmv -r -f sjis -t utf8 * --notest'."
  1981. (interactive)
  1982. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  1983. (defun kill-ring-save-buffer-file-name ()
  1984. "Get current filename."
  1985. (interactive)
  1986. (let ((file buffer-file-name))
  1987. (if file
  1988. (progn (kill-new file)
  1989. (message file))
  1990. (message "not visiting file."))))
  1991. (defvar kill-ring-buffer-name "*kill-ring*"
  1992. "Buffer name for `kill-ring-buffer'.")
  1993. (defun open-kill-ring-buffer ()
  1994. "Open kill- ring buffer."
  1995. (interactive)
  1996. (pop-to-buffer
  1997. (with-current-buffer (get-buffer-create kill-ring-buffer-name)
  1998. (erase-buffer)
  1999. (yank)
  2000. (text-mode)
  2001. (current-local-map)
  2002. (goto-char (point-min)))))
  2003. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2004. ;; ;; savage emacs
  2005. ;; ;; when enabled emacs fails to complete
  2006. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  2007. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  2008. ;; (setq arg
  2009. ;; (concat arg
  2010. ;; (if (eq nil
  2011. ;; (string-match "\\. *$"
  2012. ;; arg))
  2013. ;; ".")
  2014. ;; " Stupid!")))
  2015. (defvar my-system-info
  2016. nil
  2017. "System info in the form of \"[user@host] \".")
  2018. (setq my-system-info
  2019. (concat "["
  2020. user-login-name
  2021. "@"
  2022. (car (split-string system-name
  2023. "\\."))
  2024. "] "))
  2025. (defadvice read-from-minibuffer (before info-in-prompt activate)
  2026. "Show system info when use `read-from-minibuffer'."
  2027. (ad-set-arg 0
  2028. (concat my-system-info
  2029. (ad-get-arg 0))))
  2030. (defadvice read-string (before info-in-prompt activate)
  2031. "Show system info when use `read-string'."
  2032. (ad-set-arg 0
  2033. (concat my-system-info
  2034. (ad-get-arg 0))))
  2035. (when (< emacs-major-version 24)
  2036. (defadvice completing-read (before info-in-prompt activate)
  2037. "Show system info when use `completing-read'."
  2038. (ad-set-arg 0
  2039. (concat my-system-info
  2040. (ad-get-arg 0)))))
  2041. (defun my-real-function-subr-p (function)
  2042. "Return t if FUNCTION is a built-in function even if it is advised."
  2043. (let* ((advised (and (symbolp function)
  2044. (featurep 'advice)
  2045. (ad-get-advice-info function)))
  2046. (real-function
  2047. (or (and advised (let ((origname (cdr (assq 'origname advised))))
  2048. (and (fboundp origname)
  2049. origname)))
  2050. function))
  2051. (def (if (symbolp real-function)
  2052. (symbol-function real-function)
  2053. function)))
  2054. (subrp def)))
  2055. ;; (my-real-function-subr-p 'my-real-function-subr-p)
  2056. ;;;;;;;;;;;;;;;;;;;;;;;;
  2057. ;; ilookup
  2058. (when (fetch-library
  2059. "https://raw.github.com/10sr/emacs-lisp/master/ilookup.el"
  2060. t)
  2061. (lazy-load-eval 'ilookup
  2062. '(ilookup-open)
  2063. (setq ilookup-dict-alist
  2064. '(
  2065. ("en" . (lambda (word)
  2066. (shell-command-to-string
  2067. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  2068. word))))
  2069. ("ja" . (lambda (word)
  2070. (shell-command-to-string
  2071. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  2072. word))))
  2073. ("jaj" . (lambda (word)
  2074. (shell-command-to-string
  2075. (format "sdcv -n -u jmdict-en-ja '%s'"
  2076. word))))
  2077. ("jag" .
  2078. (lambda (word)
  2079. (with-temp-buffer
  2080. (insert (shell-command-to-string
  2081. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  2082. word)))
  2083. (html2text)
  2084. (buffer-substring (point-min)
  2085. (point-max)))))
  2086. ("alc" . (lambda (word)
  2087. (shell-command-to-string
  2088. (format "alc '%s' | head -n 20"
  2089. word))))
  2090. ("app" . (lambda (word)
  2091. (shell-command-to-string
  2092. (format "dict_app '%s'"
  2093. word))))
  2094. ;; letters broken
  2095. ("ms" .
  2096. (lambda (word)
  2097. (let ((url (concat
  2098. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  2099. "Translate?appId=%s&text=%s&to=%s"))
  2100. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  2101. (target "ja")
  2102. (eword (url-hexify-string word)))
  2103. (with-current-buffer (url-retrieve-synchronously
  2104. (format url
  2105. apikey
  2106. eword
  2107. target))
  2108. (message "")
  2109. (goto-char (point-min))
  2110. (search-forward-regexp "^$"
  2111. nil
  2112. t)
  2113. (url-unhex-string (buffer-substring-no-properties
  2114. (point)
  2115. (point-max)))))))
  2116. ))
  2117. ;; (funcall (cdr (assoc "ms"
  2118. ;; ilookup-alist))
  2119. ;; "dictionary")
  2120. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  2121. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  2122. (setq ilookup-default "ja")))
  2123. ;;; emacs.el ends here