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

13 years ago
12 years ago
13 years ago
13 years ago
11 years ago
8 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
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
9 years ago
9 years ago
12 years ago
9 years ago
9 years ago
9 years ago
13 years ago
13 years ago
11 years ago
13 years ago
13 years ago
11 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
11 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
8 years ago
8 years ago
13 years ago
11 years ago
11 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
10 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
8 years ago
10 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
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
9 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610
  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Commentary:
  3. ;;; Code:
  4. ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
  5. ;; SETUP_LOAD: (and (file-readable-p file)
  6. ;; SETUP_LOAD: (load-file file)))
  7. (setq debug-on-error t)
  8. ;; make directories
  9. (unless (file-directory-p (expand-file-name user-emacs-directory))
  10. (make-directory (expand-file-name user-emacs-directory)))
  11. (require 'cl-lib)
  12. (require 'simple)
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14. ;; Some macros for internals
  15. ;; `emacs --load emacs.el` with Emacs 24.3 requires with-eval-after-load to be
  16. ;; defined at the toplevel (means that it should not be defined inside of some
  17. ;; special forms like `when'. I do not now how to do with about this...)
  18. (unless (fboundp 'with-eval-after-load)
  19. ;; polyfill for Emacs < 24.4
  20. (defmacro with-eval-after-load (file &rest body)
  21. "After FILE is loaded execute BODY."
  22. (declare (indent 1) (debug t))
  23. `(eval-after-load ,file (quote (progn ,@body)))))
  24. (defun call-after-init (func)
  25. "If `after-init-hook' has been run, call FUNC immediately.
  26. Otherwize hook it."
  27. (if after-init-time
  28. (funcall func)
  29. (add-hook 'after-init-hook
  30. func)))
  31. (defmacro safe-require-or-eval (feature)
  32. "Require FEATURE if available.
  33. At compile time the feature will be loaded immediately."
  34. `(eval-and-compile
  35. (message "safe-require-or-eval: Trying to require %s" ,feature)
  36. (require ,feature nil t)))
  37. (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  38. "Define autoloading FEATURE that defines FUNCTIONS.
  39. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  40. the function same as FEATURE is defined as autoloaded function. BODY is passed
  41. to `eval-after-load'.
  42. After this macro is expanded, this returns the path to library if FEATURE
  43. found, otherwise returns nil."
  44. (declare (indent 2) (debug t))
  45. (let* ((libname (symbol-name (eval feature)))
  46. (libpath (locate-library libname)))
  47. `(progn
  48. (when (locate-library ,libname)
  49. ,@(mapcar (lambda (f)
  50. `(unless (fboundp ',f)
  51. (progn
  52. (message "Autoloaded function `%S' defined (%s)"
  53. (quote ,f)
  54. ,libpath)
  55. (autoload (quote ,f)
  56. ,libname
  57. ,(concat "Autoloaded function defined in \""
  58. libpath
  59. "\".")
  60. t))))
  61. (or (eval functions)
  62. `(,(eval feature)))))
  63. (eval-after-load ,feature
  64. (quote (progn
  65. ,@body)))
  66. (locate-library ,libname))))
  67. (when (autoload-eval-lazily 'tetris nil
  68. (message "Tetris loaded!"))
  69. (message "Tetris found!"))
  70. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  71. ;; package
  72. (set (defvar 10sr-package-list)
  73. '(
  74. vimrc-mode
  75. markdown-mode
  76. yaml-mode
  77. gnuplot-mode
  78. php-mode
  79. erlang
  80. js2-mode
  81. js-doc
  82. git-commit
  83. gitignore-mode
  84. adoc-mode
  85. malabar-mode
  86. ;; ack
  87. color-moccur
  88. ggtags
  89. flycheck
  90. auto-highlight-symbol
  91. hl-todo
  92. pp-c-l
  93. ;; is flymake installs are required?
  94. ;;flymake-jshint
  95. ;;flymake-python-pyflakes
  96. xclip
  97. foreign-regexp
  98. multi-term
  99. term-run
  100. editorconfig
  101. git-ps1-mode
  102. restart-emacs
  103. fill-column-indicator
  104. pkgbuild-mode
  105. minibuffer-line
  106. which-key
  107. ;; I think this works in place of my autosave lib
  108. super-save
  109. scala-mode
  110. ;;ensime
  111. editorconfig
  112. editorconfig-custom-majormode
  113. cyberpunk-theme
  114. grandshell-theme
  115. afternoon-theme
  116. git-command
  117. prompt-text
  118. ;; 10sr repository
  119. ;; 10sr-extras
  120. terminal-title
  121. recentf-show
  122. dired-list-all-mode
  123. pack
  124. set-modeline-color
  125. read-only-only-mode
  126. smart-revert
  127. autosave
  128. ;;window-organizer
  129. remember-major-modes-mode
  130. ilookup
  131. pasteboard
  132. end-mark
  133. sl
  134. gosh-mode
  135. ))
  136. (when (safe-require-or-eval 'package)
  137. (setq package-archives
  138. `(,@package-archives
  139. ("melpa" . "https://melpa.org/packages/")
  140. ("10sr-el" . "https://10sr.github.io/emacs-lisp/elpa/")))
  141. (package-initialize)
  142. (defun my-auto-install-package ()
  143. "Install packages semi-automatically."
  144. (interactive)
  145. (package-refresh-contents)
  146. (mapc (lambda (pkg)
  147. (or (package-installed-p pkg)
  148. (package-install pkg)))
  149. 10sr-package-list))
  150. )
  151. ;; (lazy-load-eval 'sudoku)
  152. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  153. ;; my-idle-hook
  154. (defvar my-idle-hook nil
  155. "Hook run when idle for several secs.")
  156. (defvar my-idle-hook-sec 5
  157. "Second to run `my-idle-hook'.")
  158. (run-with-idle-timer my-idle-hook-sec
  159. t
  160. (lambda ()
  161. (run-hooks 'my-idle-hook)))
  162. ;; (add-hook 'my-idle-hook
  163. ;; (lambda ()
  164. ;; (message "idle hook message")))
  165. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  166. ;; start and quit
  167. (setq inhibit-startup-message t)
  168. (setq confirm-kill-emacs 'y-or-n-p)
  169. (setq gc-cons-threshold (* 1024 1024 4))
  170. (when window-system
  171. (add-to-list 'default-frame-alist '(cursor-type . box))
  172. (add-to-list 'default-frame-alist '(background-color . "white"))
  173. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  174. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  175. ;; does not work?
  176. )
  177. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  178. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  179. (and (fboundp 'tool-bar-mode)
  180. (tool-bar-mode 0))
  181. (and (fboundp 'set-scroll-bar-mode)
  182. (set-scroll-bar-mode nil))
  183. (add-hook 'kill-emacs-hook
  184. ;; load init file when terminating emacs to ensure file is not broken
  185. 'reload-init-file)
  186. (defun my-force-kill-emacs ()
  187. "My force kill Emacs."
  188. (interactive)
  189. (let ((kill-emacs-hook nil))
  190. (kill-emacs)))
  191. (call-after-init
  192. (lambda ()
  193. (message "%s %s" invocation-name emacs-version)
  194. (message "Invocation directory: %s" default-directory)
  195. (message "%s was taken to initialize emacs." (emacs-init-time))
  196. (switch-to-buffer "*Messages*")))
  197. (cd ".") ; when using windows use / instead of \ in `default-directory'
  198. ;; locale
  199. (set-language-environment "Japanese")
  200. (set-default-coding-systems 'utf-8-unix)
  201. (prefer-coding-system 'utf-8-unix)
  202. (setq system-time-locale "C")
  203. ;; my prefix map
  204. (defvar my-prefix-map nil
  205. "My prefix map.")
  206. (define-prefix-command 'my-prefix-map)
  207. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  208. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  209. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  210. ;; (comint-show-maximum-output)
  211. ;; kill scratch
  212. (call-after-init (lambda ()
  213. (let ((buf (get-buffer "*scratch*")))
  214. (when buf
  215. (kill-buffer buf)))))
  216. ;; modifier keys
  217. ;; (setq mac-option-modifier 'control)
  218. ;; display
  219. (setq visible-bell t)
  220. (setq ring-bell-function 'ignore)
  221. (mouse-avoidance-mode 'banish)
  222. (setq echo-keystrokes 0.1)
  223. (defun reload-init-file ()
  224. "Reload Emacs init file."
  225. (interactive)
  226. (when (and user-init-file
  227. (file-readable-p user-init-file))
  228. (load-file user-init-file)))
  229. (safe-require-or-eval 'session)
  230. ;; server
  231. (set-variable 'server-name (concat "server"
  232. (number-to-string (emacs-pid))))
  233. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  234. ;; In Darwin environment, init fails with message like 'Service name too long'
  235. ;; when server-use-tcp is nil
  236. (when (or (eq system-type
  237. 'cygwin)
  238. (eq system-type
  239. 'darwin))
  240. (set-variable 'server-use-tcp t))
  241. ;; MSYS2 fix
  242. (when (eq system-type
  243. 'windows-nt)
  244. (setq shell-file-name
  245. (executable-find "bash"))
  246. '(setq function-key-map
  247. `(,@function-key-map ([pause] . [?\C-c])
  248. ))
  249. (define-key key-translation-map
  250. (kbd "<pause>")
  251. (kbd "C-c"))
  252. '(keyboard-translate [pause]
  253. (kbd "C-c")p)
  254. ;; TODO: move to other place later
  255. (when (not window-system)
  256. (setq interprogram-paste-function nil)
  257. (setq interprogram-cut-function nil)))
  258. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  259. ;; global keys
  260. (global-set-key (kbd "<up>") 'scroll-down-line)
  261. (global-set-key (kbd "<down>") 'scroll-up-line)
  262. (global-set-key (kbd "<left>") 'scroll-down)
  263. (global-set-key (kbd "<right>") 'scroll-up)
  264. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  265. (global-set-key (kbd "C-\\") help-map)
  266. (define-key ctl-x-map (kbd "DEL") help-map)
  267. (define-key ctl-x-map (kbd "C-h") help-map)
  268. (define-key help-map "a" 'apropos)
  269. ;; disable annoying keys
  270. (global-set-key [prior] 'ignore)
  271. (global-set-key (kbd "<next>") 'ignore)
  272. (global-set-key [menu] 'ignore)
  273. (global-set-key [down-mouse-1] 'ignore)
  274. (global-set-key [down-mouse-2] 'ignore)
  275. (global-set-key [down-mouse-3] 'ignore)
  276. (global-set-key [mouse-1] 'ignore)
  277. (global-set-key [mouse-2] 'ignore)
  278. (global-set-key [mouse-3] 'ignore)
  279. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  280. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  281. (when (safe-require-or-eval 'which-key)
  282. (which-key-mode))
  283. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  284. ;; editting
  285. (defun my-copy-whole-line ()
  286. "Copy whole line."
  287. (interactive)
  288. (kill-new (concat (buffer-substring (point-at-bol)
  289. (point-at-eol))
  290. "\n")))
  291. (setq require-final-newline t)
  292. (setq kill-whole-line t)
  293. (setq scroll-conservatively 35
  294. scroll-margin 2
  295. scroll-step 0)
  296. (setq-default major-mode 'text-mode)
  297. (setq next-line-add-newlines nil)
  298. (setq kill-read-only-ok t)
  299. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  300. ;; (setq-default line-spacing 0.2)
  301. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  302. (setq-default tab-width 4)
  303. (setq-default indent-tabs-mode nil)
  304. (setq-default indent-line-function 'indent-to-left-margin)
  305. ;; (setq-default indent-line-function nil)
  306. (setq-default truncate-lines nil)
  307. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  308. (delete-selection-mode 1)
  309. (cua-mode 0)
  310. (setq line-move-visual nil)
  311. ;; key bindings
  312. ;; moving around
  313. ;; (global-set-key (kbd "M-j") 'next-line)
  314. ;; (global-set-key (kbd "M-k") 'previous-line)
  315. ;; (global-set-key (kbd "M-h") 'backward-char)
  316. ;; (global-set-key (kbd "M-l") 'forward-char)
  317. ;;(keyboard-translate ?\M-j ?\C-j)
  318. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  319. (define-key esc-map "p" 'backward-paragraph)
  320. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  321. (define-key esc-map "n" 'forward-paragraph)
  322. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  323. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  324. (global-set-key (kbd "C-<left>") 'scroll-down)
  325. (global-set-key (kbd "C-<right>") 'scroll-up)
  326. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  327. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  328. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  329. ;; C-h and DEL
  330. (global-set-key (kbd "C-h") (kbd "DEL"))
  331. ;;(global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  332. (global-set-key (kbd "C-m") 'newline-and-indent)
  333. ;; (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  334. (define-key esc-map "k" 'my-copy-whole-line)
  335. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  336. (define-key esc-map "u" 'undo)
  337. (define-key esc-map "i" (kbd "ESC TAB"))
  338. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  339. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  340. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  341. (define-key my-prefix-map (kbd "C-o") 'occur)
  342. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  343. ;; title and mode-line
  344. (when (safe-require-or-eval 'terminal-title)
  345. ;; if TERM is not screen use default value
  346. (if (getenv "TMUX")
  347. ;; if use tmux locally just basename of current dir
  348. (set-variable 'terminal-title-format
  349. '((file-name-nondirectory (directory-file-name
  350. default-directory))))
  351. (if (and (let ((tty-type (frame-parameter nil
  352. 'tty-type)))
  353. (and tty-type
  354. (equal (car (split-string tty-type
  355. "-"))
  356. "screen")))
  357. (not (getenv "SSH_CONNECTION")))
  358. (set-variable 'terminal-title-format
  359. '((file-name-nondirectory (directory-file-name
  360. default-directory))))
  361. ;; seems that TMUX is used locally and ssh to remote host
  362. (set-variable 'terminal-title-format
  363. `("em:"
  364. ,user-login-name
  365. "@"
  366. ,(car (split-string (system-name)
  367. "\\."))
  368. ":"
  369. default-directory))
  370. )
  371. )
  372. (terminal-title-mode))
  373. (setq eol-mnemonic-dos "\\r\\n")
  374. (setq eol-mnemonic-mac "\\r")
  375. (setq eol-mnemonic-unix "\\n")
  376. (which-function-mode 0)
  377. (line-number-mode 0)
  378. (column-number-mode 0)
  379. (size-indication-mode 0)
  380. (setq mode-line-position
  381. '(:eval (format "L%%l/%d,C%%c"
  382. (count-lines (point-max)
  383. (point-min)))))
  384. (when (safe-require-or-eval 'git-ps1-mode)
  385. (git-ps1-mode))
  386. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  387. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  388. ;; minibuffer
  389. (setq insert-default-directory t)
  390. (setq completion-ignore-case t
  391. read-file-name-completion-ignore-case t
  392. read-buffer-completion-ignore-case t)
  393. (setq resize-mini-windows t)
  394. (temp-buffer-resize-mode 1)
  395. (savehist-mode 1)
  396. (defvar display-time-format "%Y/%m/%d %a %H:%M")
  397. (fset 'yes-or-no-p 'y-or-n-p)
  398. ;; complete symbol when `eval'
  399. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  400. (define-key minibuffer-local-map (kbd "C-u")
  401. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  402. ;; I dont know these bindings are good
  403. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  404. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  405. (when (safe-require-or-eval 'minibuffer-line)
  406. (set-face-underline 'minibuffer-line nil)
  407. (set-variable 'minibuffer-line-refresh-interval
  408. 25)
  409. (set-variable 'minibuffer-line-format
  410. `(,(concat user-login-name
  411. "@"
  412. (car (split-string (system-name)
  413. "\\."))
  414. ":")
  415. (:eval (abbreviate-file-name (or buffer-file-name
  416. default-directory)))
  417. (:eval (and (fboundp 'git-ps1-mode-get-current)
  418. (git-ps1-mode-get-current " [GIT:%s]")))
  419. " "
  420. (:eval (format-time-string display-time-format))))
  421. (minibuffer-line-mode 1)
  422. )
  423. (when (safe-require-or-eval 'prompt-text)
  424. (set-variable 'prompt-text-format
  425. `(,(concat ""
  426. user-login-name
  427. "@"
  428. (car (split-string (system-name)
  429. "\\."))
  430. ":")
  431. (:eval (abbreviate-file-name (or buffer-file-name
  432. default-directory)))
  433. (:eval (and (fboundp 'git-ps1-mode-get-current)
  434. (git-ps1-mode-get-current " [GIT:%s]")))
  435. " "
  436. (:eval (format-time-string display-time-format))
  437. "\n"
  438. (:eval (symbol-name this-command))
  439. ": "))
  440. (prompt-text-mode 1))
  441. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  442. ;; letters, font-lock mode and fonts
  443. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  444. ;; (set-window-margins (selected-window) 1 1)
  445. (and (or (eq system-type 'Darwin)
  446. (eq system-type 'darwin))
  447. (fboundp 'mac-set-input-method-parameter)
  448. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  449. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  450. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  451. (boundp 'input-method-inactivate-hook))
  452. (add-hook 'input-method-activate-hook
  453. (lambda () (set-cursor-color "red")))
  454. (add-hook 'input-method-inactivate-hook
  455. (lambda () (set-cursor-color "black"))))
  456. (when (safe-require-or-eval 'paren)
  457. (show-paren-mode 1)
  458. (setq show-paren-delay 0.5
  459. show-paren-style 'parenthesis) ; mixed is hard to read
  460. ;; (set-face-background 'show-paren-match
  461. ;; "black")
  462. ;; ;; (face-foreground 'default))
  463. ;; (set-face-foreground 'show-paren-match
  464. ;; "white")
  465. ;; (set-face-inverse-video-p 'show-paren-match
  466. ;; t)
  467. )
  468. (transient-mark-mode 1)
  469. (global-font-lock-mode 1)
  470. (setq font-lock-global-modes
  471. '(not
  472. help-mode
  473. eshell-mode
  474. ;;term-mode
  475. Man-mode))
  476. ;; (standard-display-ascii ?\n "$\n")
  477. ;; (defvar my-eol-face
  478. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  479. ;; )
  480. ;; (defvar my-tab-face
  481. ;; '(("\t" . '(0 highlight t nil))))
  482. (defvar my-jspace-face
  483. '(("\u3000" . '(0 highlight t nil))))
  484. (add-hook 'font-lock-mode-hook
  485. (lambda ()
  486. ;; (font-lock-add-keywords nil my-eol-face)
  487. (font-lock-add-keywords nil my-jspace-face)
  488. ))
  489. (when (safe-require-or-eval 'whitespace)
  490. (add-to-list 'whitespace-display-mappings
  491. ;; We need t since last one takes precedence
  492. `(tab-mark ?\t ,(vconcat "^I\t")) t)
  493. ;; (add-to-list 'whitespace-display-mappings
  494. ;; `(newline-mark ?\n ,(vconcat "$\n")))
  495. (setq whitespace-style '(face
  496. trailing ; trailing blanks
  497. newline ; newlines
  498. newline-mark ; use display table for newline
  499. tab-mark
  500. empty ; empty lines at beg or end of buffer
  501. lines-tail ; lines over 80
  502. ))
  503. ;; (setq whitespace-newline 'font-lock-comment-face)
  504. (set-variable 'whitespace-line-column nil)
  505. (global-whitespace-mode t)
  506. (add-hook 'dired-mode-hook
  507. (lambda ()
  508. (set (make-local-variable 'whitespace-style) nil)))
  509. (if (eq (display-color-cells)
  510. 256)
  511. (set-face-foreground 'whitespace-newline "color-109")
  512. ;; (progn
  513. ;; (set-face-bold-p 'whitespace-newline
  514. ;; t))
  515. ))
  516. (and nil
  517. (safe-require-or-eval 'fill-column-indicator)
  518. (setq fill-column-indicator))
  519. ;; highlight current line
  520. ;; http://wiki.riywo.com/index.php?Meadow
  521. (face-spec-set 'hl-line
  522. '((((min-colors 256)
  523. (background dark))
  524. (:background "color-234"))
  525. (((min-colors 256)
  526. (background light))
  527. (:background "color-234"))
  528. (t
  529. (:underline "black"))))
  530. (set-variable 'hl-line-global-modes
  531. '(not
  532. term-mode))
  533. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  534. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  535. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  536. ;;(safe-require-or-eval 'set-modeline-color)
  537. ;; (let ((fg (face-foreground 'default))
  538. ;; (bg (face-background 'default)))
  539. ;; (set-face-background 'mode-line-inactive
  540. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  541. ;; (set-face-foreground 'mode-line-inactive
  542. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  543. ;; (set-face-underline 'mode-line-inactive
  544. ;; t)
  545. ;; (set-face-underline 'vertical-border
  546. ;; nil)
  547. (when (safe-require-or-eval 'end-mark)
  548. (global-end-mark-mode))
  549. (when (safe-require-or-eval 'auto-highlight-symbol)
  550. (set-variable 'ahs-idle-interval 0.6)
  551. (global-auto-highlight-symbol-mode 1))
  552. ;; (when (safe-require-or-eval 'cyberpunk-theme)
  553. ;; (load-theme 'cyberpunk t)
  554. ;; (set-face-attribute 'button
  555. ;; nil
  556. ;; :inherit 'highlight)
  557. ;; (set-face-foreground 'mode-line-inactive
  558. ;; "white")
  559. ;; (face-spec-set 'term-color-black (face-default-spec 'term-color-black))
  560. ;; (face-spec-set 'term-color-red (face-default-spec 'term-color-red))
  561. ;; (face-spec-set 'term-color-green (face-default-spec 'term-color-green))
  562. ;; (face-spec-set 'term-color-yellow (face-default-spec 'term-color-yellow))
  563. ;; (face-spec-set 'term-color-blue (face-default-spec 'term-color-blue))
  564. ;; (face-spec-set 'term-color-magenta (face-default-spec 'term-color-magenta))
  565. ;; (face-spec-set 'term-color-cyan (face-default-spec 'term-color-cyan))
  566. ;; (face-spec-set 'term-color-white (face-default-spec 'term-color-white))
  567. ;; )
  568. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  569. ;; file handling
  570. (when (safe-require-or-eval 'editorconfig)
  571. ;; (set-variable 'editorconfig-get-properties-function
  572. ;; 'editorconfig-core-get-properties-hash)
  573. (editorconfig-mode 1))
  574. (when (fboundp 'editorconfig-custom-majormode)
  575. (add-hook 'editorconfig-custom-hooks
  576. 'editorconfig-custom-majormode))
  577. (when (fboundp 'editorconfig-charset-extras)
  578. (add-hook 'editorconfig-custom-hooks
  579. 'editorconfig-charset-extras))
  580. (setq revert-without-query '(".+"))
  581. ;; save cursor position
  582. (when (safe-require-or-eval 'saveplace)
  583. (setq-default save-place t)
  584. (setq save-place-file (concat user-emacs-directory
  585. "places")))
  586. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  587. (setq make-backup-files t)
  588. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  589. (setq backup-directory-alist
  590. (cons (cons "\\.*$" (expand-file-name (concat user-emacs-directory
  591. "backup")))
  592. backup-directory-alist))
  593. (setq version-control 'never)
  594. (setq delete-old-versions t)
  595. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  596. "auto-save/")))
  597. (setq delete-auto-save-files t)
  598. (add-to-list 'completion-ignored-extensions ".bak")
  599. ;; (setq delete-by-moving-to-trash t
  600. ;; trash-directory "~/.emacs.d/trash")
  601. (add-hook 'after-save-hook
  602. 'executable-make-buffer-file-executable-if-script-p)
  603. (set (defvar bookmark-default-file)
  604. (expand-file-name (concat user-emacs-directory
  605. "bmk")))
  606. (with-eval-after-load 'recentf
  607. (defvar recentf-exclude nil)
  608. (add-to-list 'recentf-exclude
  609. (regexp-quote bookmark-default-file)))
  610. (when (safe-require-or-eval 'smart-revert)
  611. (smart-revert-on))
  612. ;; autosave
  613. (when (safe-require-or-eval 'autosave)
  614. (autosave-set 8))
  615. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  616. ;; buffer killing
  617. ;; (defun my-delete-window-killing-buffer () nil)
  618. (defun my-query-kill-current-buffer ()
  619. "Interactively kill current buffer."
  620. (interactive)
  621. (if (y-or-n-p (concat "kill current buffer? :"))
  622. (kill-buffer (current-buffer))))
  623. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  624. (substitute-key-definition 'kill-buffer
  625. 'my-query-kill-current-buffer
  626. global-map)
  627. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  628. ;; share clipboard with x
  629. ;; this page describes this in details, but only these sexps seem to be needed
  630. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  631. (and (not window-system)
  632. (not (eq window-system 'mac))
  633. (getenv "DISPLAY")
  634. (not (equal (getenv "DISPLAY") ""))
  635. (executable-find "xclip")
  636. ;; (< emacs-major-version 24)
  637. (safe-require-or-eval 'xclip)
  638. nil
  639. (turn-on-xclip))
  640. (and (eq system-type 'darwin)
  641. (safe-require-or-eval 'pasteboard)
  642. (turn-on-pasteboard))
  643. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  644. ;; some modes and hooks
  645. ;; Workaround to avoid ensime error
  646. (defvar ensime-mode-key-prefix nil)
  647. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  648. (when (safe-require-or-eval 'company)
  649. (global-company-mode)
  650. (set-variable 'company-idle-delay 0.5)
  651. (set-variable 'company-minimum-prefix-length 2)
  652. (set-variable 'company-selection-wrap-around t))
  653. ;; https://github.com/lunaryorn/flycheck
  654. (when (safe-require-or-eval 'flycheck)
  655. (call-after-init 'global-flycheck-mode))
  656. (set-variable 'ac-ignore-case nil)
  657. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  658. (define-key ctl-x-map "t" 'term-run-shell-command))
  659. (add-to-list 'safe-local-variable-values
  660. '(encoding utf-8))
  661. (setq enable-local-variables :safe)
  662. (when (safe-require-or-eval 'remember-major-modes-mode)
  663. (remember-major-modes-mode 1))
  664. ;; Detect file type from shebang and set major-mode.
  665. (add-to-list 'interpreter-mode-alist
  666. '("python3" . python-mode))
  667. (add-to-list 'interpreter-mode-alist
  668. '("python2" . python-mode))
  669. (with-eval-after-load 'python
  670. (defvar python-mode-map (make-sparse-keymap))
  671. (define-key python-mode-map (kbd "C-m") 'newline-and-indent))
  672. ;; http://fukuyama.co/foreign-regexp
  673. '(and (safe-require-or-eval 'foreign-regexp)
  674. (progn
  675. (setq foreign-regexp/regexp-type 'perl)
  676. '(setq reb-re-syntax 'foreign-regexp)
  677. ))
  678. (autoload-eval-lazily 'sql '(sql-mode)
  679. (safe-require-or-eval 'sql-indent))
  680. (when (autoload-eval-lazily 'git-command)
  681. (define-key ctl-x-map "g" 'git-command))
  682. (when (safe-require-or-eval 'git-commit)
  683. (global-git-commit-mode 1))
  684. (with-eval-after-load 'git-commit
  685. (add-hook 'git-commit-setup-hook
  686. 'turn-off-auto-fill t))
  687. (autoload-eval-lazily 'sl)
  688. (with-eval-after-load 'rst
  689. (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
  690. ;; jdee is too old! use malabar instead
  691. (with-eval-after-load 'jdee
  692. (add-hook 'jdee-mode-hook
  693. (lambda ()
  694. (make-local-variable 'global-mode-string)
  695. (add-to-list 'global-mode-string
  696. mode-line-position))))
  697. ;; Cannot enable error thrown. Why???
  698. ;; https://github.com/m0smith/malabar-mode#Installation
  699. ;; (when (autoload-eval-lazily 'malabar-mode)
  700. ;; (add-to-list 'load-path
  701. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  702. ;; (safe-require-or-eval 'cedet-devel-load)
  703. ;; (call-after-init 'activate-malabar-mode))
  704. (with-eval-after-load 'make-mode
  705. (defvar makefile-mode-map (make-sparse-keymap))
  706. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  707. ;; this functions is set in write-file-functions, i cannot find any
  708. ;; good way to remove this.
  709. (fset 'makefile-warn-suspicious-lines 'ignore))
  710. (with-eval-after-load 'verilog-mode
  711. (defvar verilog-mode-map (make-sparse-keymap))
  712. (define-key verilog-mode-map ";" 'self-insert-command))
  713. (setq diff-switches "-u")
  714. (with-eval-after-load 'diff-mode
  715. ;; (when (and (eq major-mode
  716. ;; 'diff-mode)
  717. ;; (not buffer-file-name))
  718. ;; ;; do not pass when major-mode is derived mode of diff-mode
  719. ;; (view-mode 1))
  720. (set-face-attribute 'diff-header nil
  721. :foreground nil
  722. :background nil
  723. :weight 'bold)
  724. (set-face-attribute 'diff-file-header nil
  725. :foreground nil
  726. :background nil
  727. :weight 'bold)
  728. (set-face-foreground 'diff-index-face "blue")
  729. (set-face-attribute 'diff-hunk-header nil
  730. :foreground "cyan"
  731. :weight 'normal)
  732. (set-face-attribute 'diff-context nil
  733. ;; :foreground "white"
  734. :foreground nil
  735. :weight 'normal)
  736. (set-face-foreground 'diff-removed-face "red")
  737. (set-face-foreground 'diff-added-face "green")
  738. (set-face-background 'diff-removed-face nil)
  739. (set-face-background 'diff-added-face nil)
  740. (set-face-attribute 'diff-changed nil
  741. :foreground "magenta"
  742. :weight 'normal)
  743. (set-face-attribute 'diff-refine-change nil
  744. :foreground nil
  745. :background nil
  746. :weight 'bold
  747. :inverse-video t)
  748. ;; Annoying !
  749. ;;(diff-auto-refine-mode)
  750. )
  751. ;; (ffap-bindings)
  752. (set-variable 'browse-url-browser-function
  753. 'eww-browse-url)
  754. (set-variable 'sh-here-document-word "__EOC__")
  755. (when (autoload-eval-lazily 'adoc-mode
  756. nil
  757. (defvar adoc-mode-map (make-sparse-keymap))
  758. (define-key adoc-mode-map (kbd "C-m") 'newline))
  759. (setq auto-mode-alist
  760. `(("\\.adoc\\'" . adoc-mode)
  761. ("\\.asciidoc\\'" . adoc-mode)
  762. ,@auto-mode-alist)))
  763. (with-eval-after-load 'markup-faces
  764. ;; Is this too match ?
  765. (set-face-foreground 'markup-meta-face
  766. "color-245")
  767. (set-face-foreground 'markup-meta-hide-face
  768. "color-245")
  769. )
  770. ;; TODO: check if this is required
  771. (when (autoload-eval-lazily 'groovy-mode nil
  772. (defvar groovy-mode-map (make-sparse-keymap))
  773. (define-key groovy-mode-map "(" 'self-insert-command)
  774. (define-key groovy-mode-map ")" 'self-insert-command)
  775. (define-key groovy-mode-map (kbd "C-m") 'newline-and-indent)
  776. )
  777. (add-to-list 'auto-mode-alist
  778. '("build\\.gradle\\'" . groovy-mode)))
  779. (with-eval-after-load 'yaml-mode
  780. (defvar yaml-mode-map (make-sparse-keymap))
  781. (define-key yaml-mode-map (kbd "C-m") 'newline))
  782. (with-eval-after-load 'html-mode
  783. (defvar html-mode-map (make-sparse-keymap))
  784. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  785. (with-eval-after-load 'text-mode
  786. (define-key text-mode-map (kbd "C-m") 'newline))
  787. (add-to-list 'Info-default-directory-list
  788. (expand-file-name "~/.info/emacs-ja"))
  789. (with-eval-after-load 'apropos
  790. (defvar apropos-mode-map (make-sparse-keymap))
  791. (define-key apropos-mode-map "n" 'next-line)
  792. (define-key apropos-mode-map "p" 'previous-line))
  793. ;; `isearch' library does not call `provide' so cannot use with-eval-after-load
  794. ;; (define-key isearch-mode-map
  795. ;; (kbd "C-j") 'isearch-other-control-char)
  796. ;; (define-key isearch-mode-map
  797. ;; (kbd "C-k") 'isearch-other-control-char)
  798. ;; (define-key isearch-mode-map
  799. ;; (kbd "C-h") 'isearch-other-control-char)
  800. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  801. (define-key isearch-mode-map (kbd "M-r")
  802. 'isearch-query-replace-regexp)
  803. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  804. (setq lazy-highlight-cleanup nil)
  805. ;; face for isearch highlighing
  806. (set-face-attribute 'lazy-highlight
  807. nil
  808. :foreground `unspecified
  809. :background `unspecified
  810. :underline t
  811. ;; :weight `bold
  812. )
  813. (add-hook 'outline-mode-hook
  814. (lambda ()
  815. (when (string-match "\\.md\\'" buffer-file-name)
  816. (set (make-local-variable 'outline-regexp) "#+ "))))
  817. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  818. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  819. (when (autoload-eval-lazily 'markdown-mode
  820. '(markdown-mode gfm-mode)
  821. (defvar gfm-mode-map (make-sparse-keymap))
  822. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline))
  823. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  824. (set-variable 'markdown-command (or (executable-find "markdown")
  825. (executable-find "markdown.pl")
  826. ""))
  827. (add-hook 'markdown-mode-hook
  828. (lambda ()
  829. (outline-minor-mode 1)
  830. (flyspell-mode)
  831. (set (make-local-variable 'comment-start) ";")))
  832. )
  833. ;; c-mode
  834. ;; http://www.emacswiki.org/emacs/IndentingC
  835. ;; http://en.wikipedia.org/wiki/Indent_style
  836. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  837. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  838. (with-eval-after-load 'cc-vars
  839. (defvar c-default-style nil)
  840. (add-to-list 'c-default-style
  841. '(c-mode . "k&r"))
  842. (add-to-list 'c-default-style
  843. '(c++-mode . "k&r"))
  844. (add-hook 'c-mode-common-hook
  845. (lambda ()
  846. ;; why c-basic-offset in k&r style defaults to 5 ???
  847. (set-variable 'c-basic-offset 4)
  848. (set-variable 'indent-tabs-mode nil)
  849. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  850. (c-toggle-hungry-state -1)
  851. ;; (and (require 'gtags nil t)
  852. ;; (gtags-mode 1))
  853. )))
  854. (autoload-eval-lazily 'js2-mode nil
  855. ;; currently do not use js2-mode
  856. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  857. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  858. (defvar js2-mode-map (make-sparse-keymap))
  859. (define-key js2-mode-map (kbd "C-m") (lambda ()
  860. (interactive)
  861. (js2-enter-key)
  862. (indent-for-tab-command)))
  863. ;; (add-hook (kill-local-variable 'before-save-hook)
  864. ;; 'js2-before-save)
  865. ;; (add-hook 'before-save-hook
  866. ;; 'my-indent-buffer
  867. ;; nil
  868. ;; t)
  869. )
  870. (add-to-list 'interpreter-mode-alist
  871. '("node" . js-mode))
  872. (when (autoload-eval-lazily 'flymake-jslint
  873. '(flymake-jslint-load))
  874. (autoload-eval-lazily 'js nil
  875. (add-hook 'js-mode-hook
  876. 'flymake-jslint-load)))
  877. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  878. (with-eval-after-load 'uniquify
  879. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  880. (setq uniquify-ignore-buffers-re "*[^*]+*")
  881. (setq uniquify-min-dir-content 1))
  882. (with-eval-after-load 'view
  883. (defvar view-mode-map (make-sparse-keymap))
  884. (define-key view-mode-map "j" 'scroll-up-line)
  885. (define-key view-mode-map "k" 'scroll-down-line)
  886. (define-key view-mode-map "v" 'toggle-read-only)
  887. (define-key view-mode-map "q" 'bury-buffer)
  888. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  889. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  890. ;; (define-key view-mode-map
  891. ;; "n" 'nonincremental-repeat-search-forward)
  892. ;; (define-key view-mode-map
  893. ;; "N" 'nonincremental-repeat-search-backward)
  894. (define-key view-mode-map "/" 'isearch-forward-regexp)
  895. (define-key view-mode-map "?" 'isearch-backward-regexp)
  896. (define-key view-mode-map "n" 'isearch-repeat-forward)
  897. (define-key view-mode-map "N" 'isearch-repeat-backward)
  898. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  899. (global-set-key "\M-r" 'view-mode)
  900. ;; (setq view-read-only t)
  901. (with-eval-after-load 'term
  902. (defvar term-raw-map (make-sparse-keymap))
  903. (define-key term-raw-map (kbd "C-x")
  904. (lookup-key (current-global-map)
  905. (kbd "C-x"))))
  906. (add-hook 'term-mode-hook
  907. (lambda ()
  908. ;; Stop current line highlighting
  909. (set (make-local-variable (defvar hl-line-range-function))
  910. (lambda () '(0 . 0)))
  911. (set (make-local-variable 'scroll-margin)
  912. 0)))
  913. (add-hook 'Man-mode-hook
  914. (lambda ()
  915. (view-mode 1)
  916. (setq truncate-lines nil)))
  917. (set-variable 'Man-notify-method (if window-system
  918. 'newframe
  919. 'aggressive))
  920. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  921. "woman_cache.el")))
  922. ;; not work because man.el will be loaded when man called
  923. (defalias 'man 'woman)
  924. (add-to-list 'auto-mode-alist
  925. '("tox\\.ini\\'" . conf-unix-mode))
  926. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  927. ;; buffer switching
  928. (defvar bs-configurations)
  929. (when (autoload-eval-lazily 'bs '(bs-show)
  930. (add-to-list 'bs-configurations
  931. '("specials" "^\\*" nil ".*" nil nil))
  932. (add-to-list 'bs-configurations
  933. '("files-and-specials" "^\\*" buffer-file-name ".*" nil nil))
  934. (defvar bs-mode-map)
  935. (defvar bs-current-configuration)
  936. (define-key bs-mode-map (kbd "t")
  937. ;; TODO: fix toggle feature
  938. (lambda ()
  939. (interactive)
  940. (if (string= "specials"
  941. bs-current-configuration)
  942. (bs-set-configuration "files")
  943. (bs-set-configuration "specials"))
  944. (bs-refresh)
  945. (bs-message-without-log "%s"
  946. (bs--current-config-message))))
  947. ;; (setq bs-configurations (list
  948. ;; '("processes" nil get-buffer-process ".*" nil nil)
  949. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  950. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  951. )
  952. (defalias 'list-buffers 'bs-show)
  953. (set-variable 'bs-default-configuration "files-and-specials")
  954. (set-variable 'bs-default-sort-name "by nothing")
  955. (add-hook 'bs-mode-hook
  956. (lambda ()
  957. (set (make-local-variable 'scroll-margin) 0))))
  958. ;;(iswitchb-mode 1)
  959. (icomplete-mode)
  960. (defun iswitchb-buffer-display-other-window ()
  961. "Do iswitchb in other window."
  962. (interactive)
  963. (let ((iswitchb-default-method 'display))
  964. (call-interactively 'iswitchb-buffer)))
  965. ;;;;;;;;;;;;;;;;;;;;;;;;
  966. ;; ilookup
  967. (with-eval-after-load 'ilookup
  968. (set-variable 'ilookup-dict-alist
  969. '(
  970. ("sdcv" . (lambda (word)
  971. (shell-command-to-string
  972. (format "sdcv -n '%s'"
  973. word))))
  974. ("en" . (lambda (word)
  975. (shell-command-to-string
  976. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  977. word))))
  978. ("ja" . (lambda (word)
  979. (shell-command-to-string
  980. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  981. word))))
  982. ("jaj" . (lambda (word)
  983. (shell-command-to-string
  984. (format "sdcv -n -u jmdict-en-ja '%s'"
  985. word))))
  986. ("jag" .
  987. (lambda (word)
  988. (with-temp-buffer
  989. (insert (shell-command-to-string
  990. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  991. word)))
  992. (html2text)
  993. (buffer-substring (point-min)
  994. (point-max)))))
  995. ("alc" . (lambda (word)
  996. (shell-command-to-string
  997. (format "alc '%s' | head -n 20"
  998. word))))
  999. ("app" . (lambda (word)
  1000. (shell-command-to-string
  1001. (format "dict_app '%s'"
  1002. word))))
  1003. ;; letters broken
  1004. ("ms" .
  1005. (lambda (word)
  1006. (let ((url (concat
  1007. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  1008. "Translate?appId=%s&text=%s&to=%s"))
  1009. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  1010. (target "ja")
  1011. (eword (url-hexify-string word)))
  1012. (with-current-buffer (url-retrieve-synchronously
  1013. (format url
  1014. apikey
  1015. eword
  1016. target))
  1017. (message "")
  1018. (goto-char (point-min))
  1019. (search-forward-regexp "^$"
  1020. nil
  1021. t)
  1022. (url-unhex-string (buffer-substring-no-properties
  1023. (point)
  1024. (point-max)))))))
  1025. ))
  1026. ;; (funcall (cdr (assoc "ms"
  1027. ;; ilookup-alist))
  1028. ;; "dictionary")
  1029. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  1030. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  1031. (set-variable 'ilookup-default "ja")
  1032. (when (locate-library "google-translate")
  1033. (defvar ilookup-dict-alist nil)
  1034. (add-to-list 'ilookup-dict-alist
  1035. '("gt" .
  1036. (lambda (word)
  1037. (save-excursion
  1038. (google-translate-translate "auto"
  1039. "ja"
  1040. word))
  1041. (with-current-buffer "*Google Translate*"
  1042. (buffer-substring-no-properties (point-min)
  1043. (point-max)))))))
  1044. )
  1045. (when (autoload-eval-lazily 'google-translate '(google-translate-translate
  1046. google-translate-at-point))
  1047. (set-variable 'google-translate-default-source-language "auto")
  1048. (set-variable 'google-translate-default-target-language "ja"))
  1049. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1050. ;; vc
  1051. (set-variable 'vc-handled-backends '())
  1052. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1053. ;; recentf-mode
  1054. (set-variable 'recentf-save-file (expand-file-name (concat user-emacs-directory
  1055. "recentf")))
  1056. (set-variable 'recentf-max-menu-items 20)
  1057. (set-variable 'recentf-max-saved-items 30)
  1058. (set-variable 'recentf-show-file-shortcuts-flag nil)
  1059. (when (safe-require-or-eval 'recentf)
  1060. (add-to-list 'recentf-exclude
  1061. (regexp-quote recentf-save-file))
  1062. (add-to-list 'recentf-exclude
  1063. (regexp-quote (expand-file-name user-emacs-directory)))
  1064. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1065. (remove-hook 'find-file-hook
  1066. 'recentf-track-opened-file)
  1067. (defun my-recentf-load-track-save-list ()
  1068. "Load current recentf list from file, track current visiting file, then save
  1069. the list."
  1070. (recentf-load-list)
  1071. (recentf-track-opened-file)
  1072. (recentf-save-list))
  1073. (add-hook 'find-file-hook
  1074. 'my-recentf-load-track-save-list)
  1075. (add-hook 'kill-emacs-hook
  1076. 'recentf-load-list)
  1077. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1078. ;; (add-hook 'find-file-hook
  1079. ;; (lambda ()
  1080. ;; (recentf-add-file default-directory)))
  1081. (and (autoload-eval-lazily 'recentf-show)
  1082. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1083. (add-hook 'recentf-show-before-listing-hook
  1084. 'recentf-load-list))
  1085. (recentf-mode 1)
  1086. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1087. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1088. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1089. (define-key recentf-dialog-mode-map "n" 'next-line)
  1090. (add-hook 'recentf-dialog-mode-hook
  1091. (lambda ()
  1092. ;; (recentf-save-list)
  1093. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1094. ;; 'my-recentf-cd-and-find-file)
  1095. (cd "~/"))))
  1096. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1097. ;; dired
  1098. (defun my-dired-echo-file-head (arg)
  1099. ""
  1100. (interactive "P")
  1101. (let ((f (dired-get-filename)))
  1102. (message "%s"
  1103. (with-temp-buffer
  1104. (insert-file-contents f)
  1105. (buffer-substring-no-properties
  1106. (point-min)
  1107. (progn (goto-char (point-min))
  1108. (forward-line (1- (if arg
  1109. (prefix-numeric-value arg)
  1110. 7)))
  1111. (point-at-eol)))))))
  1112. (defun my-dired-diff ()
  1113. ""
  1114. (interactive)
  1115. (let ((files (dired-get-marked-files nil nil nil t)))
  1116. (if (eq (car files)
  1117. t)
  1118. (diff (cadr files) (dired-get-filename))
  1119. (message "One file must be marked!"))))
  1120. (defun dired-get-file-info ()
  1121. "dired get file info"
  1122. (interactive)
  1123. (let ((f (shell-quote-argument (dired-get-filename t))))
  1124. (if (file-directory-p f)
  1125. (progn
  1126. (message "Calculating disk usage...")
  1127. (shell-command (concat "du -hsD "
  1128. f)))
  1129. (shell-command (concat "file "
  1130. f)))))
  1131. (defun my-dired-scroll-up ()
  1132. ""
  1133. (interactive)
  1134. (my-dired-previous-line (- (window-height) 1)))
  1135. (defun my-dired-scroll-down ()
  1136. ""
  1137. (interactive)
  1138. (my-dired-next-line (- (window-height) 1)))
  1139. ;; (defun my-dired-forward-line (arg)
  1140. ;; ""
  1141. ;; (interactive "p"))
  1142. (defun my-dired-previous-line (arg)
  1143. ""
  1144. (interactive "p")
  1145. (if (> arg 0)
  1146. (progn
  1147. (if (eq (line-number-at-pos)
  1148. 1)
  1149. (goto-char (point-max))
  1150. (forward-line -1))
  1151. (my-dired-previous-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-next-line (arg)
  1157. ""
  1158. (interactive "p")
  1159. (if (> arg 0)
  1160. (progn
  1161. (if (eq (point)
  1162. (point-max))
  1163. (goto-char (point-min))
  1164. (forward-line 1))
  1165. (my-dired-next-line (if (or (dired-get-filename nil t)
  1166. (dired-get-subdir))
  1167. (- arg 1)
  1168. arg)))
  1169. (dired-move-to-filename)))
  1170. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1171. (if (eq window-system 'mac)
  1172. (setq dired-listing-switches "-lhF")
  1173. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1174. )
  1175. (setq dired-listing-switches "-lhF")
  1176. (put 'dired-find-alternate-file 'disabled nil)
  1177. ;; when using dired-find-alternate-file
  1178. ;; reuse current dired buffer for the file to open
  1179. (set-variable 'dired-ls-F-marks-symlinks t)
  1180. (with-eval-after-load 'ls-lisp
  1181. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1182. (setq ls-lisp-dirs-first t)
  1183. (setq ls-lisp-use-localized-time-format t)
  1184. (setq ls-lisp-format-time-list
  1185. '("%Y-%m-%d %H:%M"
  1186. "%Y-%m-%d ")))
  1187. (set-variable 'dired-dwim-target t)
  1188. (set-variable 'dired-isearch-filenames t)
  1189. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1190. (set-variable 'dired-hide-details-hide-information-lines nil)
  1191. ;; (add-hook 'dired-after-readin-hook
  1192. ;; 'my-replace-nasi-none)
  1193. ;; (add-hook 'after-init-hook
  1194. ;; (lambda ()
  1195. ;; (dired ".")))
  1196. (with-eval-after-load 'dired
  1197. (safe-require-or-eval 'ls-lisp)
  1198. (defvar dired-mode-map (make-sparse-keymap))
  1199. (define-key dired-mode-map "i" 'dired-get-file-info)
  1200. (define-key dired-mode-map "f" 'find-file)
  1201. (define-key dired-mode-map "!" 'shell-command)
  1202. (define-key dired-mode-map "&" 'async-shell-command)
  1203. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1204. (define-key dired-mode-map "=" 'my-dired-diff)
  1205. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1206. (define-key dired-mode-map "b" 'gtkbm)
  1207. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1208. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1209. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1210. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1211. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1212. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1213. (substitute-key-definition 'dired-next-line
  1214. 'my-dired-next-line
  1215. dired-mode-map)
  1216. (substitute-key-definition 'dired-previous-line
  1217. 'my-dired-previous-line
  1218. dired-mode-map)
  1219. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  1220. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  1221. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  1222. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  1223. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1224. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1225. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1226. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1227. (add-hook 'dired-mode-hook
  1228. (lambda ()
  1229. (when (fboundp 'dired-hide-details-mode)
  1230. (dired-hide-details-mode t)
  1231. (local-set-key "l" 'dired-hide-details-mode))
  1232. (let ((file "._Icon\015"))
  1233. (when nil
  1234. '(file-readable-p file)
  1235. (delete-file file)))))
  1236. (when (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack-pack))
  1237. (with-eval-after-load 'dired
  1238. (define-key dired-mode-map "P" 'pack-dired-dwim)))
  1239. (when (autoload-eval-lazily 'dired-list-all-mode)
  1240. (setq dired-listing-switches "-lhF")
  1241. (with-eval-after-load 'dired
  1242. (define-key dired-mode-map "a" 'dired-list-all-mode))))
  1243. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1244. ;; misc funcs
  1245. (defalias 'qcalc 'quick-calc)
  1246. (defun memo (&optional dir)
  1247. "Open memo.txt in DIR."
  1248. (interactive)
  1249. (pop-to-buffer (find-file-noselect (concat (if dir
  1250. (file-name-as-directory dir)
  1251. "")
  1252. "memo.txt"))))
  1253. (defvar my-rgrep-alist
  1254. `(
  1255. ;; the silver searcher
  1256. ("ag"
  1257. (executable-find "ag")
  1258. "ag --nocolor --nogroup --nopager --filename ")
  1259. ;; ack
  1260. ("ack"
  1261. (executable-find "ack")
  1262. "ack --nocolor --nogroup --nopager --with-filename ")
  1263. ;; gnu global
  1264. ("global"
  1265. (and (require 'gtags nil t)
  1266. (executable-find "global")
  1267. (gtags-get-rootpath))
  1268. "global --result grep ")
  1269. ;; git grep
  1270. ("gitgrep"
  1271. (eq 0
  1272. (shell-command "git rev-parse --git-dir"))
  1273. "git --no-pager -c color.grep=false grep -nH -e ")
  1274. ;; grep
  1275. ("grep"
  1276. t
  1277. ,(concat "find . "
  1278. "-path '*/.git' -prune -o "
  1279. "-path '*/.svn' -prune -o "
  1280. "-type f -print0 | "
  1281. "xargs -0 grep -nH -e "))
  1282. )
  1283. "Alist of rgrep command.
  1284. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1285. condition to choose COMMAND when evaluated.")
  1286. (defvar my-rgrep-default nil
  1287. "Default command name for my-rgrep.")
  1288. (defun my-rgrep-grep-command (&optional name alist)
  1289. "Return recursive grep command for current directory or nil.
  1290. If NAME is given, use that without testing.
  1291. Commands are searched from ALIST."
  1292. (if alist
  1293. (if name
  1294. ;; if name is given search that from alist and return the command
  1295. (nth 2 (assoc name
  1296. alist))
  1297. ;; if name is not given try test in 1th elem
  1298. (let ((car (car alist))
  1299. (cdr (cdr alist)))
  1300. (if (eval (nth 1 car))
  1301. ;; if the condition is true return the command
  1302. (nth 2 car)
  1303. ;; try next one
  1304. (and cdr
  1305. (my-rgrep-grep-command name cdr)))))
  1306. ;; if alist is not given set default value
  1307. (my-rgrep-grep-command name my-rgrep-alist)))
  1308. (defun my-rgrep (command-args)
  1309. "My recursive grep. Run COMMAND-ARGS."
  1310. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  1311. nil)))
  1312. (if cmd
  1313. (list (read-shell-command "grep command: "
  1314. cmd
  1315. 'grep-find-history))
  1316. (error "My-Rgrep: Command for rgrep not found")
  1317. )))
  1318. (compilation-start command-args
  1319. 'grep-mode))
  1320. ;; (defun my-rgrep-symbol-at-point (command-args)
  1321. ;; "My recursive grep. Run COMMAND-ARGS."
  1322. ;; (interactive (list (read-shell-command "grep command: "
  1323. ;; (concat (my-rgrep-grep-command)
  1324. ;; " "
  1325. ;; (thing-at-point 'symbol))
  1326. ;; 'grep-find-history)))
  1327. ;; (compilation-start command-args
  1328. ;; 'grep-mode))
  1329. (defmacro define-my-rgrep (name)
  1330. "Define rgrep for NAME."
  1331. `(defun ,(intern (concat "my-rgrep-"
  1332. name)) ()
  1333. ,(format "My recursive grep by %s."
  1334. name)
  1335. (interactive)
  1336. (let ((my-rgrep-default ,name))
  1337. (if (called-interactively-p 'any)
  1338. (call-interactively 'my-rgrep)
  1339. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1340. )
  1341. (define-my-rgrep "ack")
  1342. (define-my-rgrep "ag")
  1343. (define-my-rgrep "gitgrep")
  1344. (define-my-rgrep "grep")
  1345. (define-my-rgrep "global")
  1346. (define-key ctl-x-map "s" 'my-rgrep)
  1347. ;; (defun make ()
  1348. ;; "Run \"make -k\" in current directory."
  1349. ;; (interactive)
  1350. ;; (compile "make -k"))
  1351. (defalias 'make 'compile)
  1352. (define-key ctl-x-map "c" 'compile)
  1353. ;;;;;;;;;;;;;;;;;;;;;;;
  1354. ;; adoc-simple-mode
  1355. (when (safe-require-or-eval 'adoc-mode)
  1356. (defvar adoc-simple-font-lock-keywords
  1357. nil)
  1358. (define-derived-mode adoc-simple-mode adoc-mode
  1359. "Adoc-Simple"
  1360. "Major mode for editing AsciiDoc text files.
  1361. This mode is a simplified version of `adoc-mode'."
  1362. '(set (make-local-variable 'font-lock-defaults)
  1363. '(adoc-simple-font-lock-keywords
  1364. nil nil nil nil
  1365. (font-lock-multiline . t)
  1366. (font-lock-mark-block-function . adoc-font-lock-mark-block-function))))
  1367. (add-to-list 'auto-mode-alist
  1368. '("\\.adoc\\'" . adoc-simple-mode)))
  1369. (when (and (safe-require-or-eval 'google-translate)
  1370. (safe-require-or-eval 'google-translate-smooth-ui))
  1371. (add-to-list 'google-translate-translation-directions-alist
  1372. '("en" . "ja"))
  1373. (defun translate-echo-at-point ()
  1374. "Translate popup at point."
  1375. (interactive)
  1376. (let ((google-translate-output-destination 'echo-area))
  1377. (google-translate-translate "auto" "ja" (current-word t t))))
  1378. (define-minor-mode auto-translate-mode
  1379. "Translate word at point automatically."
  1380. :global nil
  1381. :lighter "ATranslate"))
  1382. ;;; emacs.el ends here