Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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