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

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