Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

1828 строки
61 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/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. (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. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  670. (when (safe-require-or-eval 'company)
  671. (global-company-mode)
  672. (set-variable 'company-idle-delay 0.5)
  673. (set-variable 'company-minimum-prefix-length 2)
  674. (set-variable 'company-selection-wrap-around t))
  675. ;; https://github.com/lunaryorn/flycheck
  676. (when (safe-require-or-eval 'flycheck)
  677. (call-after-init 'global-flycheck-mode))
  678. (set-variable 'ac-ignore-case nil)
  679. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  680. (define-key ctl-x-map "t" 'term-run-shell-command))
  681. (add-to-list 'safe-local-variable-values
  682. '(encoding utf-8))
  683. (setq enable-local-variables :safe)
  684. (when (safe-require-or-eval 'remember-major-modes-mode)
  685. (remember-major-modes-mode 1))
  686. ;; Detect file type from shebang and set major-mode.
  687. (add-to-list 'interpreter-mode-alist
  688. '("python3" . python-mode))
  689. (add-to-list 'interpreter-mode-alist
  690. '("python2" . python-mode))
  691. ;; http://fukuyama.co/foreign-regexp
  692. '(and (safe-require-or-eval 'foreign-regexp)
  693. (progn
  694. (setq foreign-regexp/regexp-type 'perl)
  695. '(setq reb-re-syntax 'foreign-regexp)
  696. ))
  697. (autoload-eval-lazily 'sql '(sql-mode)
  698. (safe-require-or-eval 'sql-indent))
  699. (when (autoload-eval-lazily 'git-command)
  700. (define-key ctl-x-map "g" 'git-command))
  701. (when (safe-require-or-eval 'git-commit)
  702. (global-git-commit-mode 1))
  703. (autoload-eval-lazily 'sl)
  704. (with-eval-after-load 'rst
  705. (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
  706. ;; jdee is too old! use malabar instead
  707. (with-eval-after-load 'jdee
  708. (add-hook 'jdee-mode-hook
  709. (lambda ()
  710. (make-local-variable 'global-mode-string)
  711. (add-to-list 'global-mode-string
  712. mode-line-position))))
  713. ;; Cannot enable error thrown. Why???
  714. ;; https://github.com/m0smith/malabar-mode#Installation
  715. ;; (when (autoload-eval-lazily 'malabar-mode)
  716. ;; (add-to-list 'load-path
  717. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  718. ;; (safe-require-or-eval 'cedet-devel-load)
  719. ;; (call-after-init 'activate-malabar-mode))
  720. (with-eval-after-load 'make-mode
  721. (defvar makefile-mode-map (make-sparse-keymap))
  722. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  723. ;; this functions is set in write-file-functions, i cannot find any
  724. ;; good way to remove this.
  725. (fset 'makefile-warn-suspicious-lines 'ignore))
  726. (with-eval-after-load 'verilog-mode
  727. (defvar verilog-mode-map (make-sparse-keymap))
  728. (define-key verilog-mode-map ";" 'self-insert-command))
  729. (setq diff-switches "-u")
  730. (with-eval-after-load 'diff-mode
  731. ;; (when (and (eq major-mode
  732. ;; 'diff-mode)
  733. ;; (not buffer-file-name))
  734. ;; ;; do not pass when major-mode is derived mode of diff-mode
  735. ;; (view-mode 1))
  736. (set-face-attribute 'diff-header nil
  737. :foreground nil
  738. :background nil
  739. :weight 'bold)
  740. (set-face-attribute 'diff-file-header nil
  741. :foreground nil
  742. :background nil
  743. :weight 'bold)
  744. (set-face-foreground 'diff-index-face "blue")
  745. (set-face-attribute 'diff-hunk-header nil
  746. :foreground "cyan"
  747. :weight 'normal)
  748. (set-face-attribute 'diff-context nil
  749. ;; :foreground "white"
  750. :foreground nil
  751. :weight 'normal)
  752. (set-face-foreground 'diff-removed-face "red")
  753. (set-face-foreground 'diff-added-face "green")
  754. (set-face-background 'diff-removed-face nil)
  755. (set-face-background 'diff-added-face nil)
  756. (set-face-attribute 'diff-changed nil
  757. :foreground "magenta"
  758. :weight 'normal)
  759. (set-face-attribute 'diff-refine-change nil
  760. :foreground nil
  761. :background nil
  762. :weight 'bold
  763. :inverse-video t)
  764. ;; Annoying !
  765. ;;(diff-auto-refine-mode)
  766. )
  767. ;; (ffap-bindings)
  768. (set-variable 'browse-url-browser-function
  769. 'eww-browse-url)
  770. (set-variable 'sh-here-document-word "__EOC__")
  771. (when (autoload-eval-lazily 'adoc-mode
  772. nil
  773. (defvar adoc-mode-map (make-sparse-keymap))
  774. (define-key adoc-mode-map (kbd "C-m") 'newline))
  775. (setq auto-mode-alist
  776. `(("\\.adoc\\'" . adoc-mode)
  777. ("\\.asciidoc\\'" . adoc-mode)
  778. ,@auto-mode-alist)))
  779. (with-eval-after-load 'markup-faces
  780. ;; Is this too match ?
  781. (set-face-foreground 'markup-meta-face
  782. "color-245")
  783. (set-face-foreground 'markup-meta-hide-face
  784. "color-245")
  785. )
  786. (setq auto-mode-alist
  787. `(("autostart\\'" . sh-mode)
  788. ("xinitrc\\'" . sh-mode)
  789. ("xprograms\\'" . sh-mode)
  790. ("PKGBUILD\\'" . sh-mode)
  791. ,@auto-mode-alist))
  792. ;; TODO: check if this is required
  793. (and (autoload-eval-lazily 'groovy-mode)
  794. (add-to-list 'auto-mode-alist
  795. '("build\\.gradle\\'" . groovy-mode)))
  796. (with-eval-after-load 'yaml-mode
  797. (defvar yaml-mode-map (make-sparse-keymap))
  798. (define-key yaml-mode-map (kbd "C-m") 'newline))
  799. (with-eval-after-load 'html-mode
  800. (defvar html-mode-map (make-sparse-keymap))
  801. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  802. (with-eval-after-load 'text-mode
  803. (define-key text-mode-map (kbd "C-m") 'newline))
  804. (add-to-list 'Info-default-directory-list
  805. (expand-file-name "~/.info/emacs-ja"))
  806. (with-eval-after-load 'apropos
  807. (defvar apropos-mode-map (make-sparse-keymap))
  808. (define-key apropos-mode-map "n" 'next-line)
  809. (define-key apropos-mode-map "p" 'previous-line))
  810. (with-eval-after-load 'isearch
  811. ;; (define-key isearch-mode-map
  812. ;; (kbd "C-j") 'isearch-other-control-char)
  813. ;; (define-key isearch-mode-map
  814. ;; (kbd "C-k") 'isearch-other-control-char)
  815. ;; (define-key isearch-mode-map
  816. ;; (kbd "C-h") 'isearch-other-control-char)
  817. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  818. (define-key isearch-mode-map (kbd "M-r")
  819. 'isearch-query-replace-regexp))
  820. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  821. (setq lazy-highlight-cleanup nil)
  822. ;; face for isearch highlighing
  823. (set-face-attribute 'lazy-highlight
  824. nil
  825. :foreground `unspecified
  826. :background `unspecified
  827. :underline t
  828. ;; :weight `bold
  829. )
  830. (add-hook 'outline-mode-hook
  831. (lambda ()
  832. (when (string-match "\\.md\\'" buffer-file-name)
  833. (set (make-local-variable 'outline-regexp) "#+ "))))
  834. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  835. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  836. (when (autoload-eval-lazily 'markdown-mode
  837. '(markdown-mode gfm-mode)
  838. (defvar gfm-mode-map (make-sparse-keymap))
  839. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline))
  840. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  841. (set-variable 'markdown-command (or (executable-find "markdown")
  842. (executable-find "markdown.pl")
  843. ""))
  844. (add-hook 'markdown-mode-hook
  845. (lambda ()
  846. (outline-minor-mode 1)
  847. (flyspell-mode)
  848. (set (make-local-variable 'comment-start) ";")))
  849. )
  850. ;; c-mode
  851. ;; http://www.emacswiki.org/emacs/IndentingC
  852. ;; http://en.wikipedia.org/wiki/Indent_style
  853. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  854. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  855. (with-eval-after-load 'cc-vars
  856. (defvar c-default-style nil)
  857. (add-to-list 'c-default-style
  858. '(c-mode . "k&r"))
  859. (add-to-list 'c-default-style
  860. '(c++-mode . "k&r"))
  861. (add-hook 'c-mode-common-hook
  862. (lambda ()
  863. ;; why c-basic-offset in k&r style defaults to 5 ???
  864. (set-variable 'c-basic-offset 4)
  865. (set-variable 'indent-tabs-mode nil)
  866. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  867. (c-toggle-hungry-state -1)
  868. ;; (and (require 'gtags nil t)
  869. ;; (gtags-mode 1))
  870. )))
  871. (autoload-eval-lazily 'js2-mode nil
  872. ;; currently do not use js2-mode
  873. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  874. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  875. (defvar js2-mode-map (make-sparse-keymap))
  876. (define-key js2-mode-map (kbd "C-m") (lambda ()
  877. (interactive)
  878. (js2-enter-key)
  879. (indent-for-tab-command)))
  880. ;; (add-hook (kill-local-variable 'before-save-hook)
  881. ;; 'js2-before-save)
  882. ;; (add-hook 'before-save-hook
  883. ;; 'my-indent-buffer
  884. ;; nil
  885. ;; t)
  886. )
  887. (add-to-list 'interpreter-mode-alist
  888. '("node" . js-mode))
  889. (when (autoload-eval-lazily 'flymake-jslint
  890. '(flymake-jslint-load))
  891. (autoload-eval-lazily 'js nil
  892. (add-hook 'js-mode-hook
  893. 'flymake-jslint-load)))
  894. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  895. (with-eval-after-load 'uniquify
  896. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  897. (setq uniquify-ignore-buffers-re "*[^*]+*")
  898. (setq uniquify-min-dir-content 1))
  899. (with-eval-after-load 'view
  900. (defvar view-mode-map (make-sparse-keymap))
  901. (define-key view-mode-map "j" 'scroll-up-line)
  902. (define-key view-mode-map "k" 'scroll-down-line)
  903. (define-key view-mode-map "v" 'toggle-read-only)
  904. (define-key view-mode-map "q" 'bury-buffer)
  905. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  906. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  907. ;; (define-key view-mode-map
  908. ;; "n" 'nonincremental-repeat-search-forward)
  909. ;; (define-key view-mode-map
  910. ;; "N" 'nonincremental-repeat-search-backward)
  911. (define-key view-mode-map "/" 'isearch-forward-regexp)
  912. (define-key view-mode-map "?" 'isearch-backward-regexp)
  913. (define-key view-mode-map "n" 'isearch-repeat-forward)
  914. (define-key view-mode-map "N" 'isearch-repeat-backward)
  915. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  916. (global-set-key "\M-r" 'view-mode)
  917. ;; (setq view-read-only t)
  918. (add-hook 'Man-mode-hook
  919. (lambda ()
  920. (view-mode 1)
  921. (setq truncate-lines nil)))
  922. (set-variable 'Man-notify-method (if window-system
  923. 'newframe
  924. 'aggressive))
  925. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  926. "woman_cache.el")))
  927. (defalias 'man 'woman)
  928. (add-to-list 'auto-mode-alist
  929. '("tox\\.ini\\'" . conf-unix-mode))
  930. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  931. ;; python
  932. (when (autoload-eval-lazily 'python '(python-mode)
  933. (defvar python-mode-map (make-sparse-keymap))
  934. (define-key python-mode-map (kbd "C-c C-e") 'my-python-run-as-command)
  935. (define-key python-mode-map (kbd "C-c C-b") 'my-python-display-python-buffer)
  936. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)
  937. (defvar inferior-python-mode-map (make-sparse-keymap))
  938. (define-key inferior-python-mode-map (kbd "<up>") 'comint-previous-input)
  939. (define-key inferior-python-mode-map (kbd "<down>") 'comint-next-input)
  940. )
  941. (set-variable 'python-python-command (or (executable-find "python3")
  942. (executable-find "python")))
  943. ;; (defun my-python-run-as-command ()
  944. ;; ""
  945. ;; (interactive)
  946. ;; (shell-command (concat python-python-command " " buffer-file-name)))
  947. (defun my-python-display-python-buffer ()
  948. ""
  949. (interactive)
  950. (defvar python-buffer nil)
  951. (set-window-text-height (display-buffer python-buffer
  952. t)
  953. 7))
  954. (add-hook 'inferior-python-mode-hook
  955. (lambda ()
  956. (my-python-display-python-buffer))))
  957. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  958. ;; gauche-mode
  959. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  960. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  961. ;; NOTE: This gauche-mode returns 404.
  962. ;; There is another gosh-mode, so for now I submitted a recipe for that into
  963. ;; github.com/10sr/emacs-lisp/p. I'll add setup for that later.
  964. (when nil (and '(fetch-library
  965. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  966. t)
  967. (autoload-eval-lazily 'gauche-mode '(gauche-mode run-scheme)
  968. (defvar gauche-mode-map (make-sparse-keymap))
  969. (defvar scheme-mode-map (make-sparse-keymap))
  970. (define-key gauche-mode-map
  971. (kbd "C-c C-z") 'run-gauche-other-window)
  972. (define-key scheme-mode-map
  973. (kbd "C-c C-c") 'scheme-send-buffer)
  974. (define-key scheme-mode-map
  975. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer)))
  976. (let ((s (executable-find "gosh")))
  977. (set-variable 'scheme-program-name s)
  978. (set-variable 'gauche-program-name s))
  979. (defvar gauche-program-name nil)
  980. (defvar scheme-buffer nil)
  981. (defun run-gauche-other-window ()
  982. "Run gauche on other window"
  983. (interactive)
  984. (switch-to-buffer-other-window
  985. (get-buffer-create "*scheme*"))
  986. (run-gauche))
  987. (defun run-gauche ()
  988. "run gauche"
  989. (interactive)
  990. (run-scheme gauche-program-name)
  991. )
  992. (defun scheme-send-buffer ()
  993. ""
  994. (interactive)
  995. (scheme-send-region (point-min) (point-max))
  996. (my-scheme-display-scheme-buffer)
  997. )
  998. (defun my-scheme-display-scheme-buffer ()
  999. ""
  1000. (interactive)
  1001. (set-window-text-height (display-buffer scheme-buffer
  1002. t)
  1003. 7))
  1004. (add-hook 'scheme-mode-hook
  1005. (lambda ()
  1006. nil))
  1007. (add-hook 'inferior-scheme-mode-hook
  1008. (lambda ()
  1009. ;; (my-scheme-display-scheme-buffer)
  1010. ))
  1011. (setq auto-mode-alist
  1012. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1013. (setq auto-mode-alist
  1014. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1015. )
  1016. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1017. ;; term mode
  1018. ;; (setq multi-term-program shell-file-name)
  1019. (when (autoload-eval-lazily 'multi-term)
  1020. (set-variable 'multi-term-switch-after-close nil)
  1021. (set-variable 'multi-term-dedicated-select-after-open-p t)
  1022. (set-variable 'multi-term-dedicated-window-height 20))
  1023. (when (autoload-eval-lazily 'term '(term ansi-term)
  1024. (defvar term-raw-map (make-sparse-keymap))
  1025. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  1026. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  1027. (define-key term-raw-map (kbd "<up>") 'scroll-down-line)
  1028. (define-key term-raw-map (kbd "<down>") 'scroll-up-line)
  1029. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  1030. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  1031. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  1032. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  1033. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  1034. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  1035. (define-key term-raw-map [delete] 'term-send-raw)
  1036. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  1037. (define-key term-raw-map "\C-y" 'term-paste)
  1038. (define-key term-raw-map
  1039. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  1040. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  1041. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  1042. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  1043. ;; (define-key term-raw-map "\C-d" 'delete-char)
  1044. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  1045. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  1046. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  1047. ;; (define-key term-raw-map "\C-f" 'forward-char)
  1048. ;; (define-key term-raw-map "\C-b" 'backward-char)
  1049. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  1050. )
  1051. (defun my-term-quit-or-send-raw ()
  1052. ""
  1053. (interactive)
  1054. (if (get-buffer-process (current-buffer))
  1055. (call-interactively 'term-send-raw)
  1056. (kill-buffer)))
  1057. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  1058. ;; (setq term-ansi-default-program shell-file-name)
  1059. (add-hook 'term-setup-hook
  1060. (lambda ()
  1061. (set-variable 'term-display-table (make-display-table))))
  1062. (add-hook 'term-mode-hook
  1063. (lambda ()
  1064. (defvar term-raw-map (make-sparse-keymap))
  1065. ;; (unless (memq (current-buffer)
  1066. ;; (and (featurep 'multi-term)
  1067. ;; (defvar multi-term-buffer-list)
  1068. ;; ;; current buffer is not multi-term buffer
  1069. ;; multi-term-buffer-list))
  1070. ;; )
  1071. (set (make-local-variable 'scroll-margin) 0)
  1072. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  1073. ;; (cua-mode 0)
  1074. ;; (and cua-mode
  1075. ;; (local-unset-key (kbd "C-c")))
  1076. ;; (define-key cua--prefix-override-keymap
  1077. ;;"\C-c" 'term-interrupt-subjob)
  1078. (set (make-local-variable (defvar hl-line-range-function))
  1079. (lambda ()
  1080. '(0 . 0)))
  1081. (define-key term-raw-map
  1082. "\C-x" (lookup-key (current-global-map) "\C-x"))
  1083. (define-key term-raw-map
  1084. "\C-z" (lookup-key (current-global-map) "\C-z"))
  1085. ))
  1086. ;; (add-hook 'term-exec-hook 'forward-char)
  1087. )
  1088. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1089. ;; buffer switching
  1090. (defvar bs-configurations)
  1091. (when (autoload-eval-lazily 'bs '(bs-show)
  1092. (add-to-list 'bs-configurations
  1093. '("specials" "^\\*" nil ".*" nil nil))
  1094. (defvar bs-mode-map)
  1095. (defvar bs-current-configuration)
  1096. (define-key bs-mode-map (kbd "t")
  1097. (lambda ()
  1098. (interactive)
  1099. (if (string= "specials"
  1100. bs-current-configuration)
  1101. (bs-set-configuration "files")
  1102. (bs-set-configuration "specials"))
  1103. (bs-refresh)
  1104. (bs-message-without-log "%s"
  1105. (bs--current-config-message))))
  1106. ;; (setq bs-configurations (list
  1107. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1108. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1109. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1110. )
  1111. (defalias 'list-buffers 'bs-show)
  1112. (set-variable 'bs-default-configuration "files")
  1113. (set-variable 'bs-default-sort-name "by nothing")
  1114. (add-hook 'bs-mode-hook
  1115. (lambda ()
  1116. (set (make-local-variable 'scroll-margin) 0))))
  1117. ;;(iswitchb-mode 1)
  1118. (icomplete-mode)
  1119. (defun iswitchb-buffer-display-other-window ()
  1120. "Do iswitchb in other window."
  1121. (interactive)
  1122. (let ((iswitchb-default-method 'display))
  1123. (call-interactively 'iswitchb-buffer)))
  1124. ;;;;;;;;;;;;;;;;;;;;;;;;
  1125. ;; ilookup
  1126. (with-eval-after-load 'ilookup
  1127. (set-variable 'ilookup-dict-alist
  1128. '(
  1129. ("sdcv" . (lambda (word)
  1130. (shell-command-to-string
  1131. (format "sdcv -n '%s'"
  1132. word))))
  1133. ("en" . (lambda (word)
  1134. (shell-command-to-string
  1135. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  1136. word))))
  1137. ("ja" . (lambda (word)
  1138. (shell-command-to-string
  1139. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  1140. word))))
  1141. ("jaj" . (lambda (word)
  1142. (shell-command-to-string
  1143. (format "sdcv -n -u jmdict-en-ja '%s'"
  1144. word))))
  1145. ("jag" .
  1146. (lambda (word)
  1147. (with-temp-buffer
  1148. (insert (shell-command-to-string
  1149. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  1150. word)))
  1151. (html2text)
  1152. (buffer-substring (point-min)
  1153. (point-max)))))
  1154. ("alc" . (lambda (word)
  1155. (shell-command-to-string
  1156. (format "alc '%s' | head -n 20"
  1157. word))))
  1158. ("app" . (lambda (word)
  1159. (shell-command-to-string
  1160. (format "dict_app '%s'"
  1161. word))))
  1162. ;; letters broken
  1163. ("ms" .
  1164. (lambda (word)
  1165. (let ((url (concat
  1166. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  1167. "Translate?appId=%s&text=%s&to=%s"))
  1168. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  1169. (target "ja")
  1170. (eword (url-hexify-string word)))
  1171. (with-current-buffer (url-retrieve-synchronously
  1172. (format url
  1173. apikey
  1174. eword
  1175. target))
  1176. (message "")
  1177. (goto-char (point-min))
  1178. (search-forward-regexp "^$"
  1179. nil
  1180. t)
  1181. (url-unhex-string (buffer-substring-no-properties
  1182. (point)
  1183. (point-max)))))))
  1184. ))
  1185. ;; (funcall (cdr (assoc "ms"
  1186. ;; ilookup-alist))
  1187. ;; "dictionary")
  1188. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  1189. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  1190. (set-variable 'ilookup-default "ja")
  1191. (when (locate-library "google-translate")
  1192. (defvar ilookup-dict-alist nil)
  1193. (add-to-list 'ilookup-dict-alist
  1194. '("gt" .
  1195. (lambda (word)
  1196. (save-excursion
  1197. (google-translate-translate "auto"
  1198. "ja"
  1199. word))
  1200. (with-current-buffer "*Google Translate*"
  1201. (buffer-substring-no-properties (point-min)
  1202. (point-max)))))))
  1203. )
  1204. (when (autoload-eval-lazily 'google-translate '(google-translate-translate
  1205. google-translate-at-point))
  1206. (set-variable 'google-translate-default-source-language "auto")
  1207. (set-variable 'google-translate-default-target-language "ja"))
  1208. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1209. ;; vc
  1210. (set-variable 'vc-handled-backends '())
  1211. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1212. ;; recentf-mode
  1213. (set-variable 'recentf-save-file (expand-file-name (concat user-emacs-directory
  1214. "recentf")))
  1215. (set-variable 'recentf-max-menu-items 20)
  1216. (set-variable 'recentf-max-saved-items 30)
  1217. (set-variable 'recentf-show-file-shortcuts-flag nil)
  1218. (when (safe-require-or-eval 'recentf)
  1219. (add-to-list 'recentf-exclude
  1220. (regexp-quote recentf-save-file))
  1221. (add-to-list 'recentf-exclude
  1222. (regexp-quote (expand-file-name user-emacs-directory)))
  1223. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1224. (remove-hook 'find-file-hook
  1225. 'recentf-track-opened-file)
  1226. (defun my-recentf-load-track-save-list ()
  1227. "Load current recentf list from file, track current visiting file, then save
  1228. the list."
  1229. (recentf-load-list)
  1230. (recentf-track-opened-file)
  1231. (recentf-save-list))
  1232. (add-hook 'find-file-hook
  1233. 'my-recentf-load-track-save-list)
  1234. (add-hook 'kill-emacs-hook
  1235. 'recentf-load-list)
  1236. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1237. ;; (add-hook 'find-file-hook
  1238. ;; (lambda ()
  1239. ;; (recentf-add-file default-directory)))
  1240. (and (autoload-eval-lazily 'recentf-show)
  1241. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1242. (add-hook 'recentf-show-before-listing-hook
  1243. 'recentf-load-list))
  1244. (recentf-mode 1)
  1245. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1246. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1247. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1248. (define-key recentf-dialog-mode-map "n" 'next-line)
  1249. (add-hook 'recentf-dialog-mode-hook
  1250. (lambda ()
  1251. ;; (recentf-save-list)
  1252. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1253. ;; 'my-recentf-cd-and-find-file)
  1254. (cd "~/"))))
  1255. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1256. ;; dired
  1257. (defun my-dired-echo-file-head (arg)
  1258. ""
  1259. (interactive "P")
  1260. (let ((f (dired-get-filename)))
  1261. (message "%s"
  1262. (with-temp-buffer
  1263. (insert-file-contents f)
  1264. (buffer-substring-no-properties
  1265. (point-min)
  1266. (progn (goto-char (point-min))
  1267. (forward-line (1- (if arg
  1268. (prefix-numeric-value arg)
  1269. 7)))
  1270. (point-at-eol)))))))
  1271. (defun my-dired-diff ()
  1272. ""
  1273. (interactive)
  1274. (let ((files (dired-get-marked-files nil nil nil t)))
  1275. (if (eq (car files)
  1276. t)
  1277. (diff (cadr files) (dired-get-filename))
  1278. (message "One file must be marked!"))))
  1279. (defun dired-get-file-info ()
  1280. "dired get file info"
  1281. (interactive)
  1282. (let ((f (shell-quote-argument (dired-get-filename t))))
  1283. (if (file-directory-p f)
  1284. (progn
  1285. (message "Calculating disk usage...")
  1286. (shell-command (concat "du -hsD "
  1287. f)))
  1288. (shell-command (concat "file "
  1289. f)))))
  1290. (defun my-dired-scroll-up ()
  1291. ""
  1292. (interactive)
  1293. (my-dired-previous-line (- (window-height) 1)))
  1294. (defun my-dired-scroll-down ()
  1295. ""
  1296. (interactive)
  1297. (my-dired-next-line (- (window-height) 1)))
  1298. ;; (defun my-dired-forward-line (arg)
  1299. ;; ""
  1300. ;; (interactive "p"))
  1301. (defun my-dired-previous-line (arg)
  1302. ""
  1303. (interactive "p")
  1304. (if (> arg 0)
  1305. (progn
  1306. (if (eq (line-number-at-pos)
  1307. 1)
  1308. (goto-char (point-max))
  1309. (forward-line -1))
  1310. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1311. (dired-get-subdir))
  1312. (- arg 1)
  1313. arg)))
  1314. (dired-move-to-filename)))
  1315. (defun my-dired-next-line (arg)
  1316. ""
  1317. (interactive "p")
  1318. (if (> arg 0)
  1319. (progn
  1320. (if (eq (point)
  1321. (point-max))
  1322. (goto-char (point-min))
  1323. (forward-line 1))
  1324. (my-dired-next-line (if (or (dired-get-filename nil t)
  1325. (dired-get-subdir))
  1326. (- arg 1)
  1327. arg)))
  1328. (dired-move-to-filename)))
  1329. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1330. (if (eq window-system 'mac)
  1331. (setq dired-listing-switches "-lhF")
  1332. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1333. )
  1334. (setq dired-listing-switches "-lhF")
  1335. (put 'dired-find-alternate-file 'disabled nil)
  1336. ;; when using dired-find-alternate-file
  1337. ;; reuse current dired buffer for the file to open
  1338. (set-variable 'dired-ls-F-marks-symlinks t)
  1339. (with-eval-after-load 'ls-lisp
  1340. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1341. (setq ls-lisp-dirs-first t)
  1342. (setq ls-lisp-use-localized-time-format t)
  1343. (setq ls-lisp-format-time-list
  1344. '("%Y-%m-%d %H:%M"
  1345. "%Y-%m-%d ")))
  1346. (set-variable 'dired-dwim-target t)
  1347. (set-variable 'dired-isearch-filenames t)
  1348. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1349. (set-variable 'dired-hide-details-hide-information-lines nil)
  1350. ;; (add-hook 'dired-after-readin-hook
  1351. ;; 'my-replace-nasi-none)
  1352. ;; (add-hook 'after-init-hook
  1353. ;; (lambda ()
  1354. ;; (dired ".")))
  1355. (with-eval-after-load 'dired
  1356. (safe-require-or-eval 'ls-lisp)
  1357. (defvar dired-mode-map (make-sparse-keymap))
  1358. (define-key dired-mode-map "o" 'my-dired-x-open)
  1359. (define-key dired-mode-map "i" 'dired-get-file-info)
  1360. (define-key dired-mode-map "f" 'find-file)
  1361. (define-key dired-mode-map "!" 'shell-command)
  1362. (define-key dired-mode-map "&" 'async-shell-command)
  1363. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1364. (define-key dired-mode-map "=" 'my-dired-diff)
  1365. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1366. (define-key dired-mode-map "b" 'gtkbm)
  1367. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1368. (define-key dired-mode-map "@" (lambda ()
  1369. (interactive) (my-x-open ".")))
  1370. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1371. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1372. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1373. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1374. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1375. (substitute-key-definition 'dired-next-line
  1376. 'my-dired-next-line
  1377. dired-mode-map)
  1378. (substitute-key-definition 'dired-previous-line
  1379. 'my-dired-previous-line
  1380. dired-mode-map)
  1381. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  1382. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  1383. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  1384. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  1385. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1386. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1387. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1388. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1389. (add-hook 'dired-mode-hook
  1390. (lambda ()
  1391. (when (fboundp 'dired-hide-details-mode)
  1392. (dired-hide-details-mode t)
  1393. (local-set-key "l" 'dired-hide-details-mode))
  1394. (let ((file "._Icon\015"))
  1395. (when nil
  1396. '(file-readable-p file)
  1397. (delete-file file)))))
  1398. (when (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack-pack))
  1399. (with-eval-after-load 'dired
  1400. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack)))
  1401. (when (autoload-eval-lazily 'dired-list-all-mode)
  1402. (setq dired-listing-switches "-lhF")
  1403. (with-eval-after-load 'dired
  1404. (define-key dired-mode-map "a" 'dired-list-all-mode))))
  1405. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1406. ;; my-term
  1407. (defvar my-term nil
  1408. "My terminal buffer.")
  1409. (defvar my-term-function nil
  1410. "Function to create terminal buffer.
  1411. This function accept no argument and return newly created buffer of terminal.")
  1412. (defun my-term (&optional arg)
  1413. "Open terminal buffer and return that buffer.
  1414. If ARG is given or called with prefix argument, create new buffer."
  1415. (interactive "P")
  1416. (if (and (not arg)
  1417. my-term
  1418. (buffer-name my-term))
  1419. (pop-to-buffer my-term)
  1420. (setq my-term
  1421. (save-window-excursion
  1422. (funcall my-term-function)))
  1423. (and my-term
  1424. (my-term))))
  1425. ;; (setq my-term-function
  1426. ;; (lambda ()
  1427. ;; (if (eq system-type 'windows-nt)
  1428. ;; (eshell)
  1429. ;; (if (require 'multi-term nil t)
  1430. ;; (multi-term)
  1431. ;; (ansi-term shell-file-name)))))
  1432. (setq my-term-function (lambda () (eshell t)))
  1433. ;;(define-key my-prefix-map (kbd "C-s") 'my-term)
  1434. (define-key ctl-x-map "i" 'my-term)
  1435. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1436. ;; misc funcs
  1437. (defalias 'qcalc 'quick-calc)
  1438. (defun memo (&optional dir)
  1439. "Open memo.txt in DIR."
  1440. (interactive)
  1441. (pop-to-buffer (find-file-noselect (concat (if dir
  1442. (file-name-as-directory dir)
  1443. "")
  1444. "memo.txt"))))
  1445. (defvar my-rgrep-alist
  1446. `(
  1447. ;; the silver searcher
  1448. ("ag"
  1449. (executable-find "ag")
  1450. "ag --nocolor --nogroup --nopager --filename ")
  1451. ;; ack
  1452. ("ack"
  1453. (executable-find "ack")
  1454. "ack --nocolor --nogroup --nopager --with-filename ")
  1455. ;; gnu global
  1456. ("global"
  1457. (and (require 'gtags nil t)
  1458. (executable-find "global")
  1459. (gtags-get-rootpath))
  1460. "global --result grep ")
  1461. ;; git grep
  1462. ("gitgrep"
  1463. (eq 0
  1464. (shell-command "git rev-parse --git-dir"))
  1465. "git --no-pager -c color.grep=false grep -nH -e ")
  1466. ;; grep
  1467. ("grep"
  1468. t
  1469. ,(concat "find . "
  1470. "-path '*/.git' -prune -o "
  1471. "-path '*/.svn' -prune -o "
  1472. "-type f -print0 | "
  1473. "xargs -0 grep -nH -e "))
  1474. )
  1475. "Alist of rgrep command.
  1476. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1477. condition to choose COMMAND when evaluated.")
  1478. (defvar my-rgrep-default nil
  1479. "Default command name for my-rgrep.")
  1480. (defun my-rgrep-grep-command (&optional name alist)
  1481. "Return recursive grep command for current directory or nil.
  1482. If NAME is given, use that without testing.
  1483. Commands are searched from ALIST."
  1484. (if alist
  1485. (if name
  1486. ;; if name is given search that from alist and return the command
  1487. (nth 2 (assoc name
  1488. alist))
  1489. ;; if name is not given try test in 1th elem
  1490. (let ((car (car alist))
  1491. (cdr (cdr alist)))
  1492. (if (eval (nth 1 car))
  1493. ;; if the condition is true return the command
  1494. (nth 2 car)
  1495. ;; try next one
  1496. (and cdr
  1497. (my-rgrep-grep-command name cdr)))))
  1498. ;; if alist is not given set default value
  1499. (my-rgrep-grep-command name my-rgrep-alist)))
  1500. (defun my-rgrep (command-args)
  1501. "My recursive grep. Run COMMAND-ARGS."
  1502. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  1503. nil)))
  1504. (if cmd
  1505. (list (read-shell-command "grep command: "
  1506. cmd
  1507. 'grep-find-history))
  1508. (error "My-Rgrep: Command for rgrep not found")
  1509. )))
  1510. (compilation-start command-args
  1511. 'grep-mode))
  1512. ;; (defun my-rgrep-symbol-at-point (command-args)
  1513. ;; "My recursive grep. Run COMMAND-ARGS."
  1514. ;; (interactive (list (read-shell-command "grep command: "
  1515. ;; (concat (my-rgrep-grep-command)
  1516. ;; " "
  1517. ;; (thing-at-point 'symbol))
  1518. ;; 'grep-find-history)))
  1519. ;; (compilation-start command-args
  1520. ;; 'grep-mode))
  1521. (defmacro define-my-rgrep (name)
  1522. "Define rgrep for NAME."
  1523. `(defun ,(intern (concat "my-rgrep-"
  1524. name)) ()
  1525. ,(format "My recursive grep by %s."
  1526. name)
  1527. (interactive)
  1528. (let ((my-rgrep-default ,name))
  1529. (if (called-interactively-p 'any)
  1530. (call-interactively 'my-rgrep)
  1531. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1532. )
  1533. (define-my-rgrep "ack")
  1534. (define-my-rgrep "ag")
  1535. (define-my-rgrep "gitgrep")
  1536. (define-my-rgrep "grep")
  1537. (define-my-rgrep "global")
  1538. (define-key ctl-x-map "s" 'my-rgrep)
  1539. ;; (defun make ()
  1540. ;; "Run \"make -k\" in current directory."
  1541. ;; (interactive)
  1542. ;; (compile "make -k"))
  1543. (defalias 'make 'compile)
  1544. (define-key ctl-x-map "c" 'compile)
  1545. ;;;;;;;;;;;;;;;;;;;;;;;
  1546. ;; adoc-simple-mode
  1547. (when (safe-require-or-eval 'adoc-mode)
  1548. (defvar adoc-simple-font-lock-keywords
  1549. nil)
  1550. (define-derived-mode adoc-simple-mode adoc-mode
  1551. "Adoc-Simple"
  1552. "Major mode for editing AsciiDoc text files.
  1553. This mode is a simplified version of `adoc-mode'."
  1554. '(set (make-local-variable 'font-lock-defaults)
  1555. '(adoc-simple-font-lock-keywords
  1556. nil nil nil nil
  1557. (font-lock-multiline . t)
  1558. (font-lock-mark-block-function . adoc-font-lock-mark-block-function))))
  1559. (add-to-list 'auto-mode-alist
  1560. '("\\.adoc\\'" . adoc-simple-mode)))
  1561. (when (and (safe-require-or-eval 'google-translate)
  1562. (safe-require-or-eval 'google-translate-smooth-ui))
  1563. (add-to-list 'google-translate-translation-directions-alist
  1564. '("en" . "ja"))
  1565. (defun translate-echo-at-point ()
  1566. "Translate popup at point."
  1567. (interactive)
  1568. (let ((google-translate-output-destination 'echo-area))
  1569. (google-translate-translate "auto" "ja" (current-word t t))))
  1570. (define-minor-mode auto-translate-mode
  1571. "Translate word at point automatically."
  1572. :global nil
  1573. :lighter "ATranslate"))
  1574. ;;; emacs.el ends here