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.
 
 
 
 
 
 

1838 lines
62 KiB

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