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

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