You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1910 lines
65 KiB

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