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