Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

emacs.el 63 KiB

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