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.
 
 
 
 
 
 

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