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.
 
 
 
 
 
 

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