Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

emacs.el 67 KiB

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