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.
 
 
 
 
 
 

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