Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

1855 řádky
63 KiB

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