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.
 
 
 
 
 
 

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