Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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