Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

2477 righe
85 KiB

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