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