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