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.
 
 
 
 
 
 

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