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.
 
 
 
 
 
 

1901 lines
65 KiB

  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Commentary:
  3. ;;; Code:
  4. ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
  5. ;; SETUP_LOAD: (and (file-readable-p file)
  6. ;; SETUP_LOAD: (load-file file)))
  7. (setq debug-on-error t)
  8. ;; make directories
  9. (unless (file-directory-p (expand-file-name user-emacs-directory))
  10. (make-directory (expand-file-name user-emacs-directory)))
  11. (let ((d (expand-file-name (concat user-emacs-directory
  12. "lisp"))))
  13. (unless (file-directory-p d)
  14. (make-directory d))
  15. (add-to-list 'load-path d))
  16. (require 'cl-lib)
  17. (require 'simple)
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. ;; Some macros for internals
  20. ;; `emacs --load emacs.el` with Emacs 24.3 requires with-eval-after-load to be
  21. ;; defined at the toplevel (means that it should not be defined inside of some
  22. ;; special forms like `when'. I do not now how to do with about this...)
  23. (unless (fboundp 'with-eval-after-load)
  24. ;; polyfill for Emacs < 24.4
  25. (defmacro with-eval-after-load (file &rest body)
  26. "After FILE is loaded execute BODY."
  27. (declare (indent 1) (debug t))
  28. `(eval-after-load ,file (quote (progn ,@body)))))
  29. (defun call-after-init (func)
  30. "If `after-init-hook' has been run, call FUNC immediately.
  31. Otherwize hook it."
  32. (if after-init-time
  33. (funcall func)
  34. (add-hook 'after-init-hook
  35. func)))
  36. (defmacro safe-require-or-eval (feature)
  37. "Require FEATURE if available.
  38. At compile time the feature will be loaded immediately."
  39. `(eval-and-compile
  40. (require ,feature nil t)))
  41. (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  42. "Define autoloading FEATURE that defines FUNCTIONS.
  43. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  44. the function same as FEATURE is defined as autoloaded function. BODY is passed
  45. to `eval-after-load'.
  46. After this macro is expanded, this returns the path to library if FEATURE
  47. found, otherwise returns nil."
  48. (declare (indent 2) (debug t))
  49. (let* ((libname (symbol-name (eval feature)))
  50. (libpath (locate-library libname)))
  51. `(progn
  52. (when (locate-library ,libname)
  53. ,@(mapcar (lambda (f)
  54. `(unless (fboundp ',f)
  55. (progn
  56. (message "Autoloaded function `%S' defined (%s)"
  57. (quote ,f)
  58. ,libpath)
  59. (autoload (quote ,f)
  60. ,libname
  61. ,(concat "Autoloaded function defined in \""
  62. libpath
  63. "\".")
  64. t))))
  65. (or (eval functions)
  66. `(,(eval feature)))))
  67. (eval-after-load ,feature
  68. (quote (progn
  69. ,@body)))
  70. (locate-library ,libname))))
  71. (when (autoload-eval-lazily 'tetris nil
  72. (message "Tetris loaded!"))
  73. (message "Tetris found!"))
  74. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  75. ;; download library from web
  76. (defvar fetch-library-enabled-p t
  77. "Set nil to skip downloading with `fetch-library'.")
  78. (defun fetch-library (url &optional byte-compile-p force-download-p)
  79. "Download a library from URL and locate it in \"~/emacs.d/lisp/\".
  80. Return nil if library unfound and failed to download,
  81. otherwise the path where the library installed.
  82. If BYTE-COMPILE-P is t byte compile the file after downloading.
  83. If FORCE-DOWNLOAD-P it t ignore exisiting library and always download.
  84. This function also checks the value of `fetch-library-enabled-p' and do not
  85. fetch libraries if this value is nil. In this case all arguments (including
  86. FORCE-DOWNLOAD-P) will be ignored."
  87. (let* ((dir (expand-file-name (concat user-emacs-directory "lisp/")))
  88. (lib (file-name-sans-extension (file-name-nondirectory url)))
  89. (lpath (concat dir lib ".el"))
  90. (locate-p (locate-library lib)))
  91. (if (and fetch-library-enabled-p
  92. (or force-download-p
  93. (not locate-p)))
  94. (if (progn (message "Downloading %s..."
  95. url)
  96. (download-file url
  97. lpath
  98. t))
  99. (progn (message "Downloading %s...done"
  100. url)
  101. (when (and byte-compile-p
  102. (require 'bytecomp nil t))
  103. (and (file-exists-p (byte-compile-dest-file lpath))
  104. (delete-file (byte-compile-dest-file lpath)))
  105. (message "Byte-compiling %s..."
  106. lpath)
  107. (byte-compile-file lpath)
  108. (message "Byte-compiling %s...done"
  109. lpath)))
  110. (progn (and (file-writable-p lpath)
  111. (delete-file lpath))
  112. (message "Downloading %s...failed"
  113. url))))
  114. (locate-library lib)))
  115. ;; If EMACS_EL_DRY_RUN is set and it is not an empty string, fetch-library
  116. ;; does not actually fetch library.
  117. (let ((dryrun (getenv "EMACS_EL_DRY_RUN")))
  118. (when (and dryrun
  119. (< 0
  120. (length dryrun)))
  121. (setq fetch-library-enabled-p
  122. nil)
  123. (message "EMACS_EL_DRY_RUN is set. Skip fetching libraries.")))
  124. (defun download-file (url path &optional ok-if-already-exists)
  125. "Download file from URL and output to PATH.
  126. IF OK-IF-ALREADY-EXISTS is true force download."
  127. (let ((curl (executable-find "curl"))
  128. (wget (executable-find "wget")))
  129. (cond (wget
  130. (if (and (not ok-if-already-exists)
  131. (file-exists-p path))
  132. nil
  133. (and (eq 0
  134. (call-process wget
  135. nil
  136. nil
  137. nil
  138. "-O"
  139. path
  140. url
  141. ))
  142. path)))
  143. (curl
  144. (if (and (not ok-if-already-exists)
  145. (file-exists-p path))
  146. nil
  147. (and (eq 0
  148. (call-process curl
  149. nil
  150. nil
  151. nil
  152. "--output"
  153. path
  154. "-L"
  155. url
  156. ))
  157. path)))
  158. (t
  159. (ignore-errors
  160. (require 'url)
  161. (url-copy-file url
  162. path
  163. ok-if-already-exists)
  164. path)))))
  165. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  166. ;; package
  167. (set (defvar 10sr-package-list)
  168. '(
  169. markdown-mode
  170. yaml-mode
  171. gnuplot-mode
  172. php-mode
  173. erlang
  174. js2-mode
  175. git-commit
  176. gitignore-mode
  177. adoc-mode
  178. ;; ack
  179. color-moccur
  180. ggtags
  181. flycheck
  182. auto-highlight-symbol
  183. ;; is flymake installs are required?
  184. ;;flymake-jshint
  185. ;;flymake-python-pyflakes
  186. xclip
  187. foreign-regexp
  188. multi-term
  189. term-run
  190. editorconfig
  191. git-ps1-mode
  192. restart-emacs
  193. fill-column-indicator
  194. pkgbuild-mode
  195. minibuffer-line
  196. scala-mode2
  197. ensime
  198. editorconfig
  199. cyberpunk-theme
  200. git-command
  201. prompt-text
  202. ;; 10sr repository
  203. ;; 10sr-extras
  204. terminal-title
  205. recentf-show
  206. dired-list-all-mode
  207. pack
  208. set-modeline-color
  209. read-only-only-mode
  210. smart-revert
  211. autosave
  212. ;;window-organizer
  213. remember-major-modes-mode
  214. ilookup
  215. pasteboard
  216. ))
  217. (when (safe-require-or-eval 'package)
  218. (setq package-archives
  219. `(,@package-archives
  220. ("melpa" . "https://melpa.org/packages/")
  221. ("10sr-el" . "https://10sr.github.io/emacs-lisp/p/")))
  222. (package-initialize)
  223. (defun my-auto-install-package ()
  224. "Install packages semi-automatically."
  225. (interactive)
  226. (package-refresh-contents)
  227. (mapc (lambda (pkg)
  228. (or (package-installed-p pkg)
  229. (locate-library (symbol-name pkg))
  230. (package-install pkg)))
  231. 10sr-package-list))
  232. )
  233. ;; (lazy-load-eval 'sudoku)
  234. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  235. ;; my-idle-hook
  236. (defvar my-idle-hook nil
  237. "Hook run when idle for several secs.")
  238. (defvar my-idle-hook-sec 5
  239. "Second to run `my-idle-hook'.")
  240. (run-with-idle-timer my-idle-hook-sec
  241. t
  242. (lambda ()
  243. (run-hooks 'my-idle-hook)))
  244. ;; (add-hook 'my-idle-hook
  245. ;; (lambda ()
  246. ;; (message "idle hook message")))
  247. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  248. ;; start and quit
  249. (setq inhibit-startup-message t)
  250. (setq confirm-kill-emacs 'y-or-n-p)
  251. (setq gc-cons-threshold (* 1024 1024 4))
  252. (when window-system
  253. (add-to-list 'default-frame-alist '(cursor-type . box))
  254. (add-to-list 'default-frame-alist '(background-color . "white"))
  255. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  256. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  257. ;; does not work?
  258. )
  259. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  260. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  261. (and (fboundp 'tool-bar-mode)
  262. (tool-bar-mode 0))
  263. (and (fboundp 'set-scroll-bar-mode)
  264. (set-scroll-bar-mode nil))
  265. (add-hook 'kill-emacs-hook
  266. ;; load init file when terminating emacs to ensure file is not broken
  267. 'reload-init-file)
  268. (defun my-force-kill-emacs ()
  269. "My force kill Emacs."
  270. (interactive)
  271. (let ((kill-emacs-hook nil))
  272. (kill-emacs)))
  273. (call-after-init
  274. (lambda ()
  275. (message "%s %s" invocation-name emacs-version)
  276. (message "%s was taken to initialize emacs." (emacs-init-time))
  277. (switch-to-buffer "*Messages*")))
  278. (cd ".") ; when using windows use / instead of \ in `default-directory'
  279. ;; locale
  280. (set-language-environment "Japanese")
  281. (set-default-coding-systems 'utf-8-unix)
  282. (prefer-coding-system 'utf-8-unix)
  283. (setq system-time-locale "C")
  284. ;; my prefix map
  285. (defvar my-prefix-map nil
  286. "My prefix map.")
  287. (define-prefix-command 'my-prefix-map)
  288. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  289. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  290. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  291. ;; (comint-show-maximum-output)
  292. ;; kill scratch
  293. (call-after-init (lambda ()
  294. (let ((buf (get-buffer "*scratch*")))
  295. (when buf
  296. (kill-buffer buf)))))
  297. ;; modifier keys
  298. ;; (setq mac-option-modifier 'control)
  299. ;; display
  300. (setq visible-bell t)
  301. (setq ring-bell-function 'ignore)
  302. (mouse-avoidance-mode 'banish)
  303. (setq echo-keystrokes 0.1)
  304. (defun reload-init-file ()
  305. "Reload Emacs init file."
  306. (interactive)
  307. (when (and user-init-file
  308. (file-readable-p user-init-file))
  309. (load-file user-init-file)))
  310. (safe-require-or-eval 'session)
  311. ;; server
  312. (when (safe-require-or-eval 'server)
  313. (setq 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. (setq server-use-tcp t))
  323. (server-start))
  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. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  387. (delete-selection-mode 1)
  388. (cua-mode 0)
  389. (setq line-move-visual nil)
  390. ;; key bindings
  391. ;; moving around
  392. ;; (global-set-key (kbd "M-j") 'next-line)
  393. ;; (global-set-key (kbd "M-k") 'previous-line)
  394. ;; (global-set-key (kbd "M-h") 'backward-char)
  395. ;; (global-set-key (kbd "M-l") 'forward-char)
  396. ;;(keyboard-translate ?\M-j ?\C-j)
  397. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  398. (define-key esc-map "p" 'backward-paragraph)
  399. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  400. (define-key esc-map "n" 'forward-paragraph)
  401. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  402. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  403. (global-set-key (kbd "C-<left>") 'scroll-down)
  404. (global-set-key (kbd "C-<right>") 'scroll-up)
  405. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  406. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  407. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  408. ;; C-h and DEL
  409. (global-set-key (kbd "C-h") (kbd "DEL"))
  410. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  411. (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  412. (define-key esc-map "k" 'my-copy-whole-line)
  413. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  414. (define-key esc-map "u" 'undo)
  415. (define-key esc-map "i" (kbd "ESC TAB"))
  416. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  417. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  418. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  419. (define-key my-prefix-map (kbd "C-o") 'occur)
  420. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  421. ;; title and mode-line
  422. (when (safe-require-or-eval 'terminal-title)
  423. ;; if TERM is not screen use default value
  424. (if (getenv "TMUX")
  425. ;; if use tmux locally just basename of current dir
  426. (set-variable 'terminal-title-format
  427. '((file-name-nondirectory (directory-file-name
  428. default-directory))))
  429. (if (and (let ((tty-type (frame-parameter nil
  430. 'tty-type)))
  431. (and tty-type
  432. (equal (car (split-string tty-type
  433. "-"))
  434. "screen")))
  435. (not (getenv "SSH_CONNECTION")))
  436. (set-variable 'terminal-title-format
  437. '((file-name-nondirectory (directory-file-name
  438. default-directory))))
  439. ;; seems that TMUX is used locally and ssh to remote host
  440. (set-variable 'terminal-title-format
  441. `("em:"
  442. ,user-login-name
  443. "@"
  444. ,(car (split-string system-name
  445. "\\."))
  446. ":"
  447. default-directory))
  448. )
  449. )
  450. (terminal-title-mode))
  451. (setq eol-mnemonic-dos "\\r\\n")
  452. (setq eol-mnemonic-mac "\\r")
  453. (setq eol-mnemonic-unix "\\n")
  454. (which-function-mode 0)
  455. (line-number-mode 0)
  456. (column-number-mode 0)
  457. (size-indication-mode 0)
  458. (setq mode-line-position
  459. '(:eval (format "L%%l/%d,C%%c"
  460. (count-lines (point-max)
  461. (point-min)))))
  462. (when (safe-require-or-eval 'git-ps1-mode)
  463. (git-ps1-mode))
  464. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  465. ;; display date
  466. (when (safe-require-or-eval 'time)
  467. (setq display-time-interval 29)
  468. (setq display-time-day-and-date t)
  469. (setq display-time-format "%Y/%m/%d %a %H:%M")
  470. ;; (if window-system
  471. ;; (display-time-mode 0)
  472. ;; (display-time-mode 1))
  473. (when display-time-mode
  474. (display-time-update)))
  475. ;; ;; current directory
  476. ;; (let ((ls (member 'mode-line-buffer-identification
  477. ;; mode-line-format)))
  478. ;; (setcdr ls
  479. ;; (cons '(:eval (concat " ("
  480. ;; (abbreviate-file-name default-directory)
  481. ;; ")"))
  482. ;; (cdr ls))))
  483. ;; ;; display last modified time
  484. ;; (let ((ls (member 'mode-line-buffer-identification
  485. ;; mode-line-format)))
  486. ;; (setcdr ls
  487. ;; (cons '(:eval (concat " "
  488. ;; my-buffer-file-last-modified-time))
  489. ;; (cdr ls))))
  490. (defun buffer-list-not-start-with-space ()
  491. "Return a list of buffers that not start with whitespaces."
  492. (let ((bl (buffer-list))
  493. b nbl)
  494. (while bl
  495. (setq b (pop bl))
  496. (unless (string-equal " "
  497. (substring (buffer-name b)
  498. 0
  499. 1))
  500. (add-to-list 'nbl b)))
  501. nbl))
  502. ;; http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/
  503. ;; (add-to-list 'minor-mode-alist
  504. ;; '(global-whitespace-mode ""))
  505. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  506. ;; minibuffer
  507. (setq insert-default-directory t)
  508. (setq completion-ignore-case t
  509. read-file-name-completion-ignore-case t
  510. read-buffer-completion-ignore-case t)
  511. (setq resize-mini-windows t)
  512. (temp-buffer-resize-mode 1)
  513. (savehist-mode 1)
  514. (fset 'yes-or-no-p 'y-or-n-p)
  515. ;; complete symbol when `eval'
  516. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  517. (define-key minibuffer-local-map (kbd "C-u")
  518. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  519. ;; I dont know these bindings are good
  520. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  521. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  522. (when (safe-require-or-eval 'minibuffer-line)
  523. (set-face-underline 'minibuffer-line nil)
  524. (set-variable 'minibuffer-line-refresh-interval
  525. 25)
  526. (set-variable 'minibuffer-line-format
  527. `(,(concat user-login-name
  528. "@"
  529. (car (split-string system-name
  530. "\\."))
  531. ":")
  532. (:eval (abbreviate-file-name (or buffer-file-name
  533. default-directory)))
  534. (:eval (and (fboundp 'git-ps1-mode-get-current)
  535. (git-ps1-mode-get-current " [GIT:%s]")))
  536. " "
  537. (:eval (format-time-string display-time-format))))
  538. (minibuffer-line-mode 1)
  539. )
  540. (when (safe-require-or-eval 'prompt-text)
  541. (set-variable 'prompt-text-format
  542. `(,(concat ""
  543. user-login-name
  544. "@"
  545. (car (split-string system-name
  546. "\\."))
  547. ":")
  548. (:eval (abbreviate-file-name (or buffer-file-name
  549. default-directory)))
  550. (:eval (and (fboundp 'git-ps1-mode-get-current)
  551. (git-ps1-mode-get-current " [GIT:%s]")))
  552. " "
  553. (:eval (format-time-string display-time-format))
  554. "\n"
  555. (:eval (symbol-name this-command))
  556. ": "))
  557. (prompt-text-mode 1))
  558. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  559. ;; letters, font-lock mode and fonts
  560. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  561. ;; (set-window-margins (selected-window) 1 1)
  562. (and (or (eq system-type 'Darwin)
  563. (eq system-type 'darwin))
  564. (fboundp 'mac-set-input-method-parameter)
  565. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  566. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  567. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  568. (boundp 'input-method-inactivate-hook))
  569. (add-hook 'input-method-activate-hook
  570. (lambda () (set-cursor-color "red")))
  571. (add-hook 'input-method-inactivate-hook
  572. (lambda () (set-cursor-color "black"))))
  573. (when (safe-require-or-eval 'paren)
  574. (show-paren-mode 1)
  575. (setq show-paren-delay 0.5
  576. show-paren-style 'parenthesis) ; mixed is hard to read
  577. ;; (set-face-background 'show-paren-match
  578. ;; "black")
  579. ;; ;; (face-foreground 'default))
  580. ;; (set-face-foreground 'show-paren-match
  581. ;; "white")
  582. ;; (set-face-inverse-video-p 'show-paren-match
  583. ;; t)
  584. )
  585. (transient-mark-mode 1)
  586. (global-font-lock-mode 1)
  587. (setq font-lock-global-modes
  588. '(not
  589. help-mode
  590. eshell-mode
  591. ;;term-mode
  592. Man-mode))
  593. ;; (standard-display-ascii ?\n "$\n")
  594. ;; (defvar my-eol-face
  595. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  596. ;; )
  597. ;; (defvar my-tab-face
  598. ;; '(("\t" . '(0 highlight t nil))))
  599. (defvar my-jspace-face
  600. '(("\u3000" . '(0 highlight t nil))))
  601. (add-hook 'font-lock-mode-hook
  602. (lambda ()
  603. ;; (font-lock-add-keywords nil my-eol-face)
  604. (font-lock-add-keywords nil my-jspace-face)
  605. ))
  606. (when (safe-require-or-eval 'whitespace)
  607. (add-to-list 'whitespace-display-mappings ; not work
  608. `(tab-mark ?\t ,(vconcat "^I\t")))
  609. ;; (add-to-list 'whitespace-display-mappings
  610. ;; `(newline-mark ?\n ,(vconcat "$\n")))
  611. (setq whitespace-style '(face
  612. trailing ; trailing blanks
  613. newline ; newlines
  614. newline-mark ; use display table for newline
  615. tab-mark
  616. empty ; empty lines at beg or end of buffer
  617. lines-tail ; lines over 80
  618. ))
  619. ;; (setq whitespace-newline 'font-lock-comment-face)
  620. (global-whitespace-mode t)
  621. (if (eq (display-color-cells)
  622. 256)
  623. (set-face-foreground 'whitespace-newline "color-109")
  624. ;; (progn
  625. ;; (set-face-bold-p 'whitespace-newline
  626. ;; t))
  627. ))
  628. (and nil
  629. (safe-require-or-eval 'fill-column-indicator)
  630. (setq fill-column-indicator))
  631. ;; highlight current line
  632. ;; http://wiki.riywo.com/index.php?Meadow
  633. (face-spec-set 'hl-line
  634. '((((min-colors 256)
  635. (background dark))
  636. (:background "color-234"))
  637. (((min-colors 256)
  638. (background light))
  639. (:background "color-234"))
  640. (t
  641. (:underline "black"))))
  642. (set-variable 'hl-line-global-modes
  643. '(not
  644. term-mode))
  645. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  646. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  647. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  648. ;;(safe-require-or-eval 'set-modeline-color)
  649. ;; (let ((fg (face-foreground 'default))
  650. ;; (bg (face-background 'default)))
  651. ;; (set-face-background 'mode-line-inactive
  652. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  653. ;; (set-face-foreground 'mode-line-inactive
  654. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  655. ;; (set-face-underline 'mode-line-inactive
  656. ;; t)
  657. ;; (set-face-underline 'vertical-border
  658. ;; nil)
  659. ;; Not found in MELPA nor any other package repositories
  660. (and (fetch-library
  661. "https://raw.github.com/tarao/elisp/master/end-mark.el"
  662. t)
  663. (safe-require-or-eval 'end-mark)
  664. (global-end-mark-mode))
  665. (when (safe-require-or-eval 'auto-highlight-symbol)
  666. (set-variable 'ahs-idle-interval 0.6)
  667. (global-auto-highlight-symbol-mode 1))
  668. (when (safe-require-or-eval 'cyberpunk-theme)
  669. (load-theme 'cyberpunk t)
  670. (set-face-attribute 'button
  671. nil
  672. :inherit 'highlight))
  673. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  674. ;; file handling
  675. (when (safe-require-or-eval 'editorconfig)
  676. ;; (set-variable 'editorconfig-get-properties-function
  677. ;; 'editorconfig-core-get-properties-hash)
  678. (editorconfig-mode 1))
  679. (setq revert-without-query '(".+"))
  680. ;; save cursor position
  681. (when (safe-require-or-eval 'saveplace)
  682. (setq-default save-place t)
  683. (setq save-place-file (concat user-emacs-directory
  684. "places")))
  685. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  686. (setq make-backup-files t)
  687. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  688. (setq backup-directory-alist
  689. (cons (cons "\\.*$" (expand-file-name (concat user-emacs-directory
  690. "backup")))
  691. backup-directory-alist))
  692. (setq version-control 'never)
  693. (setq delete-old-versions t)
  694. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  695. "auto-save/")))
  696. (setq delete-auto-save-files t)
  697. (add-to-list 'completion-ignored-extensions ".bak")
  698. ;; (setq delete-by-moving-to-trash t
  699. ;; trash-directory "~/.emacs.d/trash")
  700. (add-hook 'after-save-hook
  701. 'executable-make-buffer-file-executable-if-script-p)
  702. (set (defvar bookmark-default-file)
  703. (expand-file-name (concat user-emacs-directory
  704. "bmk")))
  705. (with-eval-after-load 'recentf
  706. (defvar recentf-exclude nil)
  707. (add-to-list 'recentf-exclude
  708. (regexp-quote bookmark-default-file)))
  709. (when (safe-require-or-eval 'smart-revert)
  710. (smart-revert-on))
  711. ;; autosave
  712. (when (safe-require-or-eval 'autosave)
  713. (autosave-set 2))
  714. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  715. ;; buffer killing
  716. ;; (defun my-delete-window-killing-buffer () nil)
  717. (defun my-query-kill-current-buffer ()
  718. "Interactively kill current buffer."
  719. (interactive)
  720. (if (y-or-n-p (concat "kill current buffer? :"))
  721. (kill-buffer (current-buffer))))
  722. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  723. (substitute-key-definition 'kill-buffer
  724. 'my-query-kill-current-buffer
  725. global-map)
  726. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  727. ;; share clipboard with x
  728. ;; this page describes this in details, but only these sexps seem to be needed
  729. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  730. (and (not window-system)
  731. (not (eq window-system 'mac))
  732. (getenv "DISPLAY")
  733. (not (equal (getenv "DISPLAY") ""))
  734. (executable-find "xclip")
  735. ;; (< emacs-major-version 24)
  736. (safe-require-or-eval 'xclip)
  737. nil
  738. (turn-on-xclip))
  739. (and (eq system-type 'darwin)
  740. (safe-require-or-eval 'pasteboard)
  741. (turn-on-pasteboard)
  742. (getenv "TMUX")
  743. (pasteboard-enable-rtun))
  744. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  745. ;; some modes and hooks
  746. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  747. (when (safe-require-or-eval 'company)
  748. (global-company-mode)
  749. (set-variable 'company-idle-delay 0.5)
  750. (set-variable 'company-minimum-prefix-length 2)
  751. (set-variable 'company-selection-wrap-around t))
  752. ;; https://github.com/lunaryorn/flycheck
  753. (when (safe-require-or-eval 'flycheck)
  754. (call-after-init 'global-flycheck-mode))
  755. (set-variable 'ac-ignore-case nil)
  756. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  757. (define-key ctl-x-map "t" 'term-run-shell-command))
  758. (add-to-list 'safe-local-variable-values
  759. '(encoding utf-8))
  760. (setq enable-local-variables :safe)
  761. (when (safe-require-or-eval 'remember-major-modes-mode)
  762. (remember-major-modes-mode 1))
  763. ;; Detect file type from shebang and set major-mode.
  764. (add-to-list 'interpreter-mode-alist
  765. '("python3" . python-mode))
  766. (add-to-list 'interpreter-mode-alist
  767. '("python2" . python-mode))
  768. ;; http://fukuyama.co/foreign-regexp
  769. '(and (safe-require-or-eval 'foreign-regexp)
  770. (progn
  771. (setq foreign-regexp/regexp-type 'perl)
  772. '(setq reb-re-syntax 'foreign-regexp)
  773. ))
  774. (autoload-eval-lazily 'sql '(sql-mode)
  775. (safe-require-or-eval 'sql-indent))
  776. (when (autoload-eval-lazily 'git-command)
  777. (define-key ctl-x-map "g" 'git-command))
  778. (when (safe-require-or-eval 'git-commit)
  779. (global-git-commit-mode 1))
  780. (when (fetch-library
  781. "http://www.emacswiki.org/emacs/download/sl.el"
  782. t)
  783. (autoload-eval-lazily 'sl))
  784. (with-eval-after-load 'jdee
  785. (add-hook 'jdee-mode-hook
  786. (lambda ()
  787. (make-local-variable 'global-mode-string)
  788. (add-to-list 'global-mode-string
  789. mode-line-position))))
  790. (with-eval-after-load 'make-mode
  791. (defvar makefile-mode-map (make-sparse-keymap))
  792. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  793. ;; this functions is set in write-file-functions, i cannot find any
  794. ;; good way to remove this.
  795. (fset 'makefile-warn-suspicious-lines 'ignore))
  796. (with-eval-after-load 'verilog-mode
  797. (defvar verilog-mode-map (make-sparse-keymap))
  798. (define-key verilog-mode-map ";" 'self-insert-command))
  799. (setq diff-switches "-u")
  800. (with-eval-after-load 'diff-mode
  801. ;; (when (and (eq major-mode
  802. ;; 'diff-mode)
  803. ;; (not buffer-file-name))
  804. ;; ;; do not pass when major-mode is derived mode of diff-mode
  805. ;; (view-mode 1))
  806. (set-face-attribute 'diff-header nil
  807. :foreground nil
  808. :background nil
  809. :weight 'bold)
  810. (set-face-attribute 'diff-file-header nil
  811. :foreground nil
  812. :background nil
  813. :weight 'bold)
  814. (set-face-foreground 'diff-index-face "blue")
  815. (set-face-attribute 'diff-hunk-header nil
  816. :foreground "cyan"
  817. :weight 'normal)
  818. (set-face-attribute 'diff-context nil
  819. ;; :foreground "white"
  820. :foreground nil
  821. :weight 'normal)
  822. (set-face-foreground 'diff-removed-face "red")
  823. (set-face-foreground 'diff-added-face "green")
  824. (set-face-background 'diff-removed-face nil)
  825. (set-face-background 'diff-added-face nil)
  826. (set-face-attribute 'diff-changed nil
  827. :foreground "magenta"
  828. :weight 'normal)
  829. (set-face-attribute 'diff-refine-change nil
  830. :foreground nil
  831. :background nil
  832. :weight 'bold
  833. :inverse-video t)
  834. ;; Annoying !
  835. ;;(diff-auto-refine-mode)
  836. )
  837. ;; (ffap-bindings)
  838. (set-variable 'sh-here-document-word "__EOC__")
  839. (when (autoload-eval-lazily 'adoc-mode
  840. nil
  841. (defvar adoc-mode-map (make-sparse-keymap))
  842. (define-key adoc-mode-map (kbd "C-m") 'newline))
  843. (setq auto-mode-alist
  844. `(("\\.adoc\\'" . adoc-mode)
  845. ("\\.asciidoc\\'" . adoc-mode)
  846. ,@auto-mode-alist)))
  847. (with-eval-after-load 'markup-faces
  848. ;; Is this too match ?
  849. (set-face-foreground 'markup-meta-face
  850. "color-245")
  851. (set-face-foreground 'markup-meta-hide-face
  852. "color-245")
  853. )
  854. (setq auto-mode-alist
  855. `(("autostart\\'" . sh-mode)
  856. ("xinitrc\\'" . sh-mode)
  857. ("xprograms\\'" . sh-mode)
  858. ("PKGBUILD\\'" . sh-mode)
  859. ,@auto-mode-alist))
  860. ;; TODO: check if this is required
  861. (and (autoload-eval-lazily 'groovy-mode)
  862. (add-to-list 'auto-mode-alist
  863. '("build\\.gradle\\'" . groovy-mode)))
  864. (with-eval-after-load 'yaml-mode
  865. (defvar yaml-mode-map (make-sparse-keymap))
  866. (define-key yaml-mode-map (kbd "C-m") 'newline))
  867. (with-eval-after-load 'html-mode
  868. (defvar html-mode-map (make-sparse-keymap))
  869. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  870. (with-eval-after-load 'text-mode
  871. (define-key text-mode-map (kbd "C-m") 'newline))
  872. (add-to-list 'Info-default-directory-list
  873. (expand-file-name "~/.info/emacs-ja"))
  874. (with-eval-after-load 'apropos
  875. (defvar apropos-mode-map (make-sparse-keymap))
  876. (define-key apropos-mode-map "n" 'next-line)
  877. (define-key apropos-mode-map "p" 'previous-line))
  878. (with-eval-after-load 'isearch
  879. ;; (define-key isearch-mode-map
  880. ;; (kbd "C-j") 'isearch-other-control-char)
  881. ;; (define-key isearch-mode-map
  882. ;; (kbd "C-k") 'isearch-other-control-char)
  883. ;; (define-key isearch-mode-map
  884. ;; (kbd "C-h") 'isearch-other-control-char)
  885. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  886. (define-key isearch-mode-map (kbd "M-r")
  887. 'isearch-query-replace-regexp))
  888. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  889. (setq lazy-highlight-cleanup nil)
  890. ;; face for isearch highlighing
  891. (set-face-attribute 'lazy-highlight
  892. nil
  893. :foreground `unspecified
  894. :background `unspecified
  895. :underline t
  896. ;; :weight `bold
  897. )
  898. (add-hook 'outline-mode-hook
  899. (lambda ()
  900. (when (string-match "\\.md\\'" buffer-file-name)
  901. (set (make-local-variable 'outline-regexp) "#+ "))))
  902. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  903. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  904. (when (autoload-eval-lazily 'markdown-mode
  905. '(markdown-mode gfm-mode)
  906. (defvar gfm-mode-map (make-sparse-keymap))
  907. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline))
  908. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  909. (set-variable 'markdown-command (or (executable-find "markdown")
  910. (executable-find "markdown.pl")
  911. ""))
  912. (add-hook 'markdown-mode-hook
  913. (lambda ()
  914. (outline-minor-mode 1)
  915. (flyspell-mode)
  916. (set (make-local-variable 'comment-start) ";")))
  917. )
  918. ;; c-mode
  919. ;; http://www.emacswiki.org/emacs/IndentingC
  920. ;; http://en.wikipedia.org/wiki/Indent_style
  921. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  922. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  923. (with-eval-after-load 'cc-vars
  924. (defvar c-default-style nil)
  925. (add-to-list 'c-default-style
  926. '(c-mode . "k&r"))
  927. (add-to-list 'c-default-style
  928. '(c++-mode . "k&r"))
  929. (add-hook 'c-mode-common-hook
  930. (lambda ()
  931. ;; why c-basic-offset in k&r style defaults to 5 ???
  932. (set-variable 'c-basic-offset 4)
  933. (set-variable 'indent-tabs-mode nil)
  934. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  935. (c-toggle-hungry-state -1)
  936. ;; (and (require 'gtags nil t)
  937. ;; (gtags-mode 1))
  938. )))
  939. (when (autoload-eval-lazily 'php-mode)
  940. (add-hook 'php-mode-hook
  941. (lambda ()
  942. (set-variable 'c-basic-offset 2))))
  943. (autoload-eval-lazily 'js2-mode nil
  944. ;; currently do not use js2-mode
  945. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  946. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  947. (defvar js2-mode-map (make-sparse-keymap))
  948. (define-key js2-mode-map (kbd "C-m") (lambda ()
  949. (interactive)
  950. (js2-enter-key)
  951. (indent-for-tab-command)))
  952. ;; (add-hook (kill-local-variable 'before-save-hook)
  953. ;; 'js2-before-save)
  954. ;; (add-hook 'before-save-hook
  955. ;; 'my-indent-buffer
  956. ;; nil
  957. ;; t)
  958. )
  959. (with-eval-after-load 'js
  960. (set-variable 'js-indent-level 2))
  961. (add-to-list 'interpreter-mode-alist
  962. '("node" . js-mode))
  963. (when (autoload-eval-lazily 'flymake-jslint
  964. '(flymake-jslint-load))
  965. (autoload-eval-lazily 'js nil
  966. (add-hook 'js-mode-hook
  967. 'flymake-jslint-load)))
  968. (safe-require-or-eval 'js-doc)
  969. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  970. (when (safe-require-or-eval 'uniquify)
  971. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  972. (setq uniquify-ignore-buffers-re "*[^*]+*")
  973. (setq uniquify-min-dir-content 1))
  974. (with-eval-after-load 'view
  975. (defvar view-mode-map (make-sparse-keymap))
  976. (define-key view-mode-map "j" 'scroll-up-line)
  977. (define-key view-mode-map "k" 'scroll-down-line)
  978. (define-key view-mode-map "v" 'toggle-read-only)
  979. (define-key view-mode-map "q" 'bury-buffer)
  980. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  981. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  982. ;; (define-key view-mode-map
  983. ;; "n" 'nonincremental-repeat-search-forward)
  984. ;; (define-key view-mode-map
  985. ;; "N" 'nonincremental-repeat-search-backward)
  986. (define-key view-mode-map "/" 'isearch-forward-regexp)
  987. (define-key view-mode-map "?" 'isearch-backward-regexp)
  988. (define-key view-mode-map "n" 'isearch-repeat-forward)
  989. (define-key view-mode-map "N" 'isearch-repeat-backward)
  990. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  991. (global-set-key "\M-r" 'view-mode)
  992. ;; (setq view-read-only t)
  993. (add-hook 'Man-mode-hook
  994. (lambda ()
  995. (view-mode 1)
  996. (setq truncate-lines nil)))
  997. (set-variable 'Man-notify-method (if window-system
  998. 'newframe
  999. 'aggressive))
  1000. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  1001. "woman_cache.el")))
  1002. (defalias 'man 'woman)
  1003. (add-to-list 'auto-mode-alist
  1004. '("tox\\.ini\\'" . conf-unix-mode))
  1005. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1006. ;; python
  1007. (when (autoload-eval-lazily 'python '(python-mode)
  1008. (defvar python-mode-map (make-sparse-keymap))
  1009. (define-key python-mode-map (kbd "C-c C-e") 'my-python-run-as-command)
  1010. (define-key python-mode-map (kbd "C-c C-b") 'my-python-display-python-buffer)
  1011. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)
  1012. (defvar inferior-python-mode-map (make-sparse-keymap))
  1013. (define-key inferior-python-mode-map (kbd "<up>") 'comint-previous-input)
  1014. (define-key inferior-python-mode-map (kbd "<down>") 'comint-next-input)
  1015. )
  1016. (set-variable 'python-python-command (or (executable-find "python3")
  1017. (executable-find "python")))
  1018. ;; (defun my-python-run-as-command ()
  1019. ;; ""
  1020. ;; (interactive)
  1021. ;; (shell-command (concat python-python-command " " buffer-file-name)))
  1022. (defun my-python-display-python-buffer ()
  1023. ""
  1024. (interactive)
  1025. (defvar python-buffer nil)
  1026. (set-window-text-height (display-buffer python-buffer
  1027. t)
  1028. 7))
  1029. (add-hook 'inferior-python-mode-hook
  1030. (lambda ()
  1031. (my-python-display-python-buffer))))
  1032. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1033. ;; gauche-mode
  1034. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  1035. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  1036. (when (and (fetch-library
  1037. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  1038. t)
  1039. (autoload-eval-lazily 'gauche-mode '(gauche-mode run-scheme)
  1040. (defvar gauche-mode-map (make-sparse-keymap))
  1041. (defvar scheme-mode-map (make-sparse-keymap))
  1042. (define-key gauche-mode-map
  1043. (kbd "C-c C-z") 'run-gauche-other-window)
  1044. (define-key scheme-mode-map
  1045. (kbd "C-c C-c") 'scheme-send-buffer)
  1046. (define-key scheme-mode-map
  1047. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer)))
  1048. (let ((s (executable-find "gosh")))
  1049. (set-variable 'scheme-program-name s)
  1050. (set-variable 'gauche-program-name s))
  1051. (defvar gauche-program-name nil)
  1052. (defvar scheme-buffer nil)
  1053. (defun run-gauche-other-window ()
  1054. "Run gauche on other window"
  1055. (interactive)
  1056. (switch-to-buffer-other-window
  1057. (get-buffer-create "*scheme*"))
  1058. (run-gauche))
  1059. (defun run-gauche ()
  1060. "run gauche"
  1061. (interactive)
  1062. (run-scheme gauche-program-name)
  1063. )
  1064. (defun scheme-send-buffer ()
  1065. ""
  1066. (interactive)
  1067. (scheme-send-region (point-min) (point-max))
  1068. (my-scheme-display-scheme-buffer)
  1069. )
  1070. (defun my-scheme-display-scheme-buffer ()
  1071. ""
  1072. (interactive)
  1073. (set-window-text-height (display-buffer scheme-buffer
  1074. t)
  1075. 7))
  1076. (add-hook 'scheme-mode-hook
  1077. (lambda ()
  1078. nil))
  1079. (add-hook 'inferior-scheme-mode-hook
  1080. (lambda ()
  1081. ;; (my-scheme-display-scheme-buffer)
  1082. ))
  1083. (setq auto-mode-alist
  1084. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1085. (setq auto-mode-alist
  1086. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1087. )
  1088. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1089. ;; term mode
  1090. ;; (setq multi-term-program shell-file-name)
  1091. (when (autoload-eval-lazily 'multi-term)
  1092. (set-variable 'multi-term-switch-after-close nil)
  1093. (set-variable 'multi-term-dedicated-select-after-open-p t)
  1094. (set-variable 'multi-term-dedicated-window-height 20))
  1095. (when (autoload-eval-lazily 'term '(term ansi-term)
  1096. (defvar term-raw-map (make-sparse-keymap))
  1097. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  1098. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  1099. (define-key term-raw-map (kbd "<up>") 'scroll-down-line)
  1100. (define-key term-raw-map (kbd "<down>") 'scroll-up-line)
  1101. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  1102. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  1103. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  1104. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  1105. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  1106. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  1107. (define-key term-raw-map [delete] 'term-send-raw)
  1108. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  1109. (define-key term-raw-map "\C-y" 'term-paste)
  1110. (define-key term-raw-map
  1111. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  1112. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  1113. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  1114. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  1115. ;; (define-key term-raw-map "\C-d" 'delete-char)
  1116. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  1117. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  1118. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  1119. ;; (define-key term-raw-map "\C-f" 'forward-char)
  1120. ;; (define-key term-raw-map "\C-b" 'backward-char)
  1121. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  1122. )
  1123. (defun my-term-quit-or-send-raw ()
  1124. ""
  1125. (interactive)
  1126. (if (get-buffer-process (current-buffer))
  1127. (call-interactively 'term-send-raw)
  1128. (kill-buffer)))
  1129. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  1130. ;; (setq term-ansi-default-program shell-file-name)
  1131. (add-hook 'term-setup-hook
  1132. (lambda ()
  1133. (set-variable 'term-display-table (make-display-table))))
  1134. (add-hook 'term-mode-hook
  1135. (lambda ()
  1136. (defvar term-raw-map (make-sparse-keymap))
  1137. ;; (unless (memq (current-buffer)
  1138. ;; (and (featurep 'multi-term)
  1139. ;; (defvar multi-term-buffer-list)
  1140. ;; ;; current buffer is not multi-term buffer
  1141. ;; multi-term-buffer-list))
  1142. ;; )
  1143. (set (make-local-variable 'scroll-margin) 0)
  1144. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  1145. ;; (cua-mode 0)
  1146. ;; (and cua-mode
  1147. ;; (local-unset-key (kbd "C-c")))
  1148. ;; (define-key cua--prefix-override-keymap
  1149. ;;"\C-c" 'term-interrupt-subjob)
  1150. (set (make-local-variable (defvar hl-line-range-function))
  1151. (lambda ()
  1152. '(0 . 0)))
  1153. (define-key term-raw-map
  1154. "\C-x" (lookup-key (current-global-map) "\C-x"))
  1155. (define-key term-raw-map
  1156. "\C-z" (lookup-key (current-global-map) "\C-z"))
  1157. ))
  1158. ;; (add-hook 'term-exec-hook 'forward-char)
  1159. )
  1160. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1161. ;; buffer switching
  1162. (defvar bs-configurations)
  1163. (when (autoload-eval-lazily 'bs '(bs-show)
  1164. ;; (add-to-list 'bs-configurations
  1165. ;; '("processes" nil get-buffer-process ".*" nil nil))
  1166. (add-to-list 'bs-configurations
  1167. '("files-and-terminals" nil nil nil
  1168. (lambda (buf)
  1169. (and (bs-visits-non-file buf)
  1170. (save-excursion
  1171. (set-buffer buf)
  1172. (not (memq major-mode
  1173. '(term-mode
  1174. eshell-mode))))))))
  1175. ;; (setq bs-configurations (list
  1176. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1177. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1178. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1179. )
  1180. ;; (global-set-key "\C-x\C-b" 'bs-show)
  1181. (defalias 'list-buffers 'bs-show)
  1182. (set-variable 'bs-default-configuration "files-and-terminals")
  1183. (set-variable 'bs-default-sort-name "by nothing")
  1184. (add-hook 'bs-mode-hook
  1185. (lambda ()
  1186. ;; (setq bs-default-configuration "files")
  1187. ;; (and bs--show-all
  1188. ;; (call-interactively 'bs-toggle-show-all))
  1189. (set (make-local-variable 'scroll-margin) 0))))
  1190. ;;(iswitchb-mode 1)
  1191. (icomplete-mode)
  1192. (defun iswitchb-buffer-display-other-window ()
  1193. "Do iswitchb in other window."
  1194. (interactive)
  1195. (let ((iswitchb-default-method 'display))
  1196. (call-interactively 'iswitchb-buffer)))
  1197. ;;;;;;;;;;;;;;;;;;;;;;;;
  1198. ;; ilookup
  1199. (with-eval-after-load 'ilookup
  1200. (set-variable 'ilookup-dict-alist
  1201. '(
  1202. ("sdcv" . (lambda (word)
  1203. (shell-command-to-string
  1204. (format "sdcv -n '%s'"
  1205. word))))
  1206. ("en" . (lambda (word)
  1207. (shell-command-to-string
  1208. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  1209. word))))
  1210. ("ja" . (lambda (word)
  1211. (shell-command-to-string
  1212. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  1213. word))))
  1214. ("jaj" . (lambda (word)
  1215. (shell-command-to-string
  1216. (format "sdcv -n -u jmdict-en-ja '%s'"
  1217. word))))
  1218. ("jag" .
  1219. (lambda (word)
  1220. (with-temp-buffer
  1221. (insert (shell-command-to-string
  1222. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  1223. word)))
  1224. (html2text)
  1225. (buffer-substring (point-min)
  1226. (point-max)))))
  1227. ("alc" . (lambda (word)
  1228. (shell-command-to-string
  1229. (format "alc '%s' | head -n 20"
  1230. word))))
  1231. ("app" . (lambda (word)
  1232. (shell-command-to-string
  1233. (format "dict_app '%s'"
  1234. word))))
  1235. ;; letters broken
  1236. ("ms" .
  1237. (lambda (word)
  1238. (let ((url (concat
  1239. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  1240. "Translate?appId=%s&text=%s&to=%s"))
  1241. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  1242. (target "ja")
  1243. (eword (url-hexify-string word)))
  1244. (with-current-buffer (url-retrieve-synchronously
  1245. (format url
  1246. apikey
  1247. eword
  1248. target))
  1249. (message "")
  1250. (goto-char (point-min))
  1251. (search-forward-regexp "^$"
  1252. nil
  1253. t)
  1254. (url-unhex-string (buffer-substring-no-properties
  1255. (point)
  1256. (point-max)))))))
  1257. ))
  1258. ;; (funcall (cdr (assoc "ms"
  1259. ;; ilookup-alist))
  1260. ;; "dictionary")
  1261. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  1262. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  1263. (set-variable 'ilookup-default "ja")
  1264. (when (locate-library "google-translate")
  1265. (defvar ilookup-dict-alist nil)
  1266. (add-to-list 'ilookup-dict-alist
  1267. '("gt" .
  1268. (lambda (word)
  1269. (save-excursion
  1270. (google-translate-translate "auto"
  1271. "ja"
  1272. word))
  1273. (with-current-buffer "*Google Translate*"
  1274. (buffer-substring-no-properties (point-min)
  1275. (point-max)))))))
  1276. )
  1277. (when (autoload-eval-lazily 'google-translate '(google-translate-translate
  1278. google-translate-at-point))
  1279. (set-variable 'google-translate-default-source-language "auto")
  1280. (set-variable 'google-translate-default-target-language "ja"))
  1281. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1282. ;; vc
  1283. (require 'vc)
  1284. (setq 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