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

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