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.
 
 
 
 
 
 

2496 lines
85 KiB

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