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 64 KiB

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