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.

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