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

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