25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

.emacs.el 73 KiB

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