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 68 KiB

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