您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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