Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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