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.
 
 
 
 
 
 

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