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

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