You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

emacs.el 68 KiB

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