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.
 
 
 
 
 
 

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