You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

.emacs.el 72 KiB

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