您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

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