Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

.emacs.el 69 KiB

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