Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

.emacs.el 72 KiB

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