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

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