You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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