Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

emacs.el 69 KiB

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