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.

emacs.el 67 KiB

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