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

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