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