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