Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

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