You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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