Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

.emacs 71 KiB

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