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.
 
 
 
 
 
 

2486 line
86 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. ;; make directories
  8. (unless (file-directory-p (expand-file-name user-emacs-directory))
  9. (make-directory (expand-file-name user-emacs-directory)))
  10. (let ((d (expand-file-name (concat user-emacs-directory
  11. "lisp"))))
  12. (unless (file-directory-p d)
  13. (make-directory d))
  14. (add-to-list 'load-path d))
  15. (require 'cl-lib)
  16. ;; (add-hook 'after-change-major-mode-hook
  17. ;; (lambda ()
  18. ;; (message "cmm: %S %s"
  19. ;; major-mode
  20. ;; buffer-file-name)))
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;; Some macros for internals
  23. ;; (when (version< emacs-version "24.4")
  24. ;; polyfill for Emacs < 24.4
  25. ;; `emacs --load emacs.el` with Emacs 24.3 requires with-eval-after-load to be
  26. ;; defined at the toplevel (means that it should not be defined inside of some
  27. ;; special forms like `when'. I do not now how to do with about this...)
  28. (unless (fboundp 'with-eval-after-load)
  29. (defmacro with-eval-after-load (file &rest body)
  30. "After FILE is loaded execute BODY."
  31. (declare (indent 1) (debug t))
  32. `(eval-after-load ,file (quote (progn ,@body)))))
  33. (defun call-after-init (func)
  34. "If `after-init-hook' has been run, call FUNC immediately.
  35. Otherwize hook it."
  36. (if after-init-time
  37. (funcall func)
  38. (add-hook 'after-init-hook
  39. func)))
  40. (defmacro safe-require-or-eval (feature)
  41. "Require FEATURE if available.
  42. At compile time the feature will be loaded immediately."
  43. `(eval-and-compile
  44. (require ,feature nil t)))
  45. (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  46. "Define autoloading FEATURE that defines FUNCTIONS.
  47. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  48. the function same as FEATURE is defined as autoloaded function. BODY is passed
  49. to `eval-after-load'.
  50. After this macro is expanded, this returns the path to library if FEATURE
  51. found, otherwise returns nil."
  52. (declare (indent 2) (debug t))
  53. (let* ((libname (symbol-name (eval feature)))
  54. (libpath (locate-library libname)))
  55. `(progn
  56. (when (locate-library ,libname)
  57. ,@(mapcar (lambda (f)
  58. `(unless (fboundp ',f)
  59. (progn
  60. (message "Autoloaded function `%S' defined (%s)"
  61. (quote ,f)
  62. ,libpath)
  63. (autoload (quote ,f)
  64. ,libname
  65. ,(concat "Autoloaded function defined in \""
  66. libpath
  67. "\".")
  68. t))))
  69. (or (eval functions)
  70. `(,(eval feature)))))
  71. (eval-after-load ,feature
  72. (quote (progn
  73. ,@body)))
  74. (locate-library ,libname))))
  75. (when (autoload-eval-lazily 'tetris nil
  76. (message "Tetris loaded!"))
  77. (message "Tetris found!"))
  78. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  79. ;; download library from web
  80. (defvar fetch-library-enabled-p t
  81. "Set nil to skip downloading with `fetch-library'.")
  82. (defun fetch-library (url &optional byte-compile-p force-download-p)
  83. "Download a library from URL and locate it in \"~/emacs.d/lisp/\".
  84. Return nil if library unfound and failed to download,
  85. otherwise the path where the library installed.
  86. If BYTE-COMPILE-P is t byte compile the file after downloading.
  87. If FORCE-DOWNLOAD-P it t ignore exisiting library and always download.
  88. This function also checks the value of `fetch-library-enabled-p' and do not
  89. fetch libraries if this value is nil. In this case all arguments (including
  90. FORCE-DOWNLOAD-P) will be ignored."
  91. (let* ((dir (expand-file-name (concat user-emacs-directory "lisp/")))
  92. (lib (file-name-sans-extension (file-name-nondirectory url)))
  93. (lpath (concat dir lib ".el"))
  94. (locate-p (locate-library lib)))
  95. (if (and fetch-library-enabled-p
  96. (or force-download-p
  97. (not locate-p)))
  98. (if (progn (message "Downloading %s..."
  99. url)
  100. (download-file url
  101. lpath
  102. t))
  103. (progn (message "Downloading %s...done"
  104. url)
  105. (when (and byte-compile-p
  106. (require 'bytecomp nil t))
  107. (and (file-exists-p (byte-compile-dest-file lpath))
  108. (delete-file (byte-compile-dest-file lpath)))
  109. (message "Byte-compiling %s..."
  110. lpath)
  111. (byte-compile-file lpath)
  112. (message "Byte-compiling %s...done"
  113. lpath)))
  114. (progn (and (file-writable-p lpath)
  115. (delete-file lpath))
  116. (message "Downloading %s...failed"
  117. url))))
  118. (locate-library lib)))
  119. ;; If EMACS_EL_DRY_RUN is set and it is not an empty string, fetch-library
  120. ;; does not actually fetch library.
  121. (let ((dryrun (getenv "EMACS_EL_DRY_RUN")))
  122. (when (and dryrun
  123. (< 0
  124. (length dryrun)))
  125. (setq fetch-library-enabled-p
  126. nil)
  127. (message "EMACS_EL_DRY_RUN is set. Skip fetching libraries.")))
  128. (defun download-file (url path &optional ok-if-already-exists)
  129. "Download file from URL and output to PATH.
  130. IF OK-IF-ALREADY-EXISTS is true force download."
  131. (let ((curl (executable-find "curl"))
  132. (wget (executable-find "wget")))
  133. (cond (wget
  134. (if (and (not ok-if-already-exists)
  135. (file-exists-p path))
  136. nil
  137. (and (eq 0
  138. (call-process wget
  139. nil
  140. nil
  141. nil
  142. "-O"
  143. path
  144. url
  145. ))
  146. path)))
  147. (curl
  148. (if (and (not ok-if-already-exists)
  149. (file-exists-p path))
  150. nil
  151. (and (eq 0
  152. (call-process curl
  153. nil
  154. nil
  155. nil
  156. "--output"
  157. path
  158. "-L"
  159. url
  160. ))
  161. path)))
  162. (t
  163. (ignore-errors
  164. (require 'url)
  165. (url-copy-file url
  166. path
  167. ok-if-already-exists)
  168. path)))))
  169. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  170. ;; package
  171. (set (defvar 10sr-package-list)
  172. '(
  173. markdown-mode
  174. yaml-mode
  175. gnuplot-mode
  176. erlang
  177. js2-mode
  178. git-commit
  179. gitignore-mode
  180. ;; ack
  181. color-moccur
  182. ggtags
  183. flycheck
  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. scala-mode2
  196. ensime
  197. editorconfig
  198. git-command
  199. ;; 10sr repository
  200. terminal-title
  201. recentf-show
  202. dired-list-all-mode
  203. pack
  204. set-modeline-color
  205. read-only-only-mode
  206. smart-revert
  207. autosave
  208. ;;window-organizer
  209. remember-major-modes-mode
  210. ilookup
  211. pasteboard
  212. ))
  213. (when (safe-require-or-eval 'package)
  214. (setq package-archives
  215. `(,@package-archives
  216. ("melpa" . "https://melpa.org/packages/")
  217. ("10sr-el" . "https://10sr.github.io/emacs-lisp/p/")))
  218. (package-initialize)
  219. (defun my-auto-install-package ()
  220. "Install packages semi-automatically."
  221. (interactive)
  222. (package-refresh-contents)
  223. (mapc (lambda (pkg)
  224. (or (package-installed-p pkg)
  225. (locate-library (symbol-name pkg))
  226. (package-install pkg)))
  227. 10sr-package-list))
  228. )
  229. ;; (lazy-load-eval 'sudoku)
  230. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  231. ;; my-idle-hook
  232. (defvar my-idle-hook nil
  233. "Hook run when idle for several secs.")
  234. (defvar my-idle-hook-sec 5
  235. "Second to run `my-idle-hook'.")
  236. (run-with-idle-timer my-idle-hook-sec
  237. t
  238. (lambda ()
  239. (run-hooks 'my-idle-hook)))
  240. ;; (add-hook 'my-idle-hook
  241. ;; (lambda ()
  242. ;; (message "idle hook message")))
  243. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  244. ;; start and quit
  245. (setq inhibit-startup-message t)
  246. (setq confirm-kill-emacs 'y-or-n-p)
  247. (setq gc-cons-threshold (* 1024 1024 4))
  248. (when window-system
  249. (add-to-list 'default-frame-alist '(cursor-type . box))
  250. (add-to-list 'default-frame-alist '(background-color . "white"))
  251. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  252. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  253. ;; does not work?
  254. )
  255. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  256. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  257. (and (fboundp 'tool-bar-mode)
  258. (tool-bar-mode 0))
  259. (and (fboundp 'set-scroll-bar-mode)
  260. (set-scroll-bar-mode nil))
  261. (add-hook 'kill-emacs-hook
  262. ;; load init file when terminating emacs to ensure file is not broken
  263. 'reload-init-file)
  264. (defun my-force-kill-emacs ()
  265. "My force kill Emacs."
  266. (interactive)
  267. (let ((kill-emacs-hook nil))
  268. (kill-emacs)))
  269. (call-after-init
  270. (lambda ()
  271. (message "%s %s" invocation-name emacs-version)
  272. (message "%s was taken to initialize emacs." (emacs-init-time))
  273. (switch-to-buffer "*Messages*")))
  274. (cd ".") ; when using windows use / instead of \ in `default-directory'
  275. ;; locale
  276. (set-language-environment "Japanese")
  277. (set-default-coding-systems 'utf-8-unix)
  278. (prefer-coding-system 'utf-8-unix)
  279. (setq system-time-locale "C")
  280. ;; my prefix map
  281. (defvar my-prefix-map nil
  282. "My prefix map.")
  283. (define-prefix-command 'my-prefix-map)
  284. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  285. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  286. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  287. ;; (comint-show-maximum-output)
  288. ;; kill scratch
  289. (call-after-init (lambda ()
  290. (let ((buf (get-buffer "*scratch*")))
  291. (when buf
  292. (kill-buffer buf)))))
  293. ;; modifier keys
  294. ;; (setq mac-option-modifier 'control)
  295. ;; display
  296. (setq visible-bell t)
  297. (setq ring-bell-function 'ignore)
  298. (mouse-avoidance-mode 'banish)
  299. (defun reload-init-file ()
  300. "Reload Emacs init file."
  301. (interactive)
  302. (when (and user-init-file
  303. (file-readable-p user-init-file))
  304. (load-file user-init-file)))
  305. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  306. ;; global keys
  307. (global-set-key (kbd "<up>") 'scroll-down-line)
  308. (global-set-key (kbd "<down>") 'scroll-up-line)
  309. (global-set-key (kbd "<left>") 'scroll-down)
  310. (global-set-key (kbd "<right>") 'scroll-up)
  311. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  312. (global-set-key (kbd "C-\\") help-map)
  313. (define-key ctl-x-map (kbd "DEL") help-map)
  314. (define-key ctl-x-map (kbd "C-h") help-map)
  315. (define-key help-map "a" 'apropos)
  316. ;; disable annoying keys
  317. (global-set-key [prior] 'ignore)
  318. (global-set-key (kbd "<next>") 'ignore)
  319. (global-set-key [menu] 'ignore)
  320. (global-set-key [down-mouse-1] 'ignore)
  321. (global-set-key [down-mouse-2] 'ignore)
  322. (global-set-key [down-mouse-3] 'ignore)
  323. (global-set-key [mouse-1] 'ignore)
  324. (global-set-key [mouse-2] 'ignore)
  325. (global-set-key [mouse-3] 'ignore)
  326. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  327. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  328. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  329. ;; title and mode-line
  330. (when (safe-require-or-eval 'terminal-title)
  331. ;; if TERM is not screen use default value
  332. (if (getenv "TMUX")
  333. ;; if use tmux locally just basename of current dir
  334. (set-variable 'terminal-title-format
  335. '((file-name-nondirectory (directory-file-name
  336. default-directory))))
  337. (if (and (let ((tty-type (frame-parameter nil
  338. 'tty-type)))
  339. (and tty-type
  340. (equal (car (split-string tty-type
  341. "-"))
  342. "screen")))
  343. (not (getenv "SSH_CONNECTION")))
  344. (set-variable 'terminal-title-format
  345. '((file-name-nondirectory (directory-file-name
  346. default-directory))))
  347. ;; seems that TMUX is used locally and ssh to remote host
  348. (set-variable 'terminal-title-format
  349. `("em:"
  350. ,user-login-name
  351. "@"
  352. ,(car (split-string system-name
  353. "\\."))
  354. ":"
  355. default-directory))
  356. )
  357. )
  358. (terminal-title-mode))
  359. (setq eol-mnemonic-dos "\\r\\n")
  360. (setq eol-mnemonic-mac "\\r")
  361. (setq eol-mnemonic-unix "\\n")
  362. (which-function-mode 0)
  363. (line-number-mode 0)
  364. (column-number-mode 0)
  365. (size-indication-mode 0)
  366. (setq mode-line-position
  367. '(:eval (format "L%%l/%d,C%%c"
  368. (count-lines (point-max)
  369. (point-min)))))
  370. (when (safe-require-or-eval 'git-ps1-mode)
  371. (git-ps1-mode))
  372. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  373. ;; display date
  374. (when (safe-require-or-eval 'time)
  375. (setq display-time-interval 29)
  376. (setq display-time-day-and-date t)
  377. (setq display-time-format "%a, %d %b %Y %T")
  378. (if window-system
  379. (display-time-mode 0)
  380. (display-time-mode 1))
  381. (when display-time-mode
  382. (display-time-update)))
  383. ;; ;; current directory
  384. ;; (let ((ls (member 'mode-line-buffer-identification
  385. ;; mode-line-format)))
  386. ;; (setcdr ls
  387. ;; (cons '(:eval (concat " ("
  388. ;; (abbreviate-file-name default-directory)
  389. ;; ")"))
  390. ;; (cdr ls))))
  391. ;; ;; display last modified time
  392. ;; (let ((ls (member 'mode-line-buffer-identification
  393. ;; mode-line-format)))
  394. ;; (setcdr ls
  395. ;; (cons '(:eval (concat " "
  396. ;; my-buffer-file-last-modified-time))
  397. ;; (cdr ls))))
  398. (defun buffer-list-not-start-with-space ()
  399. "Return a list of buffers that not start with whitespaces."
  400. (let ((bl (buffer-list))
  401. b nbl)
  402. (while bl
  403. (setq b (pop bl))
  404. (unless (string-equal " "
  405. (substring (buffer-name b)
  406. 0
  407. 1))
  408. (add-to-list 'nbl b)))
  409. nbl))
  410. ;; http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/
  411. ;; (add-to-list 'minor-mode-alist
  412. ;; '(global-whitespace-mode ""))
  413. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  414. ;; minibuffer
  415. (setq insert-default-directory t)
  416. (setq completion-ignore-case t
  417. read-file-name-completion-ignore-case t
  418. read-buffer-completion-ignore-case t)
  419. (setq resize-mini-windows t)
  420. (temp-buffer-resize-mode 1)
  421. (savehist-mode 1)
  422. (fset 'yes-or-no-p 'y-or-n-p)
  423. ;; complete symbol when `eval'
  424. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  425. (define-key minibuffer-local-map (kbd "C-u")
  426. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  427. ;; I dont know these bindings are good
  428. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  429. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  430. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  431. ;; letters, font-lock mode and fonts
  432. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  433. ;; (set-window-margins (selected-window) 1 1)
  434. (and (or (eq system-type 'Darwin)
  435. (eq system-type 'darwin))
  436. (fboundp 'mac-set-input-method-parameter)
  437. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  438. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  439. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  440. (boundp 'input-method-inactivate-hook))
  441. (add-hook 'input-method-activate-hook
  442. (lambda () (set-cursor-color "red")))
  443. (add-hook 'input-method-inactivate-hook
  444. (lambda () (set-cursor-color "black"))))
  445. (when (safe-require-or-eval 'paren)
  446. (show-paren-mode 1)
  447. (setq show-paren-delay 0.5
  448. show-paren-style 'parenthesis) ; mixed is hard to read
  449. ;; (set-face-background 'show-paren-match
  450. ;; "black")
  451. ;; ;; (face-foreground 'default))
  452. ;; (set-face-foreground 'show-paren-match
  453. ;; "white")
  454. ;; (set-face-inverse-video-p 'show-paren-match
  455. ;; t)
  456. )
  457. (transient-mark-mode 1)
  458. (global-font-lock-mode 1)
  459. (setq font-lock-global-modes
  460. '(not
  461. help-mode
  462. eshell-mode
  463. ;;term-mode
  464. Man-mode))
  465. ;; (standard-display-ascii ?\n "$\n")
  466. ;; (defvar my-eol-face
  467. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  468. ;; )
  469. ;; (defvar my-tab-face
  470. ;; '(("\t" . '(0 highlight t nil))))
  471. (defvar my-jspace-face
  472. '(("\u3000" . '(0 highlight t nil))))
  473. (add-hook 'font-lock-mode-hook
  474. (lambda ()
  475. ;; (font-lock-add-keywords nil my-eol-face)
  476. (font-lock-add-keywords nil my-jspace-face)
  477. ))
  478. (when (safe-require-or-eval 'whitespace)
  479. (add-to-list 'whitespace-display-mappings ; not work
  480. `(tab-mark ?\t ,(vconcat "^I\t")))
  481. (add-to-list 'whitespace-display-mappings
  482. `(newline-mark ?\n ,(vconcat "$\n")))
  483. (setq whitespace-style '(face
  484. trailing ; trailing blanks
  485. newline ; newlines
  486. newline-mark ; use display table for newline
  487. ;; tab-mark
  488. empty ; empty lines at beg or end of buffer
  489. lines-tail ; lines over 80
  490. ))
  491. ;; (setq whitespace-newline 'font-lock-comment-face)
  492. (global-whitespace-mode t)
  493. (if (eq (display-color-cells)
  494. 256)
  495. (set-face-foreground 'whitespace-newline "brightblack")
  496. ;; (progn
  497. ;; (set-face-bold-p 'whitespace-newline
  498. ;; t))
  499. ))
  500. (and nil
  501. (safe-require-or-eval 'fill-column-indicator)
  502. (setq fill-column-indicator))
  503. ;; highlight current line
  504. ;; http://wiki.riywo.com/index.php?Meadow
  505. (defface 10sr-hl-line
  506. '((((min-colors 256)
  507. (background dark))
  508. (:background "color-234"))
  509. (((min-colors 256)
  510. (background light))
  511. (:background "color-234"))
  512. (t
  513. (:underline "black")))
  514. "*Face used by hl-line."
  515. :group '10sr)
  516. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  517. (set-variable 'hl-line-face '10sr-hl-line) ;; (setq hl-line-face nil)
  518. (set-variable 'hl-line-global-modes
  519. '(not
  520. term-mode))
  521. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  522. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  523. (safe-require-or-eval 'set-modeline-color)
  524. (let ((fg (face-foreground 'default))
  525. (bg (face-background 'default)))
  526. (set-face-background 'mode-line-inactive
  527. (if (face-inverse-video-p 'mode-line) fg bg))
  528. (set-face-foreground 'mode-line-inactive
  529. (if (face-inverse-video-p 'mode-line) bg fg)))
  530. (set-face-underline 'mode-line-inactive
  531. t)
  532. (set-face-underline 'vertical-border
  533. nil)
  534. ;; Not found in MELPA nor any other package repositories
  535. (and (fetch-library
  536. "https://raw.github.com/tarao/elisp/master/end-mark.el"
  537. t)
  538. (safe-require-or-eval 'end-mark)
  539. (global-end-mark-mode))
  540. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  541. ;; file handling
  542. (when (safe-require-or-eval 'editorconfig)
  543. (editorconfig-mode 1))
  544. (setq revert-without-query '(".+"))
  545. ;; save cursor position
  546. (when (safe-require-or-eval 'saveplace)
  547. (setq-default save-place t)
  548. (setq save-place-file (concat user-emacs-directory
  549. "places")))
  550. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  551. (setq make-backup-files t)
  552. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  553. (setq backup-directory-alist
  554. (cons (cons "\\.*$" (expand-file-name (concat user-emacs-directory
  555. "backup")))
  556. backup-directory-alist))
  557. (setq version-control 'never)
  558. (setq delete-old-versions t)
  559. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  560. "auto-save/")))
  561. (setq delete-auto-save-files t)
  562. (add-to-list 'completion-ignored-extensions ".bak")
  563. ;; (setq delete-by-moving-to-trash t
  564. ;; trash-directory "~/.emacs.d/trash")
  565. (add-hook 'after-save-hook
  566. 'executable-make-buffer-file-executable-if-script-p)
  567. (set (defvar bookmark-default-file)
  568. (expand-file-name (concat user-emacs-directory
  569. "bmk")))
  570. (add-hook 'recentf-load-hook
  571. (lambda ()
  572. (defvar recentf-exclude)
  573. (add-to-list 'recentf-exclude
  574. (regexp-quote bookmark-default-file))))
  575. (when (safe-require-or-eval 'smart-revert)
  576. (smart-revert-on))
  577. ;; autosave
  578. (when (safe-require-or-eval 'autosave)
  579. (autosave-set 2))
  580. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  581. ;; editting
  582. (defun my-copy-whole-line ()
  583. "Copy whole line."
  584. (interactive)
  585. (kill-new (concat (buffer-substring (point-at-bol)
  586. (point-at-eol))
  587. "\n")))
  588. (setq require-final-newline t)
  589. (setq kill-whole-line t)
  590. (setq scroll-conservatively 35
  591. scroll-margin 2
  592. scroll-step 0)
  593. (setq-default major-mode 'text-mode)
  594. (setq next-line-add-newlines nil)
  595. (setq kill-read-only-ok t)
  596. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  597. ;; (setq-default line-spacing 0.2)
  598. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  599. (setq-default tab-width 4)
  600. (setq-default indent-tabs-mode nil)
  601. (setq-default indent-line-function nil)
  602. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  603. (delete-selection-mode 1)
  604. (cua-mode 0)
  605. (setq line-move-visual nil)
  606. ;; key bindings
  607. ;; moving around
  608. ;; (global-set-key (kbd "M-j") 'next-line)
  609. ;; (global-set-key (kbd "M-k") 'previous-line)
  610. ;; (global-set-key (kbd "M-h") 'backward-char)
  611. ;; (global-set-key (kbd "M-l") 'forward-char)
  612. ;;(keyboard-translate ?\M-j ?\C-j)
  613. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  614. (define-key esc-map "p" 'backward-paragraph)
  615. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  616. (define-key esc-map "n" 'forward-paragraph)
  617. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  618. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  619. (global-set-key (kbd "C-<left>") 'scroll-down)
  620. (global-set-key (kbd "C-<right>") 'scroll-up)
  621. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  622. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  623. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  624. ;; C-h and DEL
  625. (global-set-key (kbd "C-h") (kbd "DEL"))
  626. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  627. (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  628. (define-key esc-map "k" 'my-copy-whole-line)
  629. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  630. (define-key esc-map "u" 'undo)
  631. (define-key esc-map "i" (kbd "ESC TAB"))
  632. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  633. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  634. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  635. (define-key my-prefix-map (kbd "C-o") 'occur)
  636. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  637. ;; gmail
  638. (setq mail-interactive t
  639. send-mail-function 'smtpmail-send-it)
  640. ;; message-send-mail-function 'smtpmail-send-it
  641. (set-variable 'smtpmail-smtp-server "smtp.gmail.com")
  642. (set-variable 'smtpmail-smtp-service 587)
  643. (set-variable 'smtpmail-starttls-credentials '(("smtp.gmail.com" 587
  644. "8.slashes@gmail.com" nil)))
  645. (set-variable 'smtpmail-auth-credentials '(("smtp.gmail.com" 587
  646. "8.slashes@gmail.com" nil)))
  647. (set-variable 'user-mail-address "8.slashes@gmail.com")
  648. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  649. ;; buffer killing
  650. ;; (defun my-delete-window-killing-buffer () nil)
  651. (defun my-query-kill-current-buffer ()
  652. "Interactively kill current buffer."
  653. (interactive)
  654. (if (y-or-n-p (concat "kill current buffer? :"))
  655. (kill-buffer (current-buffer))))
  656. (substitute-key-definition 'kill-buffer
  657. 'my-query-kill-current-buffer
  658. global-map)
  659. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  660. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  661. ;; share clipboard with x
  662. ;; this page describes this in details, but only these sexps seem to be needed
  663. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  664. (and (not window-system)
  665. (not (eq window-system 'mac))
  666. (getenv "DISPLAY")
  667. (not (equal (getenv "DISPLAY") ""))
  668. (executable-find "xclip")
  669. ;; (< emacs-major-version 24)
  670. (safe-require-or-eval 'xclip)
  671. nil
  672. (turn-on-xclip))
  673. (and (eq system-type 'darwin)
  674. (safe-require-or-eval 'pasteboard)
  675. (turn-on-pasteboard)
  676. (getenv "TMUX")
  677. (pasteboard-enable-rtun))
  678. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  679. ;; https://github.com/lunaryorn/flycheck
  680. (when (safe-require-or-eval 'flycheck)
  681. (call-after-init 'global-flycheck-mode))
  682. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  683. ;; server
  684. (when (safe-require-or-eval 'server)
  685. (setq server-name (concat "server"
  686. (number-to-string (emacs-pid))))
  687. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  688. ;; In Darwin environment, init fails with message like 'Service name too long'
  689. ;; when server-use-tcp is nil
  690. (when (or (eq system-type
  691. 'cygwin)
  692. (eq system-type
  693. 'darwin))
  694. (setq server-use-tcp t))
  695. (server-start))
  696. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  697. ;; some modes and hooks
  698. (set-variable 'ac-ignore-case nil)
  699. ;; (when (require 'ensime nil t)
  700. ;; (set-variable 'ensime-ac-case-sensitive t)
  701. ;; (set-variable 'ensime-company-case-sensitive t)
  702. ;; (add-hook 'scala-mode-hook
  703. ;; 'ensime-scala-mode-hook)
  704. ;; (add-hook 'ensime-scala-mode-hook
  705. ;; 'ac-stop))
  706. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  707. (define-key ctl-x-map "t" 'term-run-shell-command))
  708. (add-to-list 'safe-local-variable-values
  709. '(encoding utf-8))
  710. (setq enable-local-variables :safe)
  711. (when (safe-require-or-eval 'remember-major-modes-mode)
  712. (remember-major-modes-mode 1))
  713. ;; Detect file type from shebang and set major-mode.
  714. (add-to-list 'interpreter-mode-alist
  715. '("python3" . python-mode))
  716. (add-to-list 'interpreter-mode-alist
  717. '("python2" . python-mode))
  718. ;; http://fukuyama.co/foreign-regexp
  719. '(and (safe-require-or-eval 'foreign-regexp)
  720. (progn
  721. (setq foreign-regexp/regexp-type 'perl)
  722. '(setq reb-re-syntax 'foreign-regexp)
  723. ))
  724. (safe-require-or-eval 'session)
  725. (autoload-eval-lazily 'sql '(sql-mode)
  726. (safe-require-or-eval 'sql-indent))
  727. (when (autoload-eval-lazily 'git-command)
  728. (define-key ctl-x-map "g" 'git-command))
  729. (and (fetch-library
  730. "http://www.emacswiki.org/emacs/download/sl.el"
  731. t)
  732. (autoload-eval-lazily 'sl))
  733. (defalias 'qcalc 'quick-calc)
  734. (safe-require-or-eval 'simple)
  735. (add-hook 'makefile-mode-hook
  736. (lambda ()
  737. (local-set-key (kbd "C-m") 'newline-and-indent)
  738. ;; this functions is set in write-file-functions, i cannot find any
  739. ;; good way to remove this.
  740. (fset 'makefile-warn-suspicious-lines 'ignore)
  741. ))
  742. (add-hook 'verilog-mode-hook
  743. (lambda ()
  744. (local-set-key ";" 'self-insert-command)))
  745. (setq diff-switches "-u")
  746. (add-hook 'diff-mode-hook
  747. (lambda ()
  748. ;; (when (and (eq major-mode
  749. ;; 'diff-mode)
  750. ;; (not buffer-file-name))
  751. ;; ;; do not pass when major-mode is derived mode of diff-mode
  752. ;; (view-mode 1))
  753. (set-face-attribute 'diff-header nil
  754. :foreground nil
  755. :background nil
  756. :weight 'bold)
  757. (set-face-attribute 'diff-file-header nil
  758. :foreground nil
  759. :background nil
  760. :weight 'bold)
  761. (set-face-foreground 'diff-index-face "blue")
  762. (set-face-attribute 'diff-hunk-header nil
  763. :foreground "cyan"
  764. :weight 'normal)
  765. (set-face-attribute 'diff-context nil
  766. ;; :foreground "white"
  767. :foreground nil
  768. :weight 'normal)
  769. (set-face-foreground 'diff-removed-face "red")
  770. (set-face-foreground 'diff-added-face "green")
  771. (set-face-background 'diff-removed-face nil)
  772. (set-face-background 'diff-added-face nil)
  773. (set-face-attribute 'diff-changed nil
  774. :foreground "magenta"
  775. :weight 'normal)
  776. (set-face-attribute 'diff-refine-change nil
  777. :foreground nil
  778. :background nil
  779. :weight 'bold
  780. :inverse-video t)
  781. ;; Annoying !
  782. ;;(diff-auto-refine-mode)
  783. ))
  784. ;; (ffap-bindings)
  785. (add-hook 'sh-mode-hook
  786. (lambda ()
  787. (local-set-key
  788. (kbd "C-x C-e")
  789. 'my-execute-shell-command-current-line)))
  790. (set-variable 'sh-here-document-word "__EOC__")
  791. (defun my-execute-shell-command-current-line ()
  792. "Run current line as shell command."
  793. (interactive)
  794. (shell-command (buffer-substring-no-properties (point-at-bol)
  795. (point))))
  796. (setq auto-mode-alist
  797. `(("autostart\\'" . sh-mode)
  798. ("xinitrc\\'" . sh-mode)
  799. ("xprograms\\'" . sh-mode)
  800. ("PKGBUILD\\'" . sh-mode)
  801. ,@auto-mode-alist))
  802. (and (autoload-eval-lazily 'pkgbuild-mode)
  803. (setq auto-mode-alist (append '(("PKGBUILD\\'" . pkgbuild-mode))
  804. auto-mode-alist)))
  805. (and (autoload-eval-lazily 'groovy-mode)
  806. (add-to-list 'auto-mode-alist
  807. '("build.gradle\\'" . groovy-mode)))
  808. (add-hook 'yaml-mode-hook
  809. (lambda ()
  810. (local-set-key(kbd "C-m") 'newline)))
  811. (add-hook 'html-mode-hook
  812. (lambda ()
  813. (local-set-key(kbd "C-m") 'reindent-then-newline-and-indent)))
  814. (add-hook 'text-mode-hook
  815. (lambda ()
  816. (local-set-key (kbd "C-m") 'newline)))
  817. (add-to-list 'Info-default-directory-list
  818. (expand-file-name "~/.info/emacs-ja"))
  819. (add-hook 'apropos-mode-hook
  820. (lambda ()
  821. (local-set-key "n" 'next-line)
  822. (local-set-key "p" 'previous-line)
  823. ))
  824. (add-hook 'isearch-mode-hook
  825. (lambda ()
  826. ;; (define-key isearch-mode-map
  827. ;; (kbd "C-j") 'isearch-other-control-char)
  828. ;; (define-key isearch-mode-map
  829. ;; (kbd "C-k") 'isearch-other-control-char)
  830. ;; (define-key isearch-mode-map
  831. ;; (kbd "C-h") 'isearch-other-control-char)
  832. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  833. (define-key isearch-mode-map (kbd "M-r")
  834. 'isearch-query-replace-regexp)))
  835. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  836. (setq lazy-highlight-cleanup nil)
  837. ;; face for isearch highlighing
  838. (set-face-attribute 'lazy-highlight
  839. nil
  840. :foreground `unspecified
  841. :background `unspecified
  842. :underline t
  843. ;; :weight `bold
  844. )
  845. (add-hook 'outline-mode-hook
  846. (lambda ()
  847. (if (string-match "\\.md\\'" buffer-file-name)
  848. (set (make-local-variable 'outline-regexp) "#+ "))))
  849. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  850. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  851. (when (autoload-eval-lazily 'markdown-mode
  852. '(markdown-mode gfm-mode)
  853. (defvar gfm-mode-map)
  854. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline))
  855. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  856. (set-variable 'markdown-command (or (executable-find "markdown")
  857. (executable-find "markdown.pl")))
  858. (add-hook 'markdown-mode-hook
  859. (lambda ()
  860. (outline-minor-mode 1)
  861. (flyspell-mode)
  862. (set (make-local-variable 'comment-start) ";")))
  863. )
  864. ;; c-mode
  865. ;; http://www.emacswiki.org/emacs/IndentingC
  866. ;; http://en.wikipedia.org/wiki/Indent_style
  867. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  868. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  869. (with-eval-after-load 'cc-vars
  870. (defvar c-default-style nil)
  871. (add-to-list 'c-default-style
  872. '(c-mode . "k&r"))
  873. (add-to-list 'c-default-style
  874. '(c++-mode . "k&r"))
  875. (add-hook 'c-mode-common-hook
  876. (lambda ()
  877. ;; why c-basic-offset in k&r style defaults to 5 ???
  878. (set-variable 'c-basic-offset 4)
  879. (set-variable 'indent-tabs-mode nil)
  880. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  881. (c-toggle-hungry-state -1)
  882. ;; (and (require 'gtags nil t)
  883. ;; (gtags-mode 1))
  884. )))
  885. (when (autoload-eval-lazily 'php-mode)
  886. (add-hook 'php-mode-hook
  887. (lambda ()
  888. (set-variable 'c-basic-offset 2))))
  889. (when (autoload-eval-lazily 'js2-mode)
  890. ;; currently do not use js2-mode
  891. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  892. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  893. (add-hook 'js2-mode-hook
  894. (lambda ()
  895. (defvar js2-mode-map)
  896. (define-key js2-mode-map (kbd "C-m") (lambda ()
  897. (interactive)
  898. (js2-enter-key)
  899. (indent-for-tab-command)))
  900. ;; (add-hook (kill-local-variable 'before-save-hook)
  901. ;; 'js2-before-save)
  902. ;; (add-hook 'before-save-hook
  903. ;; 'my-indent-buffer
  904. ;; nil
  905. ;; t)
  906. )))
  907. (eval-after-load "js"
  908. (set-variable 'js-indent-level 2))
  909. (add-to-list 'interpreter-mode-alist
  910. '("node" . js-mode))
  911. (when (autoload-eval-lazily 'flymake-jslint
  912. '(flymake-jslint-load))
  913. (autoload-eval-lazily 'js nil
  914. (add-hook 'js-mode-hook
  915. 'flymake-jslint-load)))
  916. (safe-require-or-eval 'js-doc)
  917. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  918. (when (safe-require-or-eval 'uniquify)
  919. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  920. (setq uniquify-ignore-buffers-re "*[^*]+*")
  921. (setq uniquify-min-dir-content 1))
  922. (add-hook 'view-mode-hook
  923. (lambda()
  924. (defvar view-mode-map)
  925. (define-key view-mode-map "j" 'scroll-up-line)
  926. (define-key view-mode-map "k" 'scroll-down-line)
  927. (define-key view-mode-map "v" 'toggle-read-only)
  928. (define-key view-mode-map "q" 'bury-buffer)
  929. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  930. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  931. ;; (define-key view-mode-map
  932. ;; "n" 'nonincremental-repeat-search-forward)
  933. ;; (define-key view-mode-map
  934. ;; "N" 'nonincremental-repeat-search-backward)
  935. (define-key view-mode-map "/" 'isearch-forward-regexp)
  936. (define-key view-mode-map "?" 'isearch-backward-regexp)
  937. (define-key view-mode-map "n" 'isearch-repeat-forward)
  938. (define-key view-mode-map "N" 'isearch-repeat-backward)
  939. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point)
  940. ))
  941. (global-set-key "\M-r" 'view-mode)
  942. ;; (setq view-read-only t)
  943. ;; (defun my-view-mode-search-word (word)
  944. ;; "Search for word current directory and subdirectories.
  945. ;; If called intearctively, find word at point."
  946. ;; (interactive (list (thing-at-point 'symbol)))
  947. ;; (if word
  948. ;; (if (and (require 'gtags nil t)
  949. ;; (gtags-get-rootpath))
  950. ;; (gtags-goto-tag word "s")
  951. ;; (my-rgrep word))
  952. ;; (message "No word at point.")
  953. ;; nil))
  954. (add-hook 'Man-mode-hook
  955. (lambda ()
  956. (view-mode 1)
  957. (setq truncate-lines nil)))
  958. (set-variable 'Man-notify-method (if window-system
  959. 'newframe
  960. 'aggressive))
  961. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  962. "woman_cache.el")))
  963. (defalias 'man 'woman)
  964. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  965. ;; python
  966. (when (autoload-eval-lazily 'python '(python-mode))
  967. (set-variable 'python-python-command (or (executable-find "python3")
  968. (executable-find "python")))
  969. ;; (defun my-python-run-as-command ()
  970. ;; ""
  971. ;; (interactive)
  972. ;; (shell-command (concat python-python-command " " buffer-file-name)))
  973. (defun my-python-display-python-buffer ()
  974. ""
  975. (interactive)
  976. (defvar python-buffer)
  977. (set-window-text-height (display-buffer python-buffer
  978. t)
  979. 7))
  980. (add-hook 'python-mode-hook
  981. (lambda ()
  982. (local-set-key (kbd "C-c C-e") 'my-python-run-as-command)
  983. (local-set-key (kbd "C-c C-b") 'my-python-display-python-buffer)
  984. (local-set-key (kbd "C-m") 'newline-and-indent)))
  985. (add-hook 'inferior-python-mode-hook
  986. (lambda ()
  987. (my-python-display-python-buffer)
  988. (local-set-key (kbd "<up>") 'comint-previous-input)
  989. (local-set-key (kbd "<down>") 'comint-next-input))))
  990. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  991. ;; GNU GLOBAL(gtags)
  992. ;; http://uguisu.skr.jp/Windows/gtags.html
  993. ;; http://eigyr.dip.jp/gtags.html
  994. ;; http://cha.la.coocan.jp/doc/gnu_global.html
  995. (let ((d "/opt/local/share/gtags/"))
  996. (and (file-directory-p d)
  997. (add-to-list 'load-path
  998. d)))
  999. (when (autoload-eval-lazily 'gtags '(gtags-mode))
  1000. (add-hook 'gtags-mode-hook
  1001. (lambda ()
  1002. (view-mode 1)
  1003. (set-variable 'gtags-select-buffer-single t)
  1004. ;; (local-set-key "\M-t" 'gtags-find-tag)
  1005. ;; (local-set-key "\M-r" 'gtags-find-rtag)
  1006. ;; (local-set-key "\M-s" 'gtags-find-symbol)
  1007. ;; (local-set-key "\C-t" 'gtags-pop-stack)
  1008. (defvar gtags-mode-map)
  1009. (define-key gtags-mode-map (kbd "C-x t h")
  1010. 'gtags-find-tag-from-here)
  1011. (define-key gtags-mode-map (kbd "C-x t t") 'gtags-find-tag)
  1012. (define-key gtags-mode-map (kbd "C-x t r") 'gtags-find-rtag)
  1013. (define-key gtags-mode-map (kbd "C-x t s") 'gtags-find-symbol)
  1014. (define-key gtags-mode-map (kbd "C-x t p") 'gtags-find-pattern)
  1015. (define-key gtags-mode-map (kbd "C-x t f") 'gtags-find-file)
  1016. (define-key gtags-mode-map (kbd "C-x t b") 'gtags-pop-stack) ;back
  1017. ))
  1018. (add-hook 'gtags-select-mode-hook
  1019. (lambda ()
  1020. (defvar gtags-select-mode-map)
  1021. (define-key gtags-select-mode-map (kbd "C-m") 'gtags-select-tag)
  1022. ))
  1023. )
  1024. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1025. ;; term mode
  1026. ;; (setq multi-term-program shell-file-name)
  1027. (when (autoload-eval-lazily 'multi-term)
  1028. (set-variable 'multi-term-switch-after-close nil)
  1029. (set-variable 'multi-term-dedicated-select-after-open-p t)
  1030. (set-variable 'multi-term-dedicated-window-height 20))
  1031. (when (autoload-eval-lazily 'term '(term ansi-term))
  1032. (defun my-term-quit-or-send-raw ()
  1033. ""
  1034. (interactive)
  1035. (if (get-buffer-process (current-buffer))
  1036. (call-interactively 'term-send-raw)
  1037. (kill-buffer)))
  1038. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  1039. ;; (setq term-ansi-default-program shell-file-name)
  1040. (add-hook 'term-setup-hook
  1041. (lambda ()
  1042. (set-variable 'term-display-table (make-display-table))))
  1043. (add-hook 'term-mode-hook
  1044. (lambda ()
  1045. (defvar term-raw-map)
  1046. (unless (memq (current-buffer)
  1047. (and (featurep 'multi-term)
  1048. (defvar multi-term-buffer-list)
  1049. ;; current buffer is not multi-term buffer
  1050. multi-term-buffer-list))
  1051. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  1052. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  1053. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  1054. ;; (define-key term-raw-map "\C-f" 'forward-char)
  1055. ;; (define-key term-raw-map "\C-b" 'backward-char)
  1056. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  1057. (define-key term-raw-map
  1058. "\C-x" (lookup-key (current-global-map) "\C-x"))
  1059. (define-key term-raw-map
  1060. "\C-z" (lookup-key (current-global-map) "\C-z"))
  1061. )
  1062. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  1063. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  1064. (define-key term-raw-map (kbd "<up>") 'scroll-down-line)
  1065. (define-key term-raw-map (kbd "<down>") 'scroll-up-line)
  1066. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  1067. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  1068. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  1069. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  1070. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  1071. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  1072. (define-key term-raw-map [delete] 'term-send-raw)
  1073. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  1074. (define-key term-raw-map "\C-y" 'term-paste)
  1075. (define-key term-raw-map
  1076. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  1077. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  1078. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  1079. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  1080. ;; (define-key term-raw-map "\C-d" 'delete-char)
  1081. (set (make-local-variable 'scroll-margin) 0)
  1082. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  1083. ;; (cua-mode 0)
  1084. ;; (and cua-mode
  1085. ;; (local-unset-key (kbd "C-c")))
  1086. ;; (define-key cua--prefix-override-keymap
  1087. ;;"\C-c" 'term-interrupt-subjob)
  1088. (set (make-local-variable (defvar hl-line-range-function))
  1089. (lambda ()
  1090. '(0 . 0)))
  1091. ))
  1092. ;; (add-hook 'term-exec-hook 'forward-char)
  1093. )
  1094. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1095. ;; buffer switching
  1096. (defvar bs-configurations)
  1097. (when (autoload-eval-lazily 'bs '(bs-show)
  1098. ;; (add-to-list 'bs-configurations
  1099. ;; '("processes" nil get-buffer-process ".*" nil nil))
  1100. (add-to-list 'bs-configurations
  1101. '("files-and-terminals" nil nil nil
  1102. (lambda (buf)
  1103. (and (bs-visits-non-file buf)
  1104. (save-excursion
  1105. (set-buffer buf)
  1106. (not (memq major-mode
  1107. '(term-mode
  1108. eshell-mode))))))))
  1109. ;; (setq bs-configurations (list
  1110. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1111. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1112. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1113. )
  1114. ;; (global-set-key "\C-x\C-b" 'bs-show)
  1115. (defalias 'list-buffers 'bs-show)
  1116. (set-variable 'bs-default-configuration "files-and-terminals")
  1117. (set-variable 'bs-default-sort-name "by nothing")
  1118. (add-hook 'bs-mode-hook
  1119. (lambda ()
  1120. ;; (setq bs-default-configuration "files")
  1121. ;; (and bs--show-all
  1122. ;; (call-interactively 'bs-toggle-show-all))
  1123. (set (make-local-variable 'scroll-margin) 0))))
  1124. ;;(iswitchb-mode 1)
  1125. (icomplete-mode)
  1126. (defun iswitchb-buffer-display-other-window ()
  1127. "Do iswitchb in other window."
  1128. (interactive)
  1129. (let ((iswitchb-default-method 'display))
  1130. (call-interactively 'iswitchb-buffer)))
  1131. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1132. ;; sdic
  1133. (when (autoload-eval-lazily 'sdic '(sdic-describe-word-at-point))
  1134. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  1135. (defvar sdic-buffer-name)
  1136. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo)
  1137. (defun sdic-describe-word-at-point-echo ()
  1138. ""
  1139. (interactive)
  1140. (save-window-excursion
  1141. (sdic-describe-word-at-point))
  1142. (with-current-buffer sdic-buffer-name
  1143. (message (buffer-substring (point-min)
  1144. (progn (goto-char (point-min))
  1145. (or (and (re-search-forward "^\\w"
  1146. nil
  1147. t
  1148. 4)
  1149. (progn (forward-line -1) t)
  1150. (point-at-eol))
  1151. (point-max)))))))
  1152. (set-variable 'sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  1153. (set-variable ' sdic-waei-dictionary-list
  1154. '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  1155. (set-variable 'sdic-disable-select-window t)
  1156. (set-variable ' sdic-window-height 7))
  1157. ;;;;;;;;;;;;;;;;;;;;;;;;
  1158. ;; ilookup
  1159. (with-eval-after-load 'ilookup
  1160. (set-variable 'ilookup-dict-alist
  1161. '(
  1162. ("sdcv" . (lambda (word)
  1163. (shell-command-to-string
  1164. (format "sdcv -n '%s'"
  1165. word))))
  1166. ("en" . (lambda (word)
  1167. (shell-command-to-string
  1168. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  1169. word))))
  1170. ("ja" . (lambda (word)
  1171. (shell-command-to-string
  1172. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  1173. word))))
  1174. ("jaj" . (lambda (word)
  1175. (shell-command-to-string
  1176. (format "sdcv -n -u jmdict-en-ja '%s'"
  1177. word))))
  1178. ("jag" .
  1179. (lambda (word)
  1180. (with-temp-buffer
  1181. (insert (shell-command-to-string
  1182. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  1183. word)))
  1184. (html2text)
  1185. (buffer-substring (point-min)
  1186. (point-max)))))
  1187. ("alc" . (lambda (word)
  1188. (shell-command-to-string
  1189. (format "alc '%s' | head -n 20"
  1190. word))))
  1191. ("app" . (lambda (word)
  1192. (shell-command-to-string
  1193. (format "dict_app '%s'"
  1194. word))))
  1195. ;; letters broken
  1196. ("ms" .
  1197. (lambda (word)
  1198. (let ((url (concat
  1199. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  1200. "Translate?appId=%s&text=%s&to=%s"))
  1201. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  1202. (target "ja")
  1203. (eword (url-hexify-string word)))
  1204. (with-current-buffer (url-retrieve-synchronously
  1205. (format url
  1206. apikey
  1207. eword
  1208. target))
  1209. (message "")
  1210. (goto-char (point-min))
  1211. (search-forward-regexp "^$"
  1212. nil
  1213. t)
  1214. (url-unhex-string (buffer-substring-no-properties
  1215. (point)
  1216. (point-max)))))))
  1217. ))
  1218. ;; (funcall (cdr (assoc "ms"
  1219. ;; ilookup-alist))
  1220. ;; "dictionary")
  1221. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  1222. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  1223. (set-variable 'ilookup-default "ja")
  1224. (when (locate-library "google-translate")
  1225. (defvar ilookup-dict-alist)
  1226. (add-to-list 'ilookup-dict-alist
  1227. '("gt" .
  1228. (lambda (word)
  1229. (save-excursion
  1230. (google-translate-translate "auto"
  1231. "ja"
  1232. word))
  1233. (with-current-buffer "*Google Translate*"
  1234. (buffer-substring-no-properties (point-min)
  1235. (point-max)))))))
  1236. )
  1237. (when (autoload-eval-lazily 'google-translate '(google-translate-translate
  1238. google-translate-at-point))
  1239. (set-variable 'google-translate-default-source-language "auto")
  1240. (set-variable 'google-translate-default-target-language "ja"))
  1241. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1242. ;; vc
  1243. (require 'vc)
  1244. (setq vc-handled-backends '())
  1245. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1246. ;; gauche-mode
  1247. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  1248. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  1249. (when (and (fetch-library
  1250. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  1251. t)
  1252. (autoload-eval-lazily 'gauche-mode '(gauche-mode run-scheme)))
  1253. (let ((s (executable-find "gosh")))
  1254. (set-variable 'scheme-program-name s)
  1255. (set-variable 'gauche-program-name s))
  1256. (defvar gauche-program-name)
  1257. (defvar scheme-buffer)
  1258. (defun run-gauche-other-window ()
  1259. "Run gauche on other window"
  1260. (interactive)
  1261. (switch-to-buffer-other-window
  1262. (get-buffer-create "*scheme*"))
  1263. (run-gauche))
  1264. (defun run-gauche ()
  1265. "run gauche"
  1266. (interactive)
  1267. (run-scheme gauche-program-name)
  1268. )
  1269. (defun scheme-send-buffer ()
  1270. ""
  1271. (interactive)
  1272. (scheme-send-region (point-min) (point-max))
  1273. (my-scheme-display-scheme-buffer)
  1274. )
  1275. (defun my-scheme-display-scheme-buffer ()
  1276. ""
  1277. (interactive)
  1278. (set-window-text-height (display-buffer scheme-buffer
  1279. t)
  1280. 7))
  1281. (add-hook 'scheme-mode-hook
  1282. (lambda ()
  1283. nil))
  1284. (add-hook 'inferior-scheme-mode-hook
  1285. (lambda ()
  1286. ;; (my-scheme-display-scheme-buffer)
  1287. ))
  1288. (setq auto-mode-alist
  1289. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1290. (setq auto-mode-alist
  1291. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1292. (add-hook 'gauche-mode-hook
  1293. (lambda ()
  1294. (defvar gauche-mode-map)
  1295. (defvar scheme-mode-map)
  1296. (define-key gauche-mode-map
  1297. (kbd "C-c C-z") 'run-gauche-other-window)
  1298. (define-key scheme-mode-map
  1299. (kbd "C-c C-c") 'scheme-send-buffer)
  1300. (define-key scheme-mode-map
  1301. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer))))
  1302. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1303. ;; recentf-mode
  1304. (set-variable 'recentf-save-file (expand-file-name (concat user-emacs-directory
  1305. "recentf")))
  1306. (set-variable 'recentf-max-menu-items 20)
  1307. (set-variable 'recentf-max-saved-items 30)
  1308. (set-variable 'recentf-show-file-shortcuts-flag nil)
  1309. (when (safe-require-or-eval 'recentf)
  1310. (add-to-list 'recentf-exclude
  1311. (regexp-quote recentf-save-file))
  1312. (add-to-list 'recentf-exclude
  1313. (regexp-quote (expand-file-name user-emacs-directory)))
  1314. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1315. (remove-hook 'find-file-hook
  1316. 'recentf-track-opened-file)
  1317. (defun my-recentf-load-track-save-list ()
  1318. "Load current recentf list from file, track current visiting file, then save
  1319. the list."
  1320. (recentf-load-list)
  1321. (recentf-track-opened-file)
  1322. (recentf-save-list))
  1323. (add-hook 'find-file-hook
  1324. 'my-recentf-load-track-save-list)
  1325. (add-hook 'kill-emacs-hook
  1326. 'recentf-load-list)
  1327. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1328. ;; (add-hook 'find-file-hook
  1329. ;; (lambda ()
  1330. ;; (recentf-add-file default-directory)))
  1331. (and (autoload-eval-lazily 'recentf-show)
  1332. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1333. (add-hook 'recentf-show-before-listing-hook
  1334. 'recentf-load-list))
  1335. (recentf-mode 1)
  1336. (add-hook 'recentf-dialog-mode-hook
  1337. (lambda ()
  1338. ;; (recentf-save-list)
  1339. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1340. ;; 'my-recentf-cd-and-find-file)
  1341. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1342. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1343. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1344. (define-key recentf-dialog-mode-map "n" 'next-line)
  1345. (cd "~/"))))
  1346. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1347. ;; dired
  1348. (when (autoload-eval-lazily 'dired nil)
  1349. (defun my-dired-echo-file-head (arg)
  1350. ""
  1351. (interactive "P")
  1352. (let ((f (dired-get-filename)))
  1353. (message "%s"
  1354. (with-temp-buffer
  1355. (insert-file-contents f)
  1356. (buffer-substring-no-properties
  1357. (point-min)
  1358. (progn (goto-char (point-min))
  1359. (forward-line (1- (if arg
  1360. (prefix-numeric-value arg)
  1361. 7)))
  1362. (point-at-eol)))))))
  1363. (defun my-dired-diff ()
  1364. ""
  1365. (interactive)
  1366. (let ((files (dired-get-marked-files nil nil nil t)))
  1367. (if (eq (car files)
  1368. t)
  1369. (diff (cadr files) (dired-get-filename))
  1370. (message "One files must be marked!"))))
  1371. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1372. "pop up buffer using `display-buffer' and return that buffer."
  1373. (let ((bf (get-buffer-create buffer-or-name)))
  1374. (with-current-buffer bf
  1375. (cd ".")
  1376. (erase-buffer))
  1377. (display-buffer bf)
  1378. bf))
  1379. (defun my-replace-nasi-none ()
  1380. ""
  1381. (save-excursion
  1382. (let ((buffer-read-only nil))
  1383. (goto-char (point-min))
  1384. (while (search-forward "なし" nil t)
  1385. (replace-match "none")))))
  1386. (defun dired-get-file-info ()
  1387. "dired get file info"
  1388. (interactive)
  1389. (let ((f (shell-quote-argument (dired-get-filename t))))
  1390. (if (file-directory-p f)
  1391. (progn
  1392. (message "Calculating disk usage...")
  1393. (shell-command (concat "du -hsD "
  1394. f)))
  1395. (shell-command (concat "file "
  1396. f)))))
  1397. (defun my-dired-scroll-up ()
  1398. ""
  1399. (interactive)
  1400. (my-dired-previous-line (- (window-height) 1)))
  1401. (defun my-dired-scroll-down ()
  1402. ""
  1403. (interactive)
  1404. (my-dired-next-line (- (window-height) 1)))
  1405. ;; (defun my-dired-forward-line (arg)
  1406. ;; ""
  1407. ;; (interactive "p"))
  1408. (defun my-dired-previous-line (arg)
  1409. ""
  1410. (interactive "p")
  1411. (if (> arg 0)
  1412. (progn
  1413. (if (eq (line-number-at-pos)
  1414. 1)
  1415. (goto-char (point-max))
  1416. (forward-line -1))
  1417. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1418. (dired-get-subdir))
  1419. (- arg 1)
  1420. arg)))
  1421. (dired-move-to-filename)))
  1422. (defun my-dired-next-line (arg)
  1423. ""
  1424. (interactive "p")
  1425. (if (> arg 0)
  1426. (progn
  1427. (if (eq (point)
  1428. (point-max))
  1429. (goto-char (point-min))
  1430. (forward-line 1))
  1431. (my-dired-next-line (if (or (dired-get-filename nil t)
  1432. (dired-get-subdir))
  1433. (- arg 1)
  1434. arg)))
  1435. (dired-move-to-filename)))
  1436. (defun my-dired-print-current-dir-and-file ()
  1437. (message "%s %s"
  1438. default-directory
  1439. (buffer-substring-no-properties (point-at-bol)
  1440. (point-at-eol))))
  1441. (defun dired-do-execute-as-command ()
  1442. ""
  1443. (interactive)
  1444. (let ((file (dired-get-filename t)))
  1445. (if (file-executable-p file)
  1446. (start-process file nil file)
  1447. (when (y-or-n-p
  1448. "This file cant be executed. Mark as executable and go? ")
  1449. (set-file-modes file
  1450. (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1451. (start-process file nil file)))))
  1452. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1453. (defun my-dired-x-open ()
  1454. ""
  1455. (interactive)
  1456. (my-x-open (dired-get-filename t t)))
  1457. (if (eq window-system 'mac)
  1458. (setq dired-listing-switches "-lhF")
  1459. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1460. )
  1461. (setq dired-listing-switches "-lhF")
  1462. (put 'dired-find-alternate-file 'disabled nil)
  1463. ;; when using dired-find-alternate-file
  1464. ;; reuse current dired buffer for the file to open
  1465. (set-variable 'dired-ls-F-marks-symlinks t)
  1466. (when (safe-require-or-eval 'ls-lisp)
  1467. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1468. (setq ls-lisp-dirs-first t)
  1469. (setq ls-lisp-use-localized-time-format t)
  1470. (setq ls-lisp-format-time-list
  1471. '("%Y-%m-%d %H:%M"
  1472. "%Y-%m-%d ")))
  1473. (set-variable 'dired-dwim-target t)
  1474. (set-variable 'dired-isearch-filenames t)
  1475. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1476. (set-variable 'dired-hide-details-hide-information-lines nil)
  1477. ;; (add-hook 'dired-after-readin-hook
  1478. ;; 'my-replace-nasi-none)
  1479. ;; (add-hook 'after-init-hook
  1480. ;; (lambda ()
  1481. ;; (dired ".")))
  1482. (add-hook 'dired-mode-hook
  1483. (lambda ()
  1484. (local-set-key "o" 'my-dired-x-open)
  1485. (local-set-key "i" 'dired-get-file-info)
  1486. (local-set-key "f" 'find-file)
  1487. (local-set-key "!" 'shell-command)
  1488. (local-set-key "&" 'async-shell-command)
  1489. (local-set-key "X" 'dired-do-async-shell-command)
  1490. (local-set-key "=" 'my-dired-diff)
  1491. (local-set-key "B" 'gtkbm-add-current-dir)
  1492. (local-set-key "b" 'gtkbm)
  1493. (local-set-key "h" 'my-dired-echo-file-head)
  1494. (local-set-key "@" (lambda ()
  1495. (interactive) (my-x-open ".")))
  1496. (local-set-key (kbd "TAB") 'other-window)
  1497. ;; (local-set-key "P" 'my-dired-do-pack-or-unpack)
  1498. (local-set-key "/" 'dired-isearch-filenames)
  1499. (local-set-key (kbd "DEL") 'dired-up-directory)
  1500. (local-set-key (kbd "C-h") 'dired-up-directory)
  1501. (substitute-key-definition 'dired-next-line
  1502. 'my-dired-next-line
  1503. (current-local-map))
  1504. (substitute-key-definition 'dired-previous-line
  1505. 'my-dired-previous-line
  1506. (current-local-map))
  1507. ;; (local-set-key (kbd "C-p") 'my-dired-previous-line)
  1508. ;; (local-set-key (kbd "p") 'my-dired-previous-line)
  1509. ;; (local-set-key (kbd "C-n") 'my-dired-next-line)
  1510. ;; (local-set-key (kbd "n") 'my-dired-next-line)
  1511. (local-set-key (kbd "<left>") 'my-dired-scroll-up)
  1512. (local-set-key (kbd "<right>") 'my-dired-scroll-down)
  1513. (local-set-key (kbd "ESC p") 'my-dired-scroll-up)
  1514. (local-set-key (kbd "ESC n") 'my-dired-scroll-down)
  1515. (when (fboundp 'dired-hide-details-mode)
  1516. (dired-hide-details-mode t)
  1517. (local-set-key "l" 'dired-hide-details-mode))
  1518. (let ((file "._Icon\015"))
  1519. (when nil
  1520. '(file-readable-p file)
  1521. (delete-file file)))))
  1522. (and (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack-pack))
  1523. (add-hook 'dired-mode-hook
  1524. (lambda ()
  1525. (local-set-key "P" 'dired-do-pack-or-unpack))))
  1526. (and (autoload-eval-lazily 'dired-list-all-mode)
  1527. (setq dired-listing-switches "-lhF")
  1528. (add-hook 'dired-mode-hook
  1529. (lambda ()
  1530. (local-set-key "a" 'dired-list-all-mode)
  1531. )))
  1532. ) ; when dired locate
  1533. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1534. (defvar dired-marker-char)
  1535. (defun my-dired-toggle-mark()
  1536. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1537. (t dired-marker-char))))
  1538. (delete-char 1)
  1539. (insert cur)))
  1540. (defun my-dired-mark (arg)
  1541. "Toggle mark the current (or next ARG) files.
  1542. If on a subdir headerline, mark all its files except `.' and `..'.
  1543. Use \\[dired-unmark-all-files] to remove all marks
  1544. and \\[dired-unmark] on a subdir to remove the marks in
  1545. this subdir."
  1546. (interactive "P")
  1547. (if (dired-get-subdir)
  1548. (save-excursion (dired-mark-subdir-files))
  1549. (let ((inhibit-read-only t))
  1550. (dired-repeat-over-lines
  1551. (prefix-numeric-value arg)
  1552. 'my-dired-toggle-mark))))
  1553. (defun my-dired-mark-backward (arg)
  1554. "In Dired, move up lines and toggle mark there.
  1555. Optional prefix ARG says how many lines to unflag; default is one line."
  1556. (interactive "p")
  1557. (my-dired-mark (- arg)))
  1558. (add-hook 'dired-mode-hook
  1559. (lambda ()
  1560. (local-set-key (kbd "SPC") 'my-dired-mark)
  1561. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1562. )
  1563. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1564. ;; eshell
  1565. (autoload-eval-lazily 'eshell nil
  1566. (set-variable 'eshell-banner-message (format "Welcome to the Emacs shell
  1567. %s
  1568. C-x t to toggling emacs-text-mode
  1569. "
  1570. (shell-command-to-string "uname -a")
  1571. ))
  1572. (defvar eshell-text-mode-map
  1573. (let ((map (make-sparse-keymap)))
  1574. (define-key map (kbd "C-x t") 'eshell-text-mode-toggle)
  1575. map))
  1576. (define-derived-mode eshell-text-mode text-mode
  1577. "Eshell-Text"
  1578. "Text-mode for Eshell."
  1579. nil)
  1580. (defun eshell-text-mode-toggle ()
  1581. "Toggle eshell-text-mode and eshell-mode."
  1582. (interactive)
  1583. (cond ((eq major-mode
  1584. 'eshell-text-mode)
  1585. (goto-char (point-max))
  1586. (message "Eshell text mode disabled")
  1587. (eshell-mode))
  1588. ((eq major-mode
  1589. 'eshell-mode)
  1590. (message "Eshell text mode enabled")
  1591. (eshell-write-history)
  1592. (eshell-text-mode))
  1593. (t
  1594. (message "Not in eshell buffer")
  1595. nil)))
  1596. (defun my-eshell-backward-delete-char ()
  1597. (interactive)
  1598. (when (< (save-excursion
  1599. (eshell-bol)
  1600. (point))
  1601. (point))
  1602. (backward-delete-char 1)))
  1603. (defun my-file-owner-p (file)
  1604. "t if FILE is owned by me."
  1605. (eq (user-uid) (nth 2 (file-attributes file))))
  1606. "http://www.bookshelf.jp/pukiwiki/pukiwiki.php\
  1607. ?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9"
  1608. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1609. ;; (defun eshell/less (&rest args)
  1610. ;; "Invoke `view-file' on the file.
  1611. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1612. ;; (if args
  1613. ;; (while args
  1614. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1615. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1616. ;; (file (pop args)))
  1617. ;; (view-file file)
  1618. ;; (goto-line line))
  1619. ;; (view-file (pop args))))))
  1620. (defun eshell/o (&optional file)
  1621. (my-x-open (or file ".")))
  1622. ;; (defun eshell/vi (&rest args)
  1623. ;; "Invoke `find-file' on the file.
  1624. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1625. ;; (while args
  1626. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1627. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1628. ;; (file (pop args)))
  1629. ;; (find-file file)
  1630. ;; (goto-line line))
  1631. ;; (find-file (pop args)))))
  1632. (defun eshell/clear ()
  1633. "Clear the current buffer, leaving one prompt at the top."
  1634. (interactive)
  1635. (let ((inhibit-read-only t))
  1636. (erase-buffer)))
  1637. (defvar eshell-prompt-function)
  1638. (defun eshell-clear ()
  1639. (interactive)
  1640. (let ((inhibit-read-only t))
  1641. (erase-buffer)
  1642. (insert (funcall eshell-prompt-function))))
  1643. (defun eshell/d (&optional dirname switches)
  1644. "if first arg is omitted open current directory."
  1645. (dired (or dirname ".") switches))
  1646. (defun eshell/v ()
  1647. (view-mode 1))
  1648. ;; (defun eshell/aaa (&rest args)
  1649. ;; (message "%S"
  1650. ;; args))
  1651. (defalias 'eshell/: 'ignore)
  1652. (defalias 'eshell/type 'eshell/which)
  1653. ;; (defalias 'eshell/vim 'eshell/vi)
  1654. (defalias 'eshell/ff 'find-file)
  1655. (defalias 'eshell/q 'eshell/exit)
  1656. (defun eshell-goto-prompt ()
  1657. ""
  1658. (interactive)
  1659. (goto-char (point-max)))
  1660. (defun eshell-delete-char-or-logout (n)
  1661. (interactive "p")
  1662. (if (equal (eshell-get-old-input)
  1663. "")
  1664. (progn
  1665. (insert "exit")
  1666. (eshell-send-input))
  1667. (delete-char n)))
  1668. (defun eshell-kill-input ()
  1669. (interactive)
  1670. (delete-region (point)
  1671. (progn (eshell-bol)
  1672. (point))))
  1673. (defalias 'eshell/logout 'eshell/exit)
  1674. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1675. "open eshell and change wd
  1676. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1677. (interactive)
  1678. (let ((dir (expand-file-name default-directory)))
  1679. (switch-to-buffer (or eshell-buffer-or-name
  1680. (eshell t)))
  1681. (unless (equal dir (expand-file-name default-directory))
  1682. ;; (cd dir)
  1683. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1684. ;; (eshell-emit-prompt)
  1685. (goto-char (point-max))
  1686. (eshell-kill-input)
  1687. (insert "cd " dir)
  1688. (eshell-send-input))))
  1689. (defadvice eshell-next-matching-input-from-input
  1690. ;; do not cycle history
  1691. (around eshell-history-do-not-cycle activate)
  1692. (if (= 0
  1693. (or eshell-history-index
  1694. 0))
  1695. (progn
  1696. (delete-region eshell-last-output-end (point))
  1697. (insert-and-inherit eshell-matching-input-from-input-string)
  1698. (setq eshell-history-index nil))
  1699. ad-do-it))
  1700. (set-variable 'eshell-directory-name (concat user-emacs-directory
  1701. "eshell/"))
  1702. (set-variable 'eshell-term-name "eterm-color")
  1703. (set-variable 'eshell-scroll-to-bottom-on-input t)
  1704. (set-variable 'eshell-cmpl-ignore-case t)
  1705. (set-variable 'eshell-cmpl-cycle-completions nil)
  1706. (set-variable 'eshell-highlight-prompt nil)
  1707. (if (eq system-type 'darwin)
  1708. (set-variable 'eshell-ls-initial-args '("-hCFG")
  1709. (set-variable 'eshell-ls-initial-args '("-hCFG"
  1710. "--color=auto"
  1711. "--time-style=long-iso")) ; "-hF")
  1712. ))
  1713. (set (defvar eshell-prompt-function)
  1714. 'my-eshell-prompt-function)
  1715. (defvar eshell-last-command-status)
  1716. (defun my-eshell-prompt-function()
  1717. "Prompt function.
  1718. It looks like:
  1719. :: [10sr@darwin:~/][ESHELL]
  1720. :: $
  1721. "
  1722. (concat ":: ["
  1723. (let ((str (concat user-login-name
  1724. "@"
  1725. (car (split-string system-name
  1726. "\\."))
  1727. )))
  1728. (put-text-property 0
  1729. (length str)
  1730. 'face
  1731. 'underline
  1732. str)
  1733. str)
  1734. ":"
  1735. (let ((str (abbreviate-file-name default-directory)))
  1736. (put-text-property 0
  1737. (length str)
  1738. 'face
  1739. 'underline
  1740. str)
  1741. str)
  1742. "][ESHELL]\n:: "
  1743. (if (eq 0
  1744. eshell-last-command-status)
  1745. ""
  1746. (format "[STATUS:%d] "
  1747. eshell-last-command-status))
  1748. (if (= (user-uid)
  1749. 0)
  1750. "# "
  1751. "$ ")
  1752. ))
  1753. (add-hook 'eshell-mode-hook
  1754. (lambda ()
  1755. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1756. ;; (interactive)
  1757. ;; (switch-to-buffer (other-buffer))))
  1758. ;; (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1759. ;; (interactive)
  1760. ;; (eshell-goto-prompt)
  1761. ;; (keyboard-quit)))
  1762. (local-set-key (kbd "C-x t") 'eshell-text-mode-toggle)
  1763. (local-set-key (kbd "C-u") 'eshell-kill-input)
  1764. (local-set-key (kbd "C-d") 'eshell-delete-char-or-logout)
  1765. ;; (define-key eshell-mode-map (kbd "C-l")
  1766. ;; 'eshell-clear)
  1767. (local-set-key (kbd "DEL") 'my-eshell-backward-delete-char)
  1768. (local-set-key (kbd "<up>") 'scroll-down-line)
  1769. (local-set-key (kbd "<down>") 'scroll-up-line)
  1770. ;; (define-key eshell-mode-map
  1771. ;; (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1772. ;; (define-key eshell-mode-map
  1773. ;; (kbd "C-n") 'eshell-next-matching-input-from-input)
  1774. (apply 'eshell/addpath exec-path)
  1775. (set (make-local-variable 'scroll-margin) 0)
  1776. ;; (eshell/export "GIT_PAGER=")
  1777. ;; (eshell/export "GIT_EDITOR=")
  1778. (eshell/export "LC_MESSAGES=C")
  1779. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1780. (set (make-local-variable (defvar hl-line-range-function))
  1781. (lambda ()
  1782. '(0 . 0)))
  1783. (defvar eshell-virtual-targets)
  1784. (add-to-list 'eshell-virtual-targets
  1785. '("/dev/less"
  1786. (lambda (str)
  1787. (if str
  1788. (with-current-buffer nil)))
  1789. nil))
  1790. ))
  1791. (add-hook 'eshell-mode-hook
  1792. (lambda ()
  1793. (defvar eshell-visual-commands)
  1794. (defvar eshell-output-filter-functions)
  1795. (defvar eshell-command-aliases-list)
  1796. (add-to-list 'eshell-visual-commands "vim")
  1797. ;; (add-to-list 'eshell-visual-commands "git")
  1798. (add-to-list 'eshell-output-filter-functions
  1799. 'eshell-truncate-buffer)
  1800. (mapcar (lambda (alias)
  1801. (add-to-list 'eshell-command-aliases-list
  1802. alias))
  1803. '(
  1804. ;; ("ll" "ls -l $*")
  1805. ;; ("la" "ls -a $*")
  1806. ;; ("lla" "ls -al $*")
  1807. ("git" "git -c color.ui=always $*")
  1808. ("g" "git $*")
  1809. ("eless"
  1810. (concat "cat >>> (with-current-buffer "
  1811. "(get-buffer-create \"*eshell output\") "
  1812. "(erase-buffer) "
  1813. "(setq buffer-read-only nil) "
  1814. "(current-buffer)) "
  1815. "(view-buffer (get-buffer \"*eshell output*\"))"))
  1816. )
  1817. )))
  1818. ) ; eval after load eshell
  1819. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1820. ;; my-term
  1821. (defvar my-term nil
  1822. "My terminal buffer.")
  1823. (defvar my-term-function nil
  1824. "Function to create terminal buffer.
  1825. This function accept no argument and return newly created buffer of terminal.")
  1826. (defun my-term (&optional arg)
  1827. "Open terminal buffer and return that buffer.
  1828. If ARG is given or called with prefix argument, create new buffer."
  1829. (interactive "P")
  1830. (if (and (not arg)
  1831. my-term
  1832. (buffer-name my-term))
  1833. (pop-to-buffer my-term)
  1834. (setq my-term
  1835. (save-window-excursion
  1836. (funcall my-term-function)))
  1837. (and my-term
  1838. (my-term))))
  1839. ;; (setq my-term-function
  1840. ;; (lambda ()
  1841. ;; (if (eq system-type 'windows-nt)
  1842. ;; (eshell)
  1843. ;; (if (require 'multi-term nil t)
  1844. ;; (multi-term)
  1845. ;; (ansi-term shell-file-name)))))
  1846. (setq my-term-function (lambda () (eshell t)))
  1847. ;;(define-key my-prefix-map (kbd "C-s") 'my-term)
  1848. (define-key ctl-x-map "i" 'my-term)
  1849. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1850. ;; x open
  1851. (defvar my-filer nil)
  1852. (setq my-filer (or (executable-find "pcmanfm")
  1853. (executable-find "nautilus")))
  1854. (defun my-x-open (file)
  1855. "Open FILE."
  1856. (interactive "FOpen File: ")
  1857. (setq file (expand-file-name file))
  1858. (message "Opening %s..." file)
  1859. (cond ((eq system-type 'windows-nt)
  1860. (call-process "cmd.exe" nil 0 nil
  1861. "/c" "start" "" (convert-standard-filename file)))
  1862. ((eq system-type 'darwin)
  1863. (call-process "open" nil 0 nil file))
  1864. ((getenv "DISPLAY")
  1865. (call-process (or my-filer "xdg-open") nil 0 nil file))
  1866. (t
  1867. (find-file file))
  1868. )
  1869. ;; (recentf-add-file file)
  1870. (message "Opening %s...done" file))
  1871. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1872. ;; misc funcs
  1873. (defun my-git-apply-index-from-buffer (&optional buf)
  1874. "Git apply buffer. BUF is buffer to apply. nil to use current buffer."
  1875. (interactive)
  1876. (let ((buf (or buf
  1877. (current-buffer)))
  1878. (file (make-temp-file "git-apply-diff.emacs")))
  1879. (with-current-buffer buf
  1880. (write-region (point-min)
  1881. (point-max)
  1882. file)
  1883. (call-process "git"
  1884. nil
  1885. nil
  1886. nil
  1887. "apply"
  1888. "--cached"
  1889. file))))
  1890. (defun memo (&optional dir)
  1891. "Open memo.txt in DIR."
  1892. (interactive)
  1893. (pop-to-buffer (find-file-noselect (concat (if dir
  1894. (file-name-as-directory dir)
  1895. "")
  1896. "memo.txt"))))
  1897. (defvar my-rgrep-alist
  1898. `(
  1899. ;; the silver searcher
  1900. ("ag"
  1901. (executable-find "ag")
  1902. "ag --nocolor --nogroup --nopager --filename ")
  1903. ;; ack
  1904. ("ack"
  1905. (executable-find "ack")
  1906. "ack --nocolor --nogroup --nopager --with-filename ")
  1907. ;; gnu global
  1908. ("global"
  1909. (and (require 'gtags nil t)
  1910. (executable-find "global")
  1911. (gtags-get-rootpath))
  1912. "global --result grep ")
  1913. ;; git grep
  1914. ("gitgrep"
  1915. (eq 0
  1916. (shell-command "git rev-parse --git-dir"))
  1917. "git --no-pager -c color.grep=false grep -nH -e ")
  1918. ;; grep
  1919. ("grep"
  1920. t
  1921. ,(concat "find . "
  1922. "-path '*/.git' -prune -o "
  1923. "-path '*/.svn' -prune -o "
  1924. "-type f -print0 | "
  1925. "xargs -0 grep -nH -e "))
  1926. )
  1927. "Alist of rgrep command.
  1928. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1929. condition to choose COMMAND when evaluated.")
  1930. (defvar my-rgrep-default nil
  1931. "Default command name for my-rgrep.")
  1932. (defun my-rgrep-grep-command (&optional name alist)
  1933. "Return recursive grep command for current directory or nil.
  1934. If NAME is given, use that without testing.
  1935. Commands are searched from ALIST."
  1936. (if alist
  1937. (if name
  1938. ;; if name is given search that from alist and return the command
  1939. (nth 2 (assoc name
  1940. alist))
  1941. ;; if name is not given try test in 1th elem
  1942. (let ((car (car alist))
  1943. (cdr (cdr alist)))
  1944. (if (eval (nth 1 car))
  1945. ;; if the condition is true return the command
  1946. (nth 2 car)
  1947. ;; try next one
  1948. (and cdr
  1949. (my-rgrep-grep-command name cdr)))))
  1950. ;; if alist is not given set default value
  1951. (my-rgrep-grep-command name my-rgrep-alist)))
  1952. (defun my-rgrep (command-args)
  1953. "My recursive grep. Run COMMAND-ARGS."
  1954. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  1955. nil)))
  1956. (if cmd
  1957. (list (read-shell-command "grep command: "
  1958. cmd
  1959. 'grep-find-history))
  1960. (error "My-Rgrep: Command for rgrep not found")
  1961. )))
  1962. (compilation-start command-args
  1963. 'grep-mode))
  1964. ;; (defun my-rgrep-symbol-at-point (command-args)
  1965. ;; "My recursive grep. Run COMMAND-ARGS."
  1966. ;; (interactive (list (read-shell-command "grep command: "
  1967. ;; (concat (my-rgrep-grep-command)
  1968. ;; " "
  1969. ;; (thing-at-point 'symbol))
  1970. ;; 'grep-find-history)))
  1971. ;; (compilation-start command-args
  1972. ;; 'grep-mode))
  1973. (defmacro define-my-rgrep (name)
  1974. "Define rgrep for NAME."
  1975. `(defun ,(intern (concat "my-rgrep-"
  1976. name)) ()
  1977. ,(format "My recursive grep by %s."
  1978. name)
  1979. (interactive)
  1980. (let ((my-rgrep-default ,name))
  1981. (if (called-interactively-p 'any)
  1982. (call-interactively 'my-rgrep)
  1983. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1984. )
  1985. (define-my-rgrep "ack")
  1986. (define-my-rgrep "ag")
  1987. (define-my-rgrep "gitgrep")
  1988. (define-my-rgrep "grep")
  1989. (define-my-rgrep "global")
  1990. (define-key ctl-x-map "s" 'my-rgrep)
  1991. ;; (defun make ()
  1992. ;; "Run \"make -k\" in current directory."
  1993. ;; (interactive)
  1994. ;; (compile "make -k"))
  1995. (defalias 'make 'compile)
  1996. (define-key ctl-x-map "c" 'compile)
  1997. (defvar sed-in-place-history nil
  1998. "History of `sed-in-place'.")
  1999. (defvar sed-in-place-command "sed --in-place=.bak -e")
  2000. (defun sed-in-place (command)
  2001. "Issue sed in place COMMAND."
  2002. (interactive (list (read-shell-command "sed in place: "
  2003. (concat sed-in-place-command " ")
  2004. 'sed-in-place-history)))
  2005. (shell-command command
  2006. "*sed in place*"))
  2007. (defun dired-do-sed-in-place (&optional arg)
  2008. "Issue sed in place dired. If ARG is given, use the next ARG files."
  2009. (interactive "p")
  2010. (require 'dired-aux)
  2011. (let* ((files (dired-get-marked-files t arg))
  2012. (expr (dired-mark-read-string "Run sed-in-place for %s: "
  2013. nil
  2014. 'sed-in-place
  2015. arg
  2016. files)))
  2017. (if (equal expr
  2018. "")
  2019. (error "No expression specified")
  2020. (shell-command (concat sed-in-place-command
  2021. " '"
  2022. expr
  2023. "' "
  2024. (mapconcat 'shell-quote-argument
  2025. files
  2026. " "))
  2027. "*sed in place*"))))
  2028. (defun dir-show (&optional dir)
  2029. "Show DIR list."
  2030. (interactive)
  2031. (let ((bf (get-buffer-create "*dir show*"))
  2032. (list-directory-brief-switches "-C"))
  2033. (with-current-buffer bf
  2034. (list-directory (or nil
  2035. default-directory)
  2036. nil))
  2037. ))
  2038. (defun my-convmv-sjis2utf8-test ()
  2039. "Run `convmv -r -f sjis -t utf8 *'.
  2040. this is test, does not rename files."
  2041. (interactive)
  2042. (shell-command "convmv -r -f sjis -t utf8 *"))
  2043. (defun my-convmv-sjis2utf8-notest ()
  2044. "Run `convmv -r -f sjis -t utf8 * --notest'."
  2045. (interactive)
  2046. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  2047. (defun kill-ring-save-buffer-file-name ()
  2048. "Get current filename."
  2049. (interactive)
  2050. (let ((file buffer-file-name))
  2051. (if file
  2052. (progn (kill-new file)
  2053. (message file))
  2054. (message "not visiting file."))))
  2055. (defvar kill-ring-buffer-name "*kill-ring*"
  2056. "Buffer name for `kill-ring-buffer'.")
  2057. (defun open-kill-ring-buffer ()
  2058. "Open kill- ring buffer."
  2059. (interactive)
  2060. (pop-to-buffer
  2061. (with-current-buffer (get-buffer-create kill-ring-buffer-name)
  2062. (erase-buffer)
  2063. (yank)
  2064. (text-mode)
  2065. (current-local-map)
  2066. (goto-char (point-min))
  2067. (yank)
  2068. (current-buffer))))
  2069. (defun set-terminal-header (string)
  2070. "Set terminal header STRING."
  2071. (let ((savepos "\033[s")
  2072. (restorepos "\033[u")
  2073. (movecursor "\033[0;%dH")
  2074. (inverse "\033[7m")
  2075. (restorecolor "\033[0m")
  2076. (cols (frame-parameter nil 'width))
  2077. (length (length string)))
  2078. ;; (redraw-frame (selected-frame))
  2079. (send-string-to-terminal (concat savepos
  2080. (format movecursor
  2081. (1+ (- cols length)))
  2082. inverse
  2083. string
  2084. restorecolor
  2085. restorepos))
  2086. ))
  2087. (defun my-set-terminal-header ()
  2088. "Set terminal header."
  2089. (set-terminal-header (concat " "
  2090. user-login-name
  2091. "@"
  2092. (car (split-string system-name
  2093. "\\."))
  2094. " "
  2095. (format-time-string "%Y/%m/%d %T %z")
  2096. " ")))
  2097. ;; (run-with-timer
  2098. ;; 0.1
  2099. ;; 1
  2100. ;; 'my-set-terminal-header)
  2101. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2102. ;; ;; savage emacs
  2103. ;; ;; when enabled emacs fails to complete
  2104. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  2105. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  2106. ;; (setq arg
  2107. ;; (concat arg
  2108. ;; (if (eq nil
  2109. ;; (string-match "\\. *$"
  2110. ;; arg))
  2111. ;; ".")
  2112. ;; " Stupid!")))
  2113. ;; TODO: make these a library
  2114. (defvar info-in-prompt
  2115. nil
  2116. "System info in the form of \"[user@host] \".")
  2117. (setq info-in-prompt
  2118. (concat "["
  2119. user-login-name
  2120. "@"
  2121. (car (split-string system-name
  2122. "\\."))
  2123. "]"))
  2124. (defun my-real-function-subr-p (function)
  2125. "Return t if FUNCTION is a built-in function even if it is advised."
  2126. (let* ((advised (and (symbolp function)
  2127. (featurep 'advice)
  2128. (ad-get-advice-info function)))
  2129. (real-function
  2130. (or (and advised (let ((origname (cdr (assq 'origname advised))))
  2131. (and (fboundp origname)
  2132. origname)))
  2133. function))
  2134. (def (if (symbolp real-function)
  2135. (symbol-function real-function)
  2136. function)))
  2137. (subrp def)))
  2138. ;; (my-real-function-subr-p 'my-real-function-subr-p)
  2139. ;; (defadvice read-from-minibuffer (before info-in-prompt activate)
  2140. ;; "Show system info when use `read-from-minibuffer'."
  2141. ;; (ad-set-arg 0
  2142. ;; (concat my-system-info
  2143. ;; (ad-get-arg 0))))
  2144. ;; (defadvice read-string (before info-in-prompt activate)
  2145. ;; "Show system info when use `read-string'."
  2146. ;; (ad-set-arg 0
  2147. ;; (concat my-system-info
  2148. ;; (ad-get-arg 0))))
  2149. ;; (when (< emacs-major-version 24)
  2150. ;; (defadvice completing-read (before info-in-prompt activate)
  2151. ;; "Show system info when use `completing-read'."
  2152. ;; (ad-set-arg 0
  2153. ;; (concat my-system-info
  2154. ;; (ad-get-arg 0)))))
  2155. (defmacro info-in-prompt-set (&rest functions)
  2156. "Set info-in-prompt advices for FUNCTIONS."
  2157. `(progn
  2158. ,@(mapcar (lambda (f)
  2159. `(defadvice ,f (before info-in-prompt activate)
  2160. "Show info in prompt."
  2161. (let ((orig (ad-get-arg 0)))
  2162. (unless (string-match-p (regexp-quote info-in-prompt)
  2163. orig)
  2164. (ad-set-arg 0
  2165. (concat info-in-prompt
  2166. " "
  2167. orig))))))
  2168. functions)))
  2169. (info-in-prompt-set read-from-minibuffer
  2170. read-string
  2171. completing-read)
  2172. ;;; emacs.el ends here