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

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