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.
 
 
 
 
 
 

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