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