Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

2535 linhas
87 KiB

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