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

emacs.el 71 KiB

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997
  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-index-face "blue")
  507. (set-face-foreground 'diff-hunk-header-face "magenda")
  508. (set-face-foreground 'diff-removed-face "red")
  509. (set-face-foreground 'diff-added-face "blue")
  510. (set-face-foreground 'diff-changed-face "syan")
  511. ))
  512. ;; (ffap-bindings)
  513. (add-hook 'sh-mode-hook
  514. (lambda ()
  515. (define-key sh-mode-map (kbd "C-x C-e") 'my-execute-shell-command-current-line)))
  516. (defun my-execute-shell-command-current-line ()
  517. ""
  518. (interactive)
  519. (shell-command (buffer-substring-no-properties (point-at-bol)
  520. (point))))
  521. (add-hook 'inferior-python-mode-hook
  522. (lambda ()
  523. (define-key inferior-python-mode-map (kbd "<up>") 'comint-previous-input)
  524. (define-key inferior-python-mode-map (kbd "<down>") 'comint-next-input)))
  525. (add-to-list 'Info-default-directory-list (expand-file-name "~/.info/emacs-ja"))
  526. (setq bookmark-default-file "~/.emacs.d/bmk")
  527. (add-hook 'apropos-mode-hook
  528. (lambda ()
  529. (define-key apropos-mode-map "j" 'next-line)
  530. (define-key apropos-mode-map "k" 'previous-line)))
  531. (define-key minibuffer-local-map (kbd "C-u") (lambda () (interactive) (delete-region (point-at-bol) (point-at-eol))))
  532. (add-hook 'isearch-mode-hook
  533. (lambda ()
  534. ;; (define-key isearch-mode-map (kbd "C-j") 'isearch-other-control-char)
  535. ;; (define-key isearch-mode-map (kbd "C-k") 'isearch-other-control-char)
  536. ;; (define-key isearch-mode-map (kbd "C-h") 'isearch-other-control-char)
  537. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  538. (define-key isearch-mode-map (kbd "M-r") 'isearch-query-replace-regexp)))
  539. (add-hook 'outline-mode-hook
  540. (lambda ()
  541. (if (string-match "\\.md$" buffer-file-name)
  542. (set (make-local-variable 'outline-regexp) "#+ "))))
  543. (add-to-list 'auto-mode-alist (cons "\\.ol$" 'outline-mode))
  544. (add-to-list 'auto-mode-alist (cons "\\.md$" 'outline-mode))
  545. (when (dllib-if-unfound "markdown-mode"
  546. "http://jblevins.org/projects/markdown-mode/markdown-mode.el"
  547. t)
  548. (add-to-list 'auto-mode-alist (cons "\\.md$" 'markdown-mode))
  549. (autoload 'markdown-mode "markdown-mode" "Major mode for editing Markdown files." nil)
  550. (add-hook 'markdown-mode-hook
  551. (lambda ()
  552. (outline-minor-mode 1)
  553. (set (make-local-variable 'comment-start) ";"))))
  554. ;; (add-hook 'c-mode-hook
  555. ;; (lambda ()
  556. ;; (set (make-local-variable 'comment-start) "//")
  557. ;; (set (make-local-variable 'comment-end) "")))
  558. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  559. ;; c-mode
  560. ;; (setq c-default-style "bsd")
  561. ;; BackSpace キーを「賢く」し,インデント幅は2桁,タブはスペースに展開
  562. (add-hook 'c-mode-common-hook
  563. (lambda ()
  564. (setq c-basic-offset 2
  565. indent-tabs-mode nil)
  566. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  567. (c-toggle-hungry-state 1)
  568. ))
  569. (when (dllib-if-unfound "js2-mode"
  570. "https://github.com/mooz/js2-mode/raw/master/js2-mode.el"
  571. t)
  572. (autoload 'js2-mode "js2-mode" nil t)
  573. (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
  574. (add-to-list 'auto-mode-alist '("\\.jsm$" . js2-mode)))
  575. ;; (add-hook 'js2-mode-hook
  576. ;; (lambda ()
  577. ;; (add-hook 'before-save-hook
  578. ;; 'my-indent-buffer
  579. ;; nil
  580. ;; t)))
  581. (add-hook 'js2-mode-hook
  582. (lambda ()
  583. (define-key js2-mode-map (kbd "C-m") (lambda ()
  584. (interactive)
  585. (js2-enter-key)
  586. (indent-for-tab-command)))
  587. (add-hook (kill-local-variable 'before-save-hook)
  588. 'js2-before-save)))
  589. (and nil
  590. (require 'zone nil t)
  591. (not (eq system-type 'windows-nt))
  592. ;; (zone-when-idle 180)
  593. (run-with-idle-timer 180 t (lambda ()
  594. (unless (memq major-mode
  595. '(term-mode))
  596. (zone)))))
  597. (when (require 'uniquify nil t)
  598. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  599. (setq uniquify-ignore-buffers-re "*[^*]+*")
  600. (setq uniquify-min-dir-content 1))
  601. (add-hook 'view-mode-hook
  602. (lambda()
  603. (define-key view-mode-map "j" (lambda() (interactive) (scroll-up 1)))
  604. (define-key view-mode-map "k" (lambda() (interactive) (scroll-down 1)))
  605. (define-key view-mode-map "/" 'isearch-forward)
  606. (define-key view-mode-map "v" 'toggle-read-only)
  607. (define-key view-mode-map "q" 'bury-buffer)))
  608. (global-set-key "\M-r" 'view-mode)
  609. (setq view-read-only t)
  610. ;; (add-hook 'find-file-hook
  611. ;; (lambda ()
  612. ;; (when buffer-read-only
  613. ;; (view-mode 1))))
  614. (add-hook 'Man-mode-hook
  615. (lambda ()
  616. (view-mode 1)
  617. (setq truncate-lines nil)))
  618. (setq Man-notify-method (if window-system
  619. 'newframe
  620. 'pushy))
  621. ;; (when (and (executable-find "git")
  622. ;; (require 'sgit-mode nil t))
  623. ;; (add-hook 'find-file-hook
  624. ;; 'sgit-load))
  625. (require 'session nil t)
  626. (when (require 'gtkbm nil t)
  627. (global-set-key (kbd "C-x C-d") 'gtkbm))
  628. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  629. ;; frame buffer
  630. (add-hook 'before-make-frame-hook
  631. (lambda ()
  632. (switch-to-buffer "*Messages*")))
  633. (defvar my-frame-buffer-plist nil)
  634. (defun my-frame-buffer-add (&optional buf frame)
  635. ""
  636. (setq my-frame-buffer-plist
  637. (plist-put my-frame-buffer-plist
  638. (or frame
  639. (selected-frame))
  640. (let ((lst (my-frame-buffer-get frame)))
  641. (if lst
  642. (add-to-list 'lst
  643. (or buf
  644. (current-buffer)))
  645. (list (or buf
  646. (current-buffer))))))))
  647. (defun my-frame-buffer-remove (&optional buf frame)
  648. ""
  649. (setq my-frame-buffer-plist
  650. (plist-put my-frame-buffer-plist
  651. (or frame
  652. (selected-frame))
  653. (delq (or buf
  654. (current-buffer))
  655. (my-frame-buffer-get frame)))))
  656. (defun my-frame-buffer-get (&optional frame)
  657. ""
  658. (plist-get my-frame-buffer-plist
  659. (or frame
  660. (selected-frame))))
  661. (defun my-frame-buffer-kill-all-buffer (&optional frame)
  662. ""
  663. (mapcar 'kill-buffer
  664. (my-frame-buffer-get frame)))
  665. (add-hook 'find-file-hook
  666. 'my-frame-buffer-add)
  667. (add-hook 'term-mode-hook
  668. 'my-frame-buffer-add)
  669. (add-hook 'eshell-mode-hook
  670. 'my-frame-buffer-add)
  671. (add-hook 'kill-buffer-hook
  672. 'my-frame-buffer-remove)
  673. (add-hook 'delete-frame-functions
  674. 'my-frame-buffer-kill-all-buffer)
  675. (defvar my-desktop-terminal "roxterm")
  676. (defun my-execute-terminal ()
  677. ""
  678. (interactive)
  679. (if (and (or (eq system-type 'windows-nt)
  680. window-system)
  681. my-desktop-terminal
  682. )
  683. (let ((process-environment (cons "TERM=xterm" process-environment)))
  684. (start-process "terminal"
  685. nil
  686. my-desktop-terminal))
  687. (my-term)))
  688. (defun my-term ()
  689. "open terminal buffer and return that buffer."
  690. (interactive)
  691. (if (eq system-type 'windows-nt)
  692. (eshell t)
  693. (if (featurep 'multi-term)
  694. (multi-term)
  695. (ansi-term "/bin/bash"))))
  696. (defun my-delete-frame-or-kill-emacs ()
  697. "delete frame when opening multiple frame, kill emacs when only one."
  698. (interactive)
  699. (if (eq 1
  700. (length (frame-list)))
  701. (save-buffers-kill-emacs)
  702. (delete-frame)))
  703. (define-key my-prefix-map (kbd "C-s") 'my-execute-terminal)
  704. (define-key my-prefix-map (kbd "C-f") 'make-frame-command)
  705. (global-set-key (kbd "C-x C-c") 'my-delete-frame-or-kill-emacs)
  706. (define-key my-prefix-map (kbd "C-x C-c") 'save-buffers-kill-emacs)
  707. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  708. ;; term mode
  709. ;; (setq multi-term-program shell-file-name)
  710. (and (dllib-if-unfound "multi-term"
  711. "http://www.emacswiki.org/emacs/download/multi-term.el"
  712. t)
  713. (require 'multi-term nil t)
  714. (setq multi-term-switch-after-close nil))
  715. (defun my-term-quit-or-send-raw ()
  716. ""
  717. (interactive)
  718. (if (get-buffer-process (current-buffer))
  719. (call-interactively 'term-send-raw)
  720. (kill-buffer)))
  721. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  722. ;; (setq term-ansi-default-program shell-file-name)
  723. (add-hook 'term-setup-hook (lambda ()
  724. (setq term-display-table (make-display-table))))
  725. (add-hook 'term-mode-hook (lambda ()
  726. (unless (memq (current-buffer) (and (featurep 'multi-term) ; current buffer is not multi-term buffer
  727. (multi-term-list)))
  728. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  729. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  730. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  731. ;; (define-key term-raw-map "\C-f" 'forward-char)
  732. ;; (define-key term-raw-map "\C-b" 'backward-char)
  733. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  734. (define-key term-raw-map "\C-x" (lookup-key (current-global-map) "\C-x"))
  735. (define-key term-raw-map "\C-z" (lookup-key (current-global-map) "\C-z")))
  736. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  737. (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  738. (define-key term-raw-map [delete] 'term-send-raw)
  739. (define-key term-raw-map "\C-h" 'term-send-backspace)
  740. (define-key term-raw-map "\C-y" 'term-paste)
  741. (define-key term-raw-map "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  742. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  743. ;; (define-key term-raw-map (kbd key) 'term-send-raw))
  744. ;; (define-key term-raw-map "\C-d" 'delete-char)
  745. (set (make-variable-buffer-local 'scroll-margin) 0)
  746. ;; (set (make-variable-buffer-local 'cua-enable-cua-keys) nil)
  747. ;; (cua-mode 0)
  748. ;; (and cua-mode
  749. ;; (local-unset-key (kbd "C-c")))
  750. ;; (define-key cua--prefix-override-keymap "\C-c" 'term-interrupt-subjob)
  751. ))
  752. ;; (add-hook 'term-exec-hook 'forward-char)
  753. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  754. ;; buffer switching
  755. (when (require 'bs nil t)
  756. ;; (global-set-key "\C-x\C-b" 'bs-show)
  757. (defalias 'list-buffers 'bs-show))
  758. ;; (add-to-list 'bs-configurations '("processes" nil get-buffer-process ".*" nil nil))
  759. (add-to-list 'bs-configurations '("same-dir" nil buffer-same-dir-p ".*" nil nil))
  760. (add-to-list 'bs-configurations '("this-frame" nil (lambda (buf) (memq buf (my-frame-buffer-get))) ".*" nil nil))
  761. ;; (setq bs-configurations (list '("processes" nil get-buffer-process ".*" nil nil)
  762. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil bs-visits-non-file bs-sort-buffer-interns-are-last)))
  763. (setq bs-default-configuration "this-frame")
  764. (setq bs-default-sort-name "by name")
  765. (add-hook 'bs-mode-hook
  766. (lambda ()
  767. (setq bs-default-configuration "this-frame")
  768. ;; (and bs--show-all
  769. ;; (call-interactively 'bs-toggle-show-all))
  770. (set (make-variable-buffer-local 'scroll-margin) 0)
  771. ))
  772. (defun buffer-same-dir-p (bf)
  773. "return t if BF's dir is same as current dir, otherwise nil."
  774. (let ((cdir (expand-file-name default-directory)))
  775. (with-current-buffer bf
  776. (equal (expand-file-name default-directory) cdir))))
  777. (defun echo-buffer-list (&optional blist)
  778. "echo buffer list as string. BLIST is list with buffer objects as elements.
  779. if arg is omitted use value of `buffer-list'."
  780. (interactive)
  781. (message (or (mapconcat (lambda (bf)
  782. (concat (buffer-name bf)
  783. "\t"
  784. (with-current-buffer bf
  785. (symbol-name major-mode))
  786. "\t"
  787. (abbreviate-file-name (buffer-file-name bf))))
  788. (or blist
  789. (buffer-list))
  790. "\n")
  791. "")))
  792. (defun my-buffer-list ()
  793. "return buffer list."
  794. (delq nil
  795. (mapcar (lambda (bf)
  796. (with-current-buffer bf
  797. (and buffer-file-name
  798. bf)))
  799. (buffer-list (selected-frame)))))
  800. (defvar buffer-switch-list-function 'my-buffer-list)
  801. (defun switch-to-previous-buffer-cycle (&optional silent-p)
  802. ""
  803. (interactive)
  804. (let ((bl (funcall buffer-switch-list-function)))
  805. (when bl
  806. (bury-buffer (car bl))
  807. (switch-to-buffer (or (nth 1 bl)
  808. (car bl)))
  809. (or silent-p
  810. (echo-buffer-list (funcall buffer-switch-list-function))))))
  811. (defun switch-to-next-buffer-cycle (&optional silent-p)
  812. ""
  813. (interactive)
  814. (let* ((bl (funcall buffer-switch-list-function))
  815. (bf (nth (- (length bl)
  816. 1)
  817. bl)))
  818. (when bl
  819. (switch-to-buffer bf)
  820. (or silent-p
  821. (echo-buffer-list (funcall buffer-switch-list-function))))))
  822. (iswitchb-mode 1)
  823. (defun iswitchb-buffer-display-other-window ()
  824. ""
  825. (interactive)
  826. (let ((iswitchb-default-method 'display))
  827. (call-interactively 'iswitchb-buffer)))
  828. (defun switch-to-other-buffer ()
  829. ""
  830. (interactive)
  831. (let ((buffer-switch-list-function 'buffer-list))
  832. (switch-to-previous-buffer-cycle t)))
  833. (global-set-key (kbd "C-.") 'switch-to-previous-buffer-cycle)
  834. (global-set-key (kbd "C-,") 'switch-to-next-buffer-cycle)
  835. ;; (global-set-key (kbd "C-\\") 'switch-to-other-buffer)
  836. ;; (global-set-key (kbd "C-\\") 'bury-buffer)
  837. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  838. ;; sdic
  839. (defun sdic-describe-word-at-point-echo ()
  840. ""
  841. (interactive)
  842. (save-window-excursion
  843. (sdic-describe-word-at-point))
  844. (save-excursion
  845. (set-buffer sdic-buffer-name)
  846. (message (buffer-substring (point-min)
  847. (progn (goto-char (point-min))
  848. (or (and (re-search-forward "^\\w" nil t 4)
  849. (progn (previous-line) t)
  850. (point-at-eol))
  851. (point-max)))))))
  852. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  853. (setq sdic-waei-dictionary-list '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  854. (setq sdic-disable-select-window t)
  855. (setq sdic-window-height 7)
  856. (when (require 'sdic nil t)
  857. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  858. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo))
  859. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  860. ;; vc
  861. ;; (require 'vc)
  862. (setq vc-handled-backends nil)
  863. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  864. ;; gauche-mode
  865. (setq scheme-program-name "gosh")
  866. (defun run-gauche-other-window ()
  867. "Run gauche on other window"
  868. (interactive)
  869. (switch-to-buffer-other-window
  870. (get-buffer-create "*scheme*"))
  871. (run-gauche))
  872. (defun run-gauche ()
  873. "run gauche"
  874. (run-scheme "gosh"))
  875. (defun scheme-send-buffer ()
  876. ""
  877. (interactive)
  878. (scheme-send-region (point-min) (point-max)))
  879. (add-hook 'scheme-mode-hook
  880. (lambda ()
  881. (define-key scheme-mode-map "\C-c\C-b" 'scheme-send-buffer)))
  882. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  883. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  884. (when (dllib-if-unfound "gauche-mode"
  885. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  886. t)
  887. (setq auto-mode-alist
  888. (cons '("\.scm$" . gauche-mode) auto-mode-alist))
  889. (autoload 'gauche-mode "gauche-mode" "Major mode for Scheme." t)
  890. (autoload 'run-scheme "gauche-mode" "Run an inferior Scheme process." t)
  891. (add-hook 'gauche-mode-hook
  892. (lambda ()
  893. (define-key scheme-mode-map "\C-c\C-z" 'run-gauche-other-window))))
  894. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  895. ;; recentf-mode
  896. (add-hook 'recentf-dialog-mode-hook
  897. 'my-recentf-abbrev-list)
  898. (defun my-recentf-delete-entry ()
  899. ""
  900. (interactive)
  901. (let ((p (point)))
  902. (setq recentf-list
  903. (delete (my-recentf-get-filename) recentf-list))
  904. (recentf-open-files)
  905. (goto-char p)))
  906. (defun my-recentf-abbrev-list ()
  907. ""
  908. (setq recentf-list
  909. (mapcar 'abbreviate-file-name
  910. recentf-list)))
  911. (defun my-recentf-view-file ()
  912. ""
  913. (interactive)
  914. (view-file (my-recentf-get-filename)))
  915. (defun my-recentf-dired ()
  916. ""
  917. (interactive)
  918. (let ((file (my-recentf-get-filename)))
  919. (if (file-directory-p file)
  920. (dired file)
  921. (dired (or (file-name-directory file)
  922. ".")))))
  923. (defun my-recentf-x-open ()
  924. ""
  925. (interactive)
  926. (my-x-open (my-recentf-get-filename)))
  927. (defun my-recentf-cd-and-find-file ()
  928. ""
  929. (interactive)
  930. (cd (file-name-directory (my-recentf-get-filename)))
  931. (call-interactively 'find-file))
  932. (defun my-recentf-get-filename ()
  933. "get file name in recentf-mode"
  934. (replace-regexp-in-string " \\(\\[.+?\\] \\)?" ; " " or " [\\d] "
  935. ""
  936. (buffer-substring-no-properties (point-at-bol)
  937. (point-at-eol))))
  938. (setq recentf-save-file (expand-file-name "~/.emacs.d/.recentf")
  939. recentf-max-menu-items 20
  940. recentf-max-saved-items 30
  941. recentf-show-file-shortcuts-flag nil)
  942. (when (require 'recentf nil t)
  943. (global-set-key "\C-x\C-r" 'recentf-open-files)
  944. ;; (add-hook 'find-file-hook
  945. ;; (lambda ()
  946. ;; (recentf-add-file default-directory)))
  947. (recentf-mode 1)
  948. (add-to-list 'recentf-filename-handlers 'abbreviate-file-name)
  949. (add-to-list 'recentf-exclude "\\.emacs\\.d/\\.recentf"))
  950. (add-hook 'recentf-dialog-mode-hook
  951. (lambda ()
  952. (recentf-save-list)
  953. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f") 'my-recentf-cd-and-find-file)
  954. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  955. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  956. (define-key recentf-dialog-mode-map "o" 'my-recentf-x-open)
  957. (define-key recentf-dialog-mode-map "d" 'my-recentf-delete-entry)
  958. (define-key recentf-dialog-mode-map "@" 'my-recentf-dired)
  959. (define-key recentf-dialog-mode-map "v" 'my-recentf-view-file)
  960. (cd "~/")))
  961. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  962. ;; dired
  963. (require 'dired)
  964. (defun my-dired-echo-file-head (&optional arg)
  965. ""
  966. (interactive "P")
  967. (let ((f (dired-get-filename)))
  968. (message "%s"
  969. (with-temp-buffer
  970. (insert-file-contents f)
  971. (buffer-substring-no-properties (point-min)
  972. (progn (goto-line (if arg
  973. (prefix-numeric-value arg)
  974. 10))
  975. (point-at-eol)))))))
  976. (defun my-dired-diff ()
  977. ""
  978. (interactive)
  979. (let ((files (dired-get-marked-files nil nil nil t)))
  980. (if (eq (car files)
  981. t)
  982. (diff (cadr files) (dired-get-filename))
  983. (message "One files must be marked!"))))
  984. (require 'dired-aux) ;; needed to use dired-dwim-target-directory
  985. (defun my-dired-do-pack-or-unpack ()
  986. "pack or unpack files.
  987. if targetting one file and that is archive file defined in `pack-program-alist', unpack that.
  988. otherwise, pack marked files. prompt user to decide filename for archive."
  989. (interactive)
  990. (let* ((infiles (dired-get-marked-files t))
  991. (onefile (and (eq 1 ; filename if only one file targeted, otherwise nil.
  992. (length infiles))
  993. (car infiles))))
  994. (if (and onefile
  995. (my-pack-file-name-association onefile))
  996. (when (y-or-n-p (format "unpack %s? " onefile))
  997. (my-unpack onefile))
  998. (let* ((dir-default (dired-dwim-target-directory))
  999. (archive-default (my-pack-file-extension (file-name-nondirectory (car infiles))))
  1000. (archive ;; (if (interactive-p)
  1001. (read-file-name "Output file to pack : "
  1002. dir-default
  1003. nil
  1004. nil
  1005. archive-default)
  1006. ;; (concat dir-default archive-default)
  1007. ))
  1008. (apply 'my-pack
  1009. archive
  1010. infiles))))
  1011. (revert-buffer)
  1012. ;; (dired-unmark-all-marks)
  1013. )
  1014. (defun my-file-name-extension-with-tar (filename)
  1015. "if FILENAME has extension with tar, like \"tar.gz\", return that.
  1016. otherwise, return extension normally."
  1017. (if (string-equal "tar" (file-name-extension (file-name-sans-extension filename)))
  1018. (concat "tar."
  1019. (file-name-extension filename))
  1020. (file-name-extension filename)))
  1021. (defun my-pack-file-extension (filename)
  1022. "if FILENAME has extension and it can be used for pack, return FILENAME.
  1023. otherwise, return FILENAME with `my-pack-default-extension'"
  1024. (if (my-pack-file-name-association filename)
  1025. filename
  1026. (concat filename "." my-pack-default-extension)))
  1027. (defvar my-7z-program-name
  1028. (or (executable-find "7z")
  1029. (executable-find "7za")
  1030. (executable-find "7zr"))
  1031. "7z program.")
  1032. (defvar my-pack-default-extension
  1033. "7z"
  1034. "default suffix for packing. filename with this suffix must matches one of `pack-program-alist'")
  1035. (defun my-pack-file-name-association (filename)
  1036. "if the pattern matching FILENAME is found at car of the list in `pack-program-alist', return cdr of that list.
  1037. otherwise, return nil."
  1038. (let ((case-fold-search nil))
  1039. (assoc-default filename
  1040. my-pack-program-alist
  1041. 'string-match-p
  1042. nil)))
  1043. (defvar my-pack-program-alist
  1044. `(
  1045. ("\\.7z\\'" ,(concat my-7z-program-name " a") ,(concat my-7z-program-name " x"))
  1046. ("\\.zip\\'" "zip -r" "unzip")
  1047. ("\\.tar\\'" "tar cf" "tar xf")
  1048. ("\\.tgz\\'" "tar czf" "tar xzf")
  1049. ("\\.tar\\.gz\\'" "tar czf" "tar xzf")
  1050. )
  1051. "Alist of filename patterns, command for pack and unpack.
  1052. Each element looks like (REGEXP PACKING-COMMAND UNPACKING-COMMAND).
  1053. PACKING-COMMAND and UNPACKING-COMMAND can be nil if the command is not available.
  1054. alist is searched from the beginning so pattern for \".tar.gz\" should be ahead of pattern for \".gz\"")
  1055. ;; (string-match-p "\\.gz\\'" "aaa.gz") ; \' matches string end, $ also matches the point before newline.
  1056. (defun my-unpack (archive)
  1057. "unpack ARCHIVE. command for unpacking is defined in `pack-program-alist'"
  1058. (interactive "fArchive to extract: ")
  1059. (let* ((earchive (expand-file-name archive))
  1060. (cmd (nth 1
  1061. (my-pack-file-name-association earchive)))
  1062. )
  1063. (if cmd
  1064. (shell-command (concat cmd
  1065. " "
  1066. (shell-quote-argument earchive)))
  1067. (message "this is not archive file defined in `pack-program-alist'!"))))
  1068. (defun my-pack (archive &rest files)
  1069. "pack FILES into ARCHIVE.
  1070. if ARCHIVE have extension defined in `pack-program-alist', use that command.
  1071. otherwise, use `pack-default-extension' for pack."
  1072. (let* ((archive-ext (my-pack-file-extension (expand-file-name archive)))
  1073. (cmd (car (my-pack-file-name-association archive-ext)))
  1074. )
  1075. (if cmd
  1076. (shell-command (concat cmd
  1077. " "
  1078. (shell-quote-argument archive-ext)
  1079. " "
  1080. (mapconcat 'shell-quote-argument
  1081. files
  1082. " ")))
  1083. (message "invalid extension for packing!"))))
  1084. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1085. "pop up buffer using `display-buffer' and return that buffer."
  1086. (let ((bf (get-buffer-create buffer-or-name)))
  1087. (with-current-buffer bf
  1088. (cd ".")
  1089. (erase-buffer))
  1090. (display-buffer bf)
  1091. bf))
  1092. (defun my-replace-nasi-none ()
  1093. ""
  1094. (save-excursion
  1095. (let ((buffer-read-only nil))
  1096. (goto-char (point-min))
  1097. (while (search-forward "なし" nil t)
  1098. (replace-match "none")))))
  1099. (defun dired-get-du () ;em-unix.el使えるかも
  1100. "dired get disk usage"
  1101. (interactive)
  1102. (message "calculating du...")
  1103. (dired-do-shell-command "du -hs * " nil (dired-get-marked-files)))
  1104. (defun my-dired-scroll-up ()
  1105. ""
  1106. (interactive)
  1107. (my-dired-previous-line (- (window-height) 1)))
  1108. (defun my-dired-scroll-down ()
  1109. ""
  1110. (interactive)
  1111. (my-dired-next-line (- (window-height) 1)))
  1112. (defun my-dired-previous-line (&optional arg)
  1113. ""
  1114. (interactive)
  1115. (dired-previous-line (or arg 1))
  1116. (my-dired-print-current-dir-and-file))
  1117. (defun my-dired-next-line (&optional arg)
  1118. ""
  1119. (interactive)
  1120. (dired-next-line (or arg 1))
  1121. (my-dired-print-current-dir-and-file))
  1122. (defun my-dired-print-current-dir-and-file ()
  1123. (message "%s %s"
  1124. default-directory
  1125. (buffer-substring-no-properties (point-at-bol)
  1126. (point-at-eol))))
  1127. (defun dired-do-execute-as-command ()
  1128. ""
  1129. (interactive)
  1130. (let ((file (dired-get-filename t)))
  1131. (if (file-executable-p file)
  1132. (start-process file nil file)
  1133. (when (y-or-n-p "this file cant be executed. mark as executable and go? : ")
  1134. (set-file-modes file (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1135. (start-process file nil file)))))
  1136. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1137. (defun my-dired-x-open ()
  1138. ""
  1139. (interactive)
  1140. (my-x-open (dired-get-filename t t)))
  1141. (if (eq window-system 'mac)
  1142. (setq dired-listing-switches "-lhFG")
  1143. (setq dired-listing-switches "-lhFG --time-style=long-iso")
  1144. )
  1145. (setq dired-listing-switches "-lhFG")
  1146. (define-minor-mode my-dired-display-all-mode
  1147. ""
  1148. :init-value nil
  1149. :global nil
  1150. :lighter " ALL"
  1151. (when (eq major-mode 'dired-mode)
  1152. (my-dired-display-all-set)
  1153. (revert-buffer)))
  1154. (defun my-dired-display-all-set ()
  1155. ""
  1156. (if my-dired-display-all-mode
  1157. (or (string-match-p my-dired-display-all-switch
  1158. dired-actual-switches)
  1159. (setq dired-actual-switches
  1160. (concat my-dired-display-all-switch
  1161. " "
  1162. dired-actual-switches)))
  1163. (setq dired-actual-switches
  1164. (replace-regexp-in-string (concat my-dired-display-all-switch
  1165. " ")
  1166. ""
  1167. dired-actual-switches))))
  1168. (defvar my-dired-display-all-switch "-A")
  1169. (add-hook 'dired-mode-hook
  1170. 'my-dired-display-all-set)
  1171. (put 'dired-find-alternate-file 'disabled nil)
  1172. (setq dired-ls-F-marks-symlinks t)
  1173. (require 'ls-lisp)
  1174. (setq ls-lisp-use-insert-directory-program nil)
  1175. (setq ls-lisp-dirs-first t)
  1176. (setq ls-lisp-use-localized-time-format t)
  1177. (setq ls-lisp-format-time-list
  1178. '("%Y-%m-%d %H:%M"
  1179. "%Y-%m-%d "))
  1180. (setq dired-dwim-target t)
  1181. ;; (add-hook 'dired-after-readin-hook
  1182. ;; 'my-replace-nasi-none)
  1183. ;; (add-hook 'after-init-hook
  1184. ;; (lambda ()
  1185. ;; (dired ".")))
  1186. (add-hook 'dired-mode-hook
  1187. (lambda ()
  1188. (define-key dired-mode-map "o" 'my-dired-x-open)
  1189. (define-key dired-mode-map "i" 'dired-get-du)
  1190. (define-key dired-mode-map "!" 'shell-command)
  1191. (define-key dired-mode-map "&" 'async-shell-command)
  1192. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1193. (define-key dired-mode-map "=" 'my-dired-diff)
  1194. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1195. (define-key dired-mode-map "b" 'gtkbm)
  1196. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1197. (define-key dired-mode-map "@" (lambda () (interactive) (my-x-open ".")))
  1198. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1199. (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1200. (define-key dired-mode-map "a" 'my-dired-display-all-mode)
  1201. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1202. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1203. (substitute-key-definition 'dired-next-line 'my-dired-next-line dired-mode-map)
  1204. (substitute-key-definition 'dired-previous-line 'my-dired-previous-line dired-mode-map)
  1205. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1206. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1207. (let ((file "._Icon\015"))
  1208. (when (file-readable-p file)
  1209. (delete-file file)))))
  1210. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1211. (defun my-dired-toggle-mark()
  1212. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1213. (t dired-marker-char))))
  1214. (delete-char 1)
  1215. (insert cur)))
  1216. (defun my-dired-mark (arg)
  1217. "toggle mark the current (or next ARG) files.
  1218. If on a subdir headerline, mark all its files except `.' and `..'.
  1219. Use \\[dired-unmark-all-files] to remove all marks
  1220. and \\[dired-unmark] on a subdir to remove the marks in
  1221. this subdir."
  1222. (interactive "P")
  1223. (if (dired-get-subdir)
  1224. (save-excursion (dired-mark-subdir-files))
  1225. (let ((inhibit-read-only t))
  1226. (dired-repeat-over-lines
  1227. (prefix-numeric-value arg)
  1228. 'my-dired-toggle-mark))))
  1229. (defun my-dired-mark-backward (arg)
  1230. "In Dired, move up lines and toggle mark there.
  1231. Optional prefix ARG says how many lines to unflag; default is one line."
  1232. (interactive "p")
  1233. (my-dired-mark (- arg)))
  1234. (defun dired-mode-hooks()
  1235. (local-set-key (kbd "SPC") 'my-dired-mark)
  1236. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1237. (add-hook 'dired-mode-hook 'dired-mode-hooks)
  1238. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1239. ;; eshell
  1240. (defun my-eshell-backward-delete-char ()
  1241. (interactive)
  1242. (when (< (save-excursion
  1243. (eshell-bol)
  1244. (point))
  1245. (point))
  1246. (backward-delete-char 1)))
  1247. (defun my-file-owner-p (file)
  1248. "t if FILE is owned by me."
  1249. (eq (user-uid) (nth 2 (file-attributes file))))
  1250. ;; ;; http://www.bookshelf.jp/pukiwiki/pukiwiki.php?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9
  1251. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1252. ;; (defun eshell/less (&rest args)
  1253. ;; "Invoke `view-file' on the file.
  1254. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1255. ;; (if args
  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. ;; (view-file file)
  1261. ;; (goto-line line))
  1262. ;; (view-file (pop args))))))
  1263. ;; (defun eshell/git (&rest args)
  1264. ;; ""
  1265. ;; )
  1266. (defun eshell/o (&optional file)
  1267. (my-x-open (or file ".")))
  1268. ;; (defun eshell/vi (&rest args)
  1269. ;; "Invoke `find-file' on the file.
  1270. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1271. ;; (while args
  1272. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1273. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1274. ;; (file (pop args)))
  1275. ;; (find-file file)
  1276. ;; (goto-line line))
  1277. ;; (find-file (pop args)))))
  1278. (defun eshell/clear ()
  1279. "Clear the current buffer, leaving one prompt at the top."
  1280. (let ((inhibit-read-only t))
  1281. (erase-buffer)))
  1282. (defun eshell/d (&optional dirname switches)
  1283. "if first arg is omitted open current directory."
  1284. (dired (or dirname ".") switches))
  1285. (defun eshell/v ()
  1286. (view-mode 1))
  1287. (defalias 'eshell/: 'ignore)
  1288. (defalias 'eshell/type 'eshell/which)
  1289. ;; (defalias 'eshell/vim 'eshell/vi)
  1290. (defalias 'eshell/ff 'find-file)
  1291. (defalias 'eshell/q 'eshell/exit)
  1292. (defun eshell-goto-prompt ()
  1293. ""
  1294. (interactive)
  1295. (goto-char (point-max)))
  1296. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1297. "open eshell and change wd
  1298. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1299. (interactive)
  1300. (let ((dir (expand-file-name default-directory)))
  1301. (switch-to-buffer (or eshell-buffer-or-name
  1302. (eshell t)))
  1303. (unless (equal dir (expand-file-name default-directory))
  1304. ;; (cd dir)
  1305. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1306. ;; (eshell-emit-prompt)
  1307. (goto-char (point-max))
  1308. (eshell-kill-input)
  1309. (insert "cd " dir)
  1310. (eshell-send-input))))
  1311. (setq eshell-directory-name "~/.emacs.d/eshell/")
  1312. (setq eshell-term-name "eterm-color")
  1313. (setq eshell-scroll-to-bottom-on-input t)
  1314. (setq eshell-cmpl-ignore-case t)
  1315. (setq eshell-cmpl-cycle-completions nil)
  1316. (setq eshell-highlight-prompt nil)
  1317. (setq eshell-ls-initial-args "-FG") ; "-hF")
  1318. (setq eshell-prompt-function
  1319. (lambda ()
  1320. (with-temp-buffer
  1321. (let (p1 p2 p3 p4)
  1322. (insert " [")
  1323. (setq p1 (point))
  1324. (insert (abbreviate-file-name default-directory))
  1325. (setq p2 (point))
  1326. (insert "]"
  1327. "\n")
  1328. (setq p3 (point))
  1329. (insert user-login-name
  1330. "@"
  1331. (or (getenv "HOSTNAME")
  1332. (substring (shell-command-to-string (or (executable-find "hostname")
  1333. "echo ''"))
  1334. 0
  1335. -1)))
  1336. (setq p4 (point))
  1337. (insert " "
  1338. (format-time-string "%a, %d %b %Y %T %z")
  1339. " eshell\n"
  1340. "last:"
  1341. (number-to-string eshell-last-command-status)
  1342. (if (= (user-uid)
  1343. 0)
  1344. " # "
  1345. " $ "))
  1346. (add-text-properties p1
  1347. p2
  1348. '(face ((foreground-color . "yellow"))))
  1349. (add-text-properties p3
  1350. p4
  1351. '(face ((foreground-color . "cyan"))))
  1352. (buffer-substring (point-min)
  1353. (point-max))))))
  1354. (add-hook 'eshell-mode-hook
  1355. (lambda ()
  1356. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1357. ;; (interactive)
  1358. ;; (switch-to-buffer (other-buffer))))
  1359. (define-key eshell-mode-map (kbd "C-u") (lambda ()
  1360. (interactive)
  1361. (eshell-goto-prompt)
  1362. (eshell-kill-input)))
  1363. (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1364. (interactive)
  1365. (eshell-goto-prompt)
  1366. (my-keyboard-quit)))
  1367. (define-key eshell-mode-map (kbd "DEL") 'my-eshell-backward-delete-char)
  1368. (define-key eshell-mode-map (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1369. (define-key eshell-mode-map (kbd "C-n") 'eshell-next-matching-input-from-input)
  1370. (mapcar (lambda (alias)
  1371. (add-to-list 'eshell-command-aliases-list
  1372. alias))
  1373. '(
  1374. ; ("ll" "ls -l $*")
  1375. ; ("la" "ls -a $*")
  1376. ; ("lla" "ls -al $*")
  1377. ("ut" "slogin 03110414@un001.ecc.u-tokyo.ac.jp $*")
  1378. ("aptin" "apt-get install $*")
  1379. ("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*\"))")
  1380. ("g" "git $*")
  1381. ))
  1382. ; (eshell/alias "g" "git $*")
  1383. (add-to-list 'eshell-output-filter-functions 'eshell-truncate-buffer)
  1384. (apply 'eshell/addpath exec-path)
  1385. (set (make-variable-buffer-local 'scroll-margin) 0)
  1386. ;; (eshell/export "GIT_PAGER=")
  1387. ;; (eshell/export "GIT_EDITOR=")
  1388. (eshell/export "LC_MESSAGES=C")
  1389. (add-to-list 'eshell-visual-commands "vim")
  1390. (add-to-list 'eshell-visual-commands "git")
  1391. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1392. ))
  1393. ;; (eval-after-load "em-alias"
  1394. ;; '(progn ;; (eshell/alias "ll" "ls -l")
  1395. ;; ;; (eshell/alias "la" "ls -a")
  1396. ;; ;; (eshell/alias "lla" "ls -al")
  1397. ;; (eshell/alias "sgcc" (if (eq system-type 'windows-nt)
  1398. ;; "gcc -o win.$1.exe $1"
  1399. ;; "gcc -o ${uname}.$1.out $1"))
  1400. ;; (eshell/alias "slmgcc" (if (eq system-type 'windows-nt)
  1401. ;; "gcc -lm -o win.$1.exe $1"
  1402. ;; "gcc -lm -o ${uname}.$1.out $1"))
  1403. ;; ;; (eshell/alias "ut" "ssh g841105@un001.ecc.u-tokyo.ac.jp")
  1404. ;; (add-to-list 'recentf-exclude (concat eshell-directory-name "alias"))))
  1405. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1406. ;; 最終更新日時を得る
  1407. (defvar my-buffer-file-last-modified-time nil "")
  1408. (make-variable-buffer-local 'my-buffer-file-last-modified-time)
  1409. (defun my-get-file-last-modified-time (file)
  1410. ""
  1411. (nth 5
  1412. (file-attributes file)))
  1413. (defun my-set-buffer-file-last-modified-time ()
  1414. ""
  1415. (make-local-variable 'my-buffer-file-last-modified-time)
  1416. (setq my-buffer-file-last-modified-time
  1417. (format-time-string "%Y/%m/%d %H:%M" (my-get-file-last-modified-time buffer-file-name))))
  1418. (add-hook 'find-file-hook
  1419. 'my-set-buffer-file-last-modified-time)
  1420. (add-hook 'after-save-hook
  1421. 'my-set-buffer-file-last-modified-time)
  1422. (add-hook 'after-revert-hook
  1423. 'my-set-buffer-file-last-modified-time)
  1424. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1425. ;; auto saving
  1426. (defun my-save-this-buffer (silent-p)
  1427. "save current buffer if can without asking"
  1428. (let ((cm (if (current-message)
  1429. (format "%s\n" (current-message))
  1430. ""))
  1431. (fun (symbol-function (if silent-p
  1432. 'ignore
  1433. 'message))))
  1434. (cond ((active-minibuffer-window) nil)
  1435. ((not buffer-file-name) (funcall fun "%ssaving... this buffer doesn't visit any file." cm) nil)
  1436. ((not (file-exists-p buffer-file-name)) (funcall fun "%ssaving... file not exist. save manually first." com) nil)
  1437. (buffer-read-only (funcall fun "%ssaving... this buffer is read-only." cm) nil)
  1438. ((not (buffer-modified-p)) (funcal fun "%ssaving... not modified yet." cm) nil)
  1439. ((not (file-writable-p buffer-file-name)) (funcall fun "%ssaving... you cannot change this file." cm) nil)
  1440. (t (funcall fun "%ssaving..." cm)
  1441. (save-buffer)
  1442. (funcall fun "%ssaving... done." cm)))))
  1443. ;; (if (and buffer-file-name
  1444. ;; (not buffer-read-only)
  1445. ;; (buffer-modified-p)
  1446. ;; (file-writable-p buffer-file-name))
  1447. ;; (save-buffer))) ; 静かな方
  1448. (defvar my-auto-save-this-buffer nil "auto save timer object")
  1449. (defun my-auto-save-this-buffer (sec &optional silent-p)
  1450. "auto save current buffer if idle for SEC.
  1451. when SEC is nil, stop auto save if enabled."
  1452. (if sec
  1453. (progn (when my-auto-save-this-buffer
  1454. (cancel-timer my-auto-save-this-buffer)
  1455. (setq my-auto-save-this-buffer nil))
  1456. (setq my-auto-save-this-buffer (run-with-idle-timer sec t 'my-save-this-buffer silent-p)))
  1457. (when my-auto-save-this-buffer
  1458. (cancel-timer my-auto-save-this-buffer)
  1459. (setq my-auto-save-this-buffer nil))))
  1460. (my-auto-save-this-buffer 2 t)
  1461. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1462. ;; misc funcs
  1463. (defun my-format-time-string (&optional time)
  1464. ""
  1465. (let ((system-time-locale "C"))
  1466. (format-time-string "%a, %d %b %Y %T" time)))
  1467. (defvar my-filer nil)
  1468. (setq my-filer (or (executable-find "pcmanfm")
  1469. (executable-find "nautilus")))
  1470. (defun my-x-open (file)
  1471. "open file."
  1472. (interactive "FOpen File: ")
  1473. (setq file (expand-file-name file))
  1474. (message "Opening %s..." file)
  1475. (cond ((eq system-type 'windows-nt)
  1476. (call-process "cmd.exe" nil 0 nil "/c" "start" "" (convert-standard-filename file)))
  1477. ((eq system-type 'darwin)
  1478. (call-process "open" nil 0 nil file))
  1479. ((not (getenv "DESKTOP_SESSION"))
  1480. (find-file file))
  1481. (t
  1482. (if (file-directory-p file)
  1483. (call-process my-filer nil 0 nil file)
  1484. (call-process "xdg-open" nil 0 nil file))))
  1485. (recentf-add-file file)
  1486. (message "Opening %s...done" file))
  1487. (defvar my-auto-indent-buffer-mode-list
  1488. '(emacs-lisp-mode
  1489. sh-mode
  1490. js-mode
  1491. sgml-mode
  1492. c-mode
  1493. c++-mode))
  1494. (setq my-auto-indent-buffer-mode-list nil) ;disable
  1495. (defun my-indent-buffer ()
  1496. "indent whole buffer."
  1497. (interactive)
  1498. (indent-region (point-min)
  1499. (point-max)))
  1500. (defun my-auto-indent-buffer ()
  1501. ""
  1502. (when (memq major-mode my-auto-indent-buffer-mode-list)
  1503. (my-indent-buffer)))
  1504. (add-hook 'before-save-hook
  1505. 'my-auto-indent-buffer)
  1506. (defun my-keyboard-quit ()
  1507. ""
  1508. (interactive)
  1509. (run-hooks 'before-keyboard-quit-hook)
  1510. ;; (redisplay t)
  1511. (redraw-display)
  1512. ;; (run-hooks 'window-configuration-change-hook)
  1513. (my-revert-buffer-if-needed)
  1514. ;; (revert-buffer t t)
  1515. (keyboard-quit)
  1516. (insert "insert me")
  1517. (run-hooks 'after-keyboard-quit-hook))
  1518. (substitute-key-definition 'keyboard-quit 'my-keyboard-quit global-map)
  1519. ;; (global-set-key (kbd "C-g") 'my-keyboard-quit)
  1520. (defun my-convmv-sjis2utf8-test ()
  1521. "run `convmv -r -f sjis -t utf8 *'
  1522. this is test, does not rename files"
  1523. (interactive)
  1524. (shell-command "convmv -r -f sjis -t utf8 *"))
  1525. (defun my-convmv-sjis2utf8-notest ()
  1526. "run `convmv -r -f sjis -t utf8 * --notest'"
  1527. (interactive)
  1528. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  1529. (defun my-copy-whole-line ()
  1530. ""
  1531. (interactive)
  1532. (kill-new (concat (buffer-substring (point-at-bol)
  1533. (point-at-eol))
  1534. "\n")))
  1535. (defun kill-ring-save-buffer-file-name ()
  1536. "get current filename"
  1537. (interactive)
  1538. (let ((file buffer-file-name))
  1539. (if file
  1540. (progn (kill-new file)
  1541. (message file))
  1542. (message "not visiting file."))))
  1543. ;; ;; コマンド的な
  1544. ;; (defvar my-execute-func-list nil "func list")
  1545. ;; (defvar my-execute-func-hist-list nil "func hist list")
  1546. ;; (setq my-execute-func-list '("(call-interactively 'my-francaiscd-b)"
  1547. ;; "(call-interactively 'my-francaiscd-a)"
  1548. ;; "parsec47"
  1549. ;; "chromium-browser"
  1550. ;; "inkscape"
  1551. ;; "audacious"
  1552. ;; "gnome-terminal"
  1553. ;; "zkaicd.py"
  1554. ;; "glchess"))
  1555. ;; (defun my-execute-start-process-or-eval-sexp ()
  1556. ;; "execute something"
  1557. ;; (interactive)
  1558. ;; (let ((func (completing-read "command?: " my-execute-func-list nil nil "" my-execute-func-hist-list)))
  1559. ;; (if (string= "(" (substring func 0 1))
  1560. ;; (with-temp-buffer (insert func)
  1561. ;; (eval-buffer))
  1562. ;; (start-process "ps"
  1563. ;; nil
  1564. ;; func))))
  1565. (defvar my-revert-buffer-if-needed-last-buffer nil)
  1566. (defun my-revert-buffer-if-needed ()
  1567. ""
  1568. (interactive)
  1569. (unless (eq my-revert-buffer-if-needed-last-buffer (current-buffer))
  1570. (setq my-revert-buffer-if-needed-last-buffer (current-buffer))
  1571. (when (or (eq major-mode 'dired-mode)
  1572. (not (verify-visited-file-modtime (current-buffer))))
  1573. (revert-buffer t t)
  1574. (message "%s reverted." (buffer-name)))))
  1575. (add-hook 'post-command-hook ; 'window-configuration-change-hook
  1576. 'my-revert-buffer-if-needed)
  1577. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1578. ;; forked from http://d.hatena.ne.jp/khiker/20100119/window_resize
  1579. (define-key my-prefix-map (kbd "C-w") 'my-window-organizer)
  1580. (defun my-window-organizer ()
  1581. "Control window size and position."
  1582. (interactive)
  1583. (save-selected-window
  1584. (select-window (window-at 0 0))
  1585. (let ( ;; (window-obj (selected-window))
  1586. ;; (current-width (window-width))
  1587. ;; (current-height (window-height))
  1588. action
  1589. c)
  1590. (catch 'end-flag
  1591. (while t
  1592. (setq action
  1593. (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."
  1594. (window-width)
  1595. (window-height))))
  1596. (setq c (aref action 0))
  1597. (cond ((= c ?l)
  1598. (unless (eq (window-width) (frame-width))
  1599. (enlarge-window-horizontally 1)))
  1600. ((= c ?h)
  1601. (unless (eq (window-width) (frame-width))
  1602. (shrink-window-horizontally 1)))
  1603. ((= c ?j)
  1604. (enlarge-window 1))
  1605. ((= c ?k)
  1606. (shrink-window 1))
  1607. ((= c ?o)
  1608. (other-window 1))
  1609. ((memq c '(?d ?0))
  1610. (unless (eq (selected-window) (next-window (selected-window) 0 1))
  1611. (delete-window (selected-window))))
  1612. ((= c ?1)
  1613. (delete-other-windows))
  1614. ((= c ?2)
  1615. (split-window-vertically))
  1616. ((= c ?3)
  1617. (split-window-horizontally))
  1618. ((memq c '(?q ?\C-g))
  1619. (message "Quit")
  1620. (throw 'end-flag t))
  1621. (t
  1622. (beep))))))))
  1623. ;; (aref (read-key-sequence-vector "aa") 0)
  1624. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1625. ;; save and restore frame size
  1626. ;;http://www.bookshelf.jp/soft/meadow_30.html#SEC416
  1627. (defun my-window-size-save ()
  1628. (let* ((rlist (frame-parameters (selected-frame)))
  1629. (ilist initial-frame-alist)
  1630. (nCHeight (frame-height))
  1631. (nCWidth (frame-width))
  1632. (tMargin (if (integerp (cdr (assoc 'top rlist)))
  1633. (cdr (assoc 'top rlist)) 0))
  1634. (lMargin (if (integerp (cdr (assoc 'left rlist)))
  1635. (cdr (assoc 'left rlist)) 0))
  1636. buf
  1637. (file "~/.emacs.d/.framesize.el")
  1638. (recentf-exclude '("\\.emacs\\.d/\\.framesize\\.el$")))
  1639. (if (get-file-buffer (expand-file-name file))
  1640. (setq buf (get-file-buffer (expand-file-name file)))
  1641. (setq buf (find-file-noselect file)))
  1642. (set-buffer buf)
  1643. (erase-buffer)
  1644. (insert (concat
  1645. ;; 初期値をいじるよりも modify-frame-parameters
  1646. ;; で変えるだけの方がいい?
  1647. "(delete 'width default-frame-alist)\n"
  1648. "(delete 'height default-frame-alist)\n"
  1649. "(delete 'top default-frame-alist)\n"
  1650. "(delete 'left default-frame-alist)\n"
  1651. "(setq default-frame-alist (append (list\n"
  1652. "'(width . " (int-to-string nCWidth) ")\n"
  1653. "'(height . " (int-to-string nCHeight) ")\n"
  1654. "'(top . " (int-to-string tMargin) ")\n"
  1655. "'(left . " (int-to-string lMargin) "))\n"
  1656. "default-frame-alist))\n"
  1657. ;;"(setq default-frame-alist default-frame-alist)"
  1658. ))
  1659. (save-buffer)
  1660. ))
  1661. (defun my-window-size-load ()
  1662. (let* ((file "~/.emacs.d/.framesize.el"))
  1663. (if (file-exists-p file)
  1664. (load file))))
  1665. (when window-system
  1666. (my-window-size-load)
  1667. (add-hook 'after-init-hook ;何かがframeの大きさ勝手に変えやがる
  1668. (lambda ()
  1669. (run-with-timer 1
  1670. nil
  1671. (lambda ()
  1672. (modify-frame-parameters (selected-frame)
  1673. default-frame-alist))))
  1674. t)
  1675. (add-hook 'kill-emacs-hook
  1676. 'my-window-size-save))
  1677. ;; windowサイズを固定
  1678. ;; setq default-frame-alist
  1679. ;; (append (list '(width . 80)
  1680. ;; '(height . 35)
  1681. ;; )
  1682. ;; default-frame-alist)
  1683. ;; ) ;;デフォルトのフレーム設定
  1684. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1685. ;; ;; emacsを殺伐とさせる
  1686. ;; ;; 補完させるとき失敗するからなし
  1687. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  1688. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  1689. ;; (setq arg
  1690. ;; (concat arg
  1691. ;; (if (eq nil (string-match "\\. *$" arg)) ".")
  1692. ;; " And You are a Coward!")))
  1693. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1694. ;; ubuntu
  1695. (defun my-load-scim ()
  1696. "use scim-bridge.el as japanese im."
  1697. ;; Load scim-bridge.
  1698. (require 'scim-bridge)
  1699. ;; Turn on scim-mode automatically after loading .emacs
  1700. (add-hook 'after-init-hook 'scim-mode-on)
  1701. (setq scim-cursor-color "red")
  1702. (scim-define-preedit-key ?\^h t)
  1703. (scim-define-common-key ?\* nil)
  1704. (scim-define-common-key ?\^/ nil))
  1705. (defun my-load-anthy ()
  1706. "use anthy.el as japanese im."
  1707. ;; anthy
  1708. (require 'anthy)
  1709. (global-set-key [muhenkan] (lambda () (interactive) (anthy-mode-off)))
  1710. (global-set-key [henkan] (lambda () (interactive) (anthy-mode-on)))
  1711. (when (>= emacs-major-version 23)
  1712. (setq anthy-accept-timeout 1)))
  1713. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1714. ;; windows用設定
  1715. ;; (add-to-list 'exec-path "c:/Program Files/Gauche/bin/")
  1716. (defun start-ckw-bash ()
  1717. ""
  1718. (interactive)
  1719. (start-process "ckw_bash"
  1720. nil
  1721. "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe")) ; cじゃないといけないらしい
  1722. (defun my-w32-add-export-path (&rest args)
  1723. ""
  1724. (mapcar (lambda (path)
  1725. (add-to-list 'exec-path (expand-file-name path)))
  1726. (reverse args))
  1727. (setenv "PATH"
  1728. (mapconcat 'convert-standard-filename
  1729. exec-path
  1730. ";")))
  1731. (when (eq system-type 'windows-nt)
  1732. ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i")
  1733. ;; (setq python-python-command "c:/Python26/python.exe")
  1734. (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash)
  1735. (my-w32-add-export-path "c:/WINDOWS"
  1736. (expand-file-name "~/bin")
  1737. (expand-file-name "~/dbx/apps/bin"))
  1738. (when window-system
  1739. (setq w32-enable-synthesized-fonts t))
  1740. (setq file-name-coding-system 'sjis))