Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

emacs.el 66 KiB

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