Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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