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

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