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

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