You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

2532 rivejä
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. ;; some modes and hooks
  763. (and (fetch-library
  764. "https://raw.github.com/10sr/emacs-lisp/master/remember-major-modes-mode.el"
  765. t)
  766. (require 'remember-major-modes-mode nil t)
  767. (remember-major-modes-mode 1)
  768. )
  769. ;; Detect file type from shebang and set major-mode.
  770. (add-to-list 'interpreter-mode-alist
  771. '("python3" . python-mode))
  772. (add-to-list 'interpreter-mode-alist
  773. '("python2" . python-mode))
  774. ;; http://fukuyama.co/foreign-regexp
  775. '(and (fetch-library
  776. "https://raw.github.com/k-talo/foreign-regexp.el/master/foreign-regexp.el"
  777. t)
  778. (require 'foreign-regexp nil t)
  779. (progn
  780. (setq foreign-regexp/regexp-type 'perl)
  781. '(setq reb-re-syntax 'foreign-regexp)
  782. ))
  783. (require 'session nil t)
  784. (lazy-load-eval 'sql '(sql-mode)
  785. (require 'sql-indent nil t))
  786. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/gtkbm.el"
  787. t)
  788. (lazy-load-eval 'gtkbm)
  789. (global-set-key (kbd "C-x C-d") 'gtkbm))
  790. (and (fetch-library
  791. "https://raw.github.com/10sr/emacs-lisp/master/git-command.el"
  792. t)
  793. (lazy-load-eval 'git-command
  794. nil
  795. (add-to-list 'git-command-major-mode-alist
  796. '("di" . diff-mode))
  797. (add-to-list 'git-command-major-mode-alist
  798. '("graph" . fundamental-mode))
  799. (add-to-list 'git-command-major-mode-alist
  800. '("log" . fundamental-mode))
  801. (when (boundp 'git-command-view-command-list)
  802. (setq git-command-view-command-list
  803. `("log" "graph" ,@git-command-view-command-list))
  804. )
  805. (or git-command-prompt-file
  806. (setq git-command-prompt-file
  807. (git-command-find-git-ps1
  808. "/usr/share/git-core/contrib/completion/git-prompt.sh"))))
  809. ;; (setq git-command-default-options "-c color.ui=always")
  810. (define-key ctl-x-map "g" 'git-command))
  811. (and (fetch-library
  812. "http://www.emacswiki.org/emacs/download/sl.el"
  813. t)
  814. (lazy-load-eval 'sl))
  815. (defalias 'qcalc 'quick-calc)
  816. (require 'simple nil t)
  817. (add-hook 'makefile-mode-hook
  818. (lambda ()
  819. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  820. ;; this functions is set in write-file-functions, i cannot find any
  821. ;; good way to remove this.
  822. (fset 'makefile-warn-suspicious-lines 'ignore)
  823. ))
  824. (add-hook 'verilog-mode-hook
  825. (lambda ()
  826. (define-key verilog-mode-map ";" 'self-insert-command)))
  827. (setq diff-switches "-u")
  828. (add-hook 'diff-mode-hook
  829. (lambda ()
  830. (when (and (eq major-mode
  831. 'diff-mode)
  832. (not buffer-file-name))
  833. ;; do not pass when major-mode is derived mode of diff-mode
  834. (view-mode 1))
  835. (set-face-attribute 'diff-header nil
  836. :foreground nil
  837. :background nil
  838. :weight 'bold)
  839. (set-face-attribute 'diff-file-header nil
  840. :foreground nil
  841. :background nil
  842. :weight 'bold)
  843. (set-face-foreground 'diff-index-face "blue")
  844. (set-face-attribute 'diff-hunk-header nil
  845. :foreground "cyan"
  846. :weight 'normal)
  847. (set-face-attribute 'diff-context nil
  848. ;; :foreground "white"
  849. :foreground nil
  850. :weight 'normal)
  851. (set-face-foreground 'diff-removed-face "red")
  852. (set-face-foreground 'diff-added-face "green")
  853. (set-face-background 'diff-removed-face nil)
  854. (set-face-background 'diff-added-face nil)
  855. (set-face-attribute 'diff-changed nil
  856. :foreground "magenta"
  857. :weight 'normal)
  858. ))
  859. ;; (ffap-bindings)
  860. (add-hook 'sh-mode-hook
  861. (lambda ()
  862. (define-key sh-mode-map
  863. (kbd "C-x C-e")
  864. 'my-execute-shell-command-current-line)))
  865. (setq sh-here-document-word "__EOC__")
  866. (defun my-execute-shell-command-current-line ()
  867. "Run current line as shell command."
  868. (interactive)
  869. (shell-command (buffer-substring-no-properties (point-at-bol)
  870. (point))))
  871. (setq auto-mode-alist
  872. `(("autostart\\'" . sh-mode)
  873. ("xinitrc\\'" . sh-mode)
  874. ("xprograms\\'" . sh-mode)
  875. ("PKGBUILD\\'" . sh-mode)
  876. ,@auto-mode-alist))
  877. (and (lazy-load-eval 'pkgbuild-mode)
  878. (setq auto-mode-alist (append '(("PKGBUILD\\'" . pkgbuild-mode))
  879. auto-mode-alist)))
  880. (add-hook 'yaml-mode-hook
  881. (lambda ()
  882. (define-key yaml-mode-map (kbd "C-m")
  883. 'newline)))
  884. (add-hook 'html-mode-hook
  885. (lambda ()
  886. (define-key html-mode-map (kbd "C-m")
  887. 'reindent-then-newline-and-indent)))
  888. (add-hook 'text-mode-hook
  889. (lambda ()
  890. (define-key text-mode-map (kbd "C-m") 'newline)))
  891. (add-to-list 'Info-default-directory-list
  892. (expand-file-name "~/.info/emacs-ja"))
  893. (add-hook 'apropos-mode-hook
  894. (lambda ()
  895. (define-key apropos-mode-map "n" 'next-line)
  896. (define-key apropos-mode-map "p" 'previous-line)
  897. ))
  898. (add-hook 'isearch-mode-hook
  899. (lambda ()
  900. ;; (define-key isearch-mode-map
  901. ;; (kbd "C-j") 'isearch-other-control-char)
  902. ;; (define-key isearch-mode-map
  903. ;; (kbd "C-k") 'isearch-other-control-char)
  904. ;; (define-key isearch-mode-map
  905. ;; (kbd "C-h") 'isearch-other-control-char)
  906. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  907. (define-key isearch-mode-map (kbd "M-r")
  908. 'isearch-query-replace-regexp)))
  909. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  910. (setq lazy-highlight-cleanup nil)
  911. ;; face for isearch highlighing
  912. (set-face-attribute 'lazy-highlight
  913. nil
  914. :foreground `unspecified
  915. :background `unspecified
  916. :underline t
  917. ;; :weight `bold
  918. )
  919. (add-hook 'outline-mode-hook
  920. (lambda ()
  921. (if (string-match "\\.md\\'" buffer-file-name)
  922. (set (make-local-variable 'outline-regexp) "#+ "))))
  923. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  924. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  925. (when (fetch-library
  926. "http://jblevins.org/projects/markdown-mode/markdown-mode.el"
  927. t)
  928. (lazy-load-eval 'markdown-mode)
  929. (setq markdown-command (or (executable-find "markdown")
  930. (executable-find "markdown.pl")))
  931. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'markdown-mode))
  932. (add-hook 'markdown-mode-hook
  933. (lambda ()
  934. (outline-minor-mode 1)
  935. (flyspell-mode)
  936. (set (make-local-variable 'comment-start) ";"))))
  937. ;; c-mode
  938. ;; http://www.emacswiki.org/emacs/IndentingC
  939. ;; http://en.wikipedia.org/wiki/Indent_style
  940. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  941. (when (lazy-load-eval 'cc-vars
  942. nil
  943. (add-to-list 'c-default-style
  944. '(c-mode . "k&r"))
  945. (add-to-list 'c-default-style
  946. '(c++-mode . "k&r"))
  947. (add-hook 'c-mode-common-hook
  948. (lambda ()
  949. ;; why c-basic-offset in k&r style defaults to 5 ???
  950. (setq c-basic-offset 4
  951. indent-tabs-mode nil)
  952. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  953. (c-toggle-hungry-state -1)
  954. ;; (and (require 'gtags nil t)
  955. ;; (gtags-mode 1))
  956. ))))
  957. (when (fetch-library
  958. "https://raw.github.com/mooz/js2-mode/master/js2-mode.el"
  959. t)
  960. (lazy-load-eval 'js2-mode)
  961. ;; currently do not use js2-mode
  962. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  963. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  964. (add-hook 'js2-mode-hook
  965. (lambda ()
  966. (define-key js2-mode-map (kbd "C-m") (lambda ()
  967. (interactive)
  968. (js2-enter-key)
  969. (indent-for-tab-command)))
  970. ;; (add-hook (kill-local-variable 'before-save-hook)
  971. ;; 'js2-before-save)
  972. ;; (add-hook 'before-save-hook
  973. ;; 'my-indent-buffer
  974. ;; nil
  975. ;; t)
  976. )))
  977. (eval-after-load "js"
  978. (setq js-indent-level 2))
  979. (add-to-list 'interpreter-mode-alist
  980. '("node" . js-mode))
  981. (when (lazy-load-eval 'flymake-jslint
  982. '(flymake-jslint-load))
  983. (lazy-load-eval 'js nil
  984. (add-hook 'js-mode-hook
  985. 'flymake-jslint-load)))
  986. (require 'js-doc nil t)
  987. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  988. (when (require 'uniquify nil t)
  989. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  990. (setq uniquify-ignore-buffers-re "*[^*]+*")
  991. (setq uniquify-min-dir-content 1))
  992. (add-hook 'view-mode-hook
  993. (lambda()
  994. (define-key view-mode-map "j" 'scroll-up-line)
  995. (define-key view-mode-map "k" 'scroll-down-line)
  996. (define-key view-mode-map "v" 'toggle-read-only)
  997. (define-key view-mode-map "q" 'bury-buffer)
  998. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  999. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  1000. ;; (define-key view-mode-map
  1001. ;; "n" 'nonincremental-repeat-search-forward)
  1002. ;; (define-key view-mode-map
  1003. ;; "N" 'nonincremental-repeat-search-backward)
  1004. (define-key view-mode-map "/" 'isearch-forward-regexp)
  1005. (define-key view-mode-map "?" 'isearch-backward-regexp)
  1006. (define-key view-mode-map "n" 'isearch-repeat-forward)
  1007. (define-key view-mode-map "N" 'isearch-repeat-backward)
  1008. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point)
  1009. ))
  1010. (global-set-key "\M-r" 'view-mode)
  1011. ;; (setq view-read-only t)
  1012. ;; (defun my-view-mode-search-word (word)
  1013. ;; "Search for word current directory and subdirectories.
  1014. ;; If called intearctively, find word at point."
  1015. ;; (interactive (list (thing-at-point 'symbol)))
  1016. ;; (if word
  1017. ;; (if (and (require 'gtags nil t)
  1018. ;; (gtags-get-rootpath))
  1019. ;; (gtags-goto-tag word "s")
  1020. ;; (my-rgrep word))
  1021. ;; (message "No word at point.")
  1022. ;; nil))
  1023. (add-hook 'Man-mode-hook
  1024. (lambda ()
  1025. (view-mode 1)
  1026. (setq truncate-lines nil)))
  1027. (setq Man-notify-method (if window-system
  1028. 'newframe
  1029. 'aggressive))
  1030. (setq woman-cache-filename (expand-file-name (concat user-emacs-directory
  1031. "woman_cache.el")))
  1032. (defalias 'man 'woman)
  1033. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1034. ;; python
  1035. (when (lazy-load-eval 'python '(python-mode))
  1036. (setq python-python-command (or (executable-find "python3")
  1037. (executable-find "python")))
  1038. ;; (defun my-python-run-as-command ()
  1039. ;; ""
  1040. ;; (interactive)
  1041. ;; (shell-command (concat python-python-command " " buffer-file-name)))
  1042. (defun my-python-display-python-buffer ()
  1043. ""
  1044. (interactive)
  1045. (set-window-text-height (display-buffer python-buffer
  1046. t)
  1047. 7))
  1048. (add-hook 'python-mode-hook
  1049. (lambda ()
  1050. (define-key python-mode-map
  1051. (kbd "C-c C-e") 'my-python-run-as-command)
  1052. (define-key python-mode-map
  1053. (kbd "C-c C-b") 'my-python-display-python-buffer)
  1054. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)))
  1055. (add-hook 'inferior-python-mode-hook
  1056. (lambda ()
  1057. (my-python-display-python-buffer)
  1058. (define-key inferior-python-mode-map
  1059. (kbd "<up>") 'comint-previous-input)
  1060. (define-key inferior-python-mode-map
  1061. (kbd "<down>") 'comint-next-input))))
  1062. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1063. ;; GNU GLOBAL(gtags)
  1064. ;; http://uguisu.skr.jp/Windows/gtags.html
  1065. ;; http://eigyr.dip.jp/gtags.html
  1066. ;; http://cha.la.coocan.jp/doc/gnu_global.html
  1067. (let ((d "/opt/local/share/gtags/"))
  1068. (and (file-directory-p d)
  1069. (add-to-list 'load-path
  1070. d)))
  1071. (when (lazy-load-eval 'gtags '(gtags-mode))
  1072. (add-hook 'gtags-mode-hook
  1073. (lambda ()
  1074. (view-mode gtags-mode)
  1075. (setq gtags-select-buffer-single t)
  1076. ;; (local-set-key "\M-t" 'gtags-find-tag)
  1077. ;; (local-set-key "\M-r" 'gtags-find-rtag)
  1078. ;; (local-set-key "\M-s" 'gtags-find-symbol)
  1079. ;; (local-set-key "\C-t" 'gtags-pop-stack)
  1080. (define-key gtags-mode-map (kbd "C-x t h")
  1081. 'gtags-find-tag-from-here)
  1082. (define-key gtags-mode-map (kbd "C-x t t") 'gtags-find-tag)
  1083. (define-key gtags-mode-map (kbd "C-x t r") 'gtags-find-rtag)
  1084. (define-key gtags-mode-map (kbd "C-x t s") 'gtags-find-symbol)
  1085. (define-key gtags-mode-map (kbd "C-x t p") 'gtags-find-pattern)
  1086. (define-key gtags-mode-map (kbd "C-x t f") 'gtags-find-file)
  1087. (define-key gtags-mode-map (kbd "C-x t b") 'gtags-pop-stack) ;back
  1088. ))
  1089. (add-hook 'gtags-select-mode-hook
  1090. (lambda ()
  1091. (define-key gtags-select-mode-map (kbd "C-m") 'gtags-select-tag)
  1092. ))
  1093. )
  1094. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1095. ;; term mode
  1096. ;; (setq multi-term-program shell-file-name)
  1097. (and (fetch-library "http://www.emacswiki.org/emacs/download/multi-term.el"
  1098. t)
  1099. (lazy-load-eval 'multi-term)
  1100. (progn
  1101. (setq multi-term-switch-after-close nil)
  1102. (setq multi-term-dedicated-select-after-open-p t)
  1103. (setq multi-term-dedicated-window-height 20)))
  1104. (when (lazy-load-eval 'term '(term ansi-term))
  1105. (defun my-term-quit-or-send-raw ()
  1106. ""
  1107. (interactive)
  1108. (if (get-buffer-process (current-buffer))
  1109. (call-interactively 'term-send-raw)
  1110. (kill-buffer)))
  1111. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  1112. ;; (setq term-ansi-default-program shell-file-name)
  1113. (add-hook 'term-setup-hook
  1114. (lambda ()
  1115. (setq term-display-table (make-display-table))))
  1116. (add-hook 'term-mode-hook
  1117. (lambda ()
  1118. (unless (memq (current-buffer)
  1119. (and (featurep 'multi-term)
  1120. ;; current buffer is not multi-term buffer
  1121. (multi-term-list)))
  1122. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  1123. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  1124. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  1125. ;; (define-key term-raw-map "\C-f" 'forward-char)
  1126. ;; (define-key term-raw-map "\C-b" 'backward-char)
  1127. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  1128. (define-key term-raw-map
  1129. "\C-x" (lookup-key (current-global-map) "\C-x"))
  1130. (define-key term-raw-map
  1131. "\C-z" (lookup-key (current-global-map) "\C-z"))
  1132. )
  1133. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  1134. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  1135. (define-key term-raw-map (kbd "<up>") 'scroll-down-line)
  1136. (define-key term-raw-map (kbd "<down>") 'scroll-up-line)
  1137. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  1138. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  1139. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  1140. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  1141. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  1142. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  1143. (define-key term-raw-map [delete] 'term-send-raw)
  1144. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  1145. (define-key term-raw-map "\C-y" 'term-paste)
  1146. (define-key term-raw-map
  1147. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  1148. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  1149. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  1150. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  1151. ;; (define-key term-raw-map "\C-d" 'delete-char)
  1152. (set (make-local-variable 'scroll-margin) 0)
  1153. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  1154. ;; (cua-mode 0)
  1155. ;; (and cua-mode
  1156. ;; (local-unset-key (kbd "C-c")))
  1157. ;; (define-key cua--prefix-override-keymap
  1158. ;;"\C-c" 'term-interrupt-subjob)
  1159. (set (make-local-variable 'hl-line-range-function)
  1160. (lambda ()
  1161. '(0 . 0)))
  1162. ))
  1163. ;; (add-hook 'term-exec-hook 'forward-char)
  1164. )
  1165. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1166. ;; buffer switching
  1167. (when (lazy-load-eval 'bs '(bs-show)
  1168. ;; (add-to-list 'bs-configurations
  1169. ;; '("processes" nil get-buffer-process ".*" nil nil))
  1170. (add-to-list 'bs-configurations
  1171. '("files-and-terminals" nil nil nil
  1172. (lambda (buf)
  1173. (and (bs-visits-non-file buf)
  1174. (save-excursion
  1175. (set-buffer buf)
  1176. (not (memq major-mode
  1177. '(term-mode
  1178. eshell-mode))))))))
  1179. ;; (setq bs-configurations (list
  1180. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1181. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1182. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1183. )
  1184. ;; (global-set-key "\C-x\C-b" 'bs-show)
  1185. (defalias 'list-buffers 'bs-show)
  1186. (setq bs-default-configuration "files-and-terminals")
  1187. (setq bs-default-sort-name "by nothing")
  1188. (add-hook 'bs-mode-hook
  1189. (lambda ()
  1190. ;; (setq bs-default-configuration "files")
  1191. ;; (and bs--show-all
  1192. ;; (call-interactively 'bs-toggle-show-all))
  1193. (set (make-local-variable 'scroll-margin) 0))))
  1194. (iswitchb-mode 1)
  1195. (defun iswitchb-buffer-display-other-window ()
  1196. "Do iswitchb in other window."
  1197. (interactive)
  1198. (let ((iswitchb-default-method 'display))
  1199. (call-interactively 'iswitchb-buffer)))
  1200. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1201. ;; sdic
  1202. (when (lazy-load-eval 'sdic '(sdic-describe-word-at-point))
  1203. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  1204. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo)
  1205. (defun sdic-describe-word-at-point-echo ()
  1206. ""
  1207. (interactive)
  1208. (save-window-excursion
  1209. (sdic-describe-word-at-point))
  1210. (save-excursion
  1211. (set-buffer sdic-buffer-name)
  1212. (message (buffer-substring (point-min)
  1213. (progn (goto-char (point-min))
  1214. (or (and (re-search-forward "^\\w"
  1215. nil
  1216. t
  1217. 4)
  1218. (progn (previous-line) t)
  1219. (point-at-eol))
  1220. (point-max)))))))
  1221. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  1222. (setq sdic-waei-dictionary-list
  1223. '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  1224. (setq sdic-disable-select-window t)
  1225. (setq sdic-window-height 7))
  1226. ;;;;;;;;;;;;;;;;;;;;;;;;
  1227. ;; ilookup
  1228. (when (fetch-library
  1229. "https://raw.github.com/10sr/emacs-lisp/master/ilookup.el"
  1230. t)
  1231. (lazy-load-eval 'ilookup
  1232. '(ilookup-open)
  1233. (setq ilookup-dict-alist
  1234. '(
  1235. ("en" . (lambda (word)
  1236. (shell-command-to-string
  1237. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  1238. word))))
  1239. ("ja" . (lambda (word)
  1240. (shell-command-to-string
  1241. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  1242. word))))
  1243. ("jaj" . (lambda (word)
  1244. (shell-command-to-string
  1245. (format "sdcv -n -u jmdict-en-ja '%s'"
  1246. word))))
  1247. ("jag" .
  1248. (lambda (word)
  1249. (with-temp-buffer
  1250. (insert (shell-command-to-string
  1251. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  1252. word)))
  1253. (html2text)
  1254. (buffer-substring (point-min)
  1255. (point-max)))))
  1256. ("alc" . (lambda (word)
  1257. (shell-command-to-string
  1258. (format "alc '%s' | head -n 20"
  1259. word))))
  1260. ("app" . (lambda (word)
  1261. (shell-command-to-string
  1262. (format "dict_app '%s'"
  1263. word))))
  1264. ;; letters broken
  1265. ("ms" .
  1266. (lambda (word)
  1267. (let ((url (concat
  1268. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  1269. "Translate?appId=%s&text=%s&to=%s"))
  1270. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  1271. (target "ja")
  1272. (eword (url-hexify-string word)))
  1273. (with-current-buffer (url-retrieve-synchronously
  1274. (format url
  1275. apikey
  1276. eword
  1277. target))
  1278. (message "")
  1279. (goto-char (point-min))
  1280. (search-forward-regexp "^$"
  1281. nil
  1282. t)
  1283. (url-unhex-string (buffer-substring-no-properties
  1284. (point)
  1285. (point-max)))))))
  1286. ))
  1287. ;; (funcall (cdr (assoc "ms"
  1288. ;; ilookup-alist))
  1289. ;; "dictionary")
  1290. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  1291. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  1292. (setq ilookup-default "ja")
  1293. (when (locate-library "google-translate")
  1294. (add-to-list 'ilookup-dict-alist
  1295. '("gt" .
  1296. (lambda (word)
  1297. (save-excursion
  1298. (google-translate-translate "auto"
  1299. "ja"
  1300. word))
  1301. (with-current-buffer "*Google Translate*"
  1302. (buffer-substring-no-properties (point-min)
  1303. (point-max)))))))
  1304. ))
  1305. (when (lazy-load-eval 'google-translate '(google-translate-translate
  1306. google-translate-at-point))
  1307. (setq google-translate-default-source-language "auto")
  1308. (setq google-translate-default-target-language "ja"))
  1309. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1310. ;; vc
  1311. ;; (require 'vc)
  1312. (setq vc-handled-backends '())
  1313. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1314. ;; gauche-mode
  1315. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  1316. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  1317. (when (and (fetch-library
  1318. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  1319. t)
  1320. (lazy-load-eval 'gauche-mode '(gauche-mode run-scheme)))
  1321. (let ((s (executable-find "gosh")))
  1322. (setq scheme-program-name s
  1323. gauche-program-name s))
  1324. (defun run-gauche-other-window ()
  1325. "Run gauche on other window"
  1326. (interactive)
  1327. (switch-to-buffer-other-window
  1328. (get-buffer-create "*scheme*"))
  1329. (run-gauche))
  1330. (defun run-gauche ()
  1331. "run gauche"
  1332. (run-scheme gauche-program-name)
  1333. )
  1334. (defun scheme-send-buffer ()
  1335. ""
  1336. (interactive)
  1337. (scheme-send-region (point-min) (point-max))
  1338. (my-scheme-display-scheme-buffer)
  1339. )
  1340. (defun my-scheme-display-scheme-buffer ()
  1341. ""
  1342. (interactive)
  1343. (set-window-text-height (display-buffer scheme-buffer
  1344. t)
  1345. 7))
  1346. (add-hook 'scheme-mode-hook
  1347. (lambda ()
  1348. nil))
  1349. (add-hook 'inferior-scheme-mode-hook
  1350. (lambda ()
  1351. ;; (my-scheme-display-scheme-buffer)
  1352. ))
  1353. (setq auto-mode-alist
  1354. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1355. (setq auto-mode-alist
  1356. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1357. (add-hook 'gauche-mode-hook
  1358. (lambda ()
  1359. (define-key gauche-mode-map
  1360. (kbd "C-c C-z") 'run-gauche-other-window)
  1361. (define-key scheme-mode-map
  1362. (kbd "C-c C-c") 'scheme-send-buffer)
  1363. (define-key scheme-mode-map
  1364. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer))))
  1365. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1366. ;; recentf-mode
  1367. (setq recentf-save-file (expand-file-name "~/.emacs.d/recentf")
  1368. recentf-max-menu-items 20
  1369. recentf-max-saved-items 30
  1370. recentf-show-file-shortcuts-flag nil)
  1371. (when (require 'recentf nil t)
  1372. (add-to-list 'recentf-exclude
  1373. (regexp-quote recentf-save-file))
  1374. (add-to-list 'recentf-exclude
  1375. (regexp-quote (expand-file-name user-emacs-directory)))
  1376. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1377. (add-hook 'find-file-hook
  1378. 'recentf-save-list
  1379. t) ; save to file immediately after adding file to recentf list
  1380. (add-hook 'kill-emacs-hook
  1381. 'recentf-load-list)
  1382. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1383. ;; (add-hook 'find-file-hook
  1384. ;; (lambda ()
  1385. ;; (recentf-add-file default-directory)))
  1386. (and (fetch-library
  1387. "https://raw.github.com/10sr/emacs-lisp/master/recentf-show.el"
  1388. t)
  1389. (lazy-load-eval 'recentf-show)
  1390. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1391. (add-hook 'recentf-show-before-listing-hook
  1392. 'recentf-load-list))
  1393. (recentf-mode 1)
  1394. (add-hook 'recentf-dialog-mode-hook
  1395. (lambda ()
  1396. ;; (recentf-save-list)
  1397. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1398. ;; 'my-recentf-cd-and-find-file)
  1399. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1400. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1401. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1402. (define-key recentf-dialog-mode-map "n" 'next-line)
  1403. (cd "~/"))))
  1404. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1405. ;; dired
  1406. (when (lazy-load-eval 'dired nil)
  1407. (defun my-dired-echo-file-head (arg)
  1408. ""
  1409. (interactive "P")
  1410. (let ((f (dired-get-filename)))
  1411. (message "%s"
  1412. (with-temp-buffer
  1413. (insert-file-contents f)
  1414. (buffer-substring-no-properties
  1415. (point-min)
  1416. (progn (goto-line (if arg
  1417. (prefix-numeric-value arg)
  1418. 10))
  1419. (point-at-eol)))))))
  1420. (defun my-dired-diff ()
  1421. ""
  1422. (interactive)
  1423. (let ((files (dired-get-marked-files nil nil nil t)))
  1424. (if (eq (car files)
  1425. t)
  1426. (diff (cadr files) (dired-get-filename))
  1427. (message "One files must be marked!"))))
  1428. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1429. "pop up buffer using `display-buffer' and return that buffer."
  1430. (let ((bf (get-buffer-create buffer-or-name)))
  1431. (with-current-buffer bf
  1432. (cd ".")
  1433. (erase-buffer))
  1434. (display-buffer bf)
  1435. bf))
  1436. (defun my-replace-nasi-none ()
  1437. ""
  1438. (save-excursion
  1439. (let ((buffer-read-only nil))
  1440. (goto-char (point-min))
  1441. (while (search-forward "なし" nil t)
  1442. (replace-match "none")))))
  1443. (defun dired-get-file-info ()
  1444. "dired get file info"
  1445. (interactive)
  1446. (let ((f (shell-quote-argument (dired-get-filename t))))
  1447. (if (file-directory-p f)
  1448. (progn
  1449. (message "Calculating disk usage...")
  1450. (shell-command (concat "du -hsD "
  1451. f)))
  1452. (shell-command (concat "file "
  1453. f)))))
  1454. (defun my-dired-scroll-up ()
  1455. ""
  1456. (interactive)
  1457. (my-dired-previous-line (- (window-height) 1)))
  1458. (defun my-dired-scroll-down ()
  1459. ""
  1460. (interactive)
  1461. (my-dired-next-line (- (window-height) 1)))
  1462. ;; (defun my-dired-forward-line (arg)
  1463. ;; ""
  1464. ;; (interactive "p"))
  1465. (defun my-dired-previous-line (arg)
  1466. ""
  1467. (interactive "p")
  1468. (if (> arg 0)
  1469. (progn
  1470. (if (eq (line-number-at-pos)
  1471. 1)
  1472. (goto-char (point-max))
  1473. (forward-line -1))
  1474. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1475. (dired-get-subdir))
  1476. (- arg 1)
  1477. arg)))
  1478. (dired-move-to-filename)))
  1479. (defun my-dired-next-line (arg)
  1480. ""
  1481. (interactive "p")
  1482. (if (> arg 0)
  1483. (progn
  1484. (if (eq (point)
  1485. (point-max))
  1486. (goto-char (point-min))
  1487. (forward-line 1))
  1488. (my-dired-next-line (if (or (dired-get-filename nil t)
  1489. (dired-get-subdir))
  1490. (- arg 1)
  1491. arg)))
  1492. (dired-move-to-filename)))
  1493. (defun my-dired-print-current-dir-and-file ()
  1494. (message "%s %s"
  1495. default-directory
  1496. (buffer-substring-no-properties (point-at-bol)
  1497. (point-at-eol))))
  1498. (defun dired-do-execute-as-command ()
  1499. ""
  1500. (interactive)
  1501. (let ((file (dired-get-filename t)))
  1502. (if (file-executable-p file)
  1503. (start-process file nil file)
  1504. (when (y-or-n-p
  1505. "this file cant be executed. mark as executable and go? : ")
  1506. (set-file-modes file
  1507. (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1508. (start-process file nil file)))))
  1509. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1510. (defun my-dired-x-open ()
  1511. ""
  1512. (interactive)
  1513. (my-x-open (dired-get-filename t t)))
  1514. (if (eq window-system 'mac)
  1515. (setq dired-listing-switches "-lhF")
  1516. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1517. )
  1518. (setq dired-listing-switches "-lhF")
  1519. (put 'dired-find-alternate-file 'disabled nil)
  1520. ;; when using dired-find-alternate-file
  1521. ;; reuse current dired buffer for the file to open
  1522. (setq dired-ls-F-marks-symlinks t)
  1523. (when (require 'ls-lisp nil t)
  1524. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1525. (setq ls-lisp-dirs-first t)
  1526. (setq ls-lisp-use-localized-time-format t)
  1527. (setq ls-lisp-format-time-list
  1528. '("%Y-%m-%d %H:%M"
  1529. "%Y-%m-%d ")))
  1530. (setq dired-dwim-target t)
  1531. ;; (add-hook 'dired-after-readin-hook
  1532. ;; 'my-replace-nasi-none)
  1533. ;; (add-hook 'after-init-hook
  1534. ;; (lambda ()
  1535. ;; (dired ".")))
  1536. (add-hook 'dired-mode-hook
  1537. (lambda ()
  1538. (define-key dired-mode-map "o" 'my-dired-x-open)
  1539. (define-key dired-mode-map "i" 'dired-get-file-info)
  1540. (define-key dired-mode-map "f" 'find-file)
  1541. (define-key dired-mode-map "!" 'shell-command)
  1542. (define-key dired-mode-map "&" 'async-shell-command)
  1543. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1544. (define-key dired-mode-map "=" 'my-dired-diff)
  1545. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1546. (define-key dired-mode-map "b" 'gtkbm)
  1547. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1548. (define-key dired-mode-map "@" (lambda ()
  1549. (interactive) (my-x-open ".")))
  1550. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1551. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1552. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1553. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1554. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1555. (substitute-key-definition 'dired-next-line
  1556. 'my-dired-next-line dired-mode-map)
  1557. (substitute-key-definition 'dired-previous-line
  1558. 'my-dired-previous-line dired-mode-map)
  1559. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  1560. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  1561. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  1562. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  1563. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1564. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1565. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1566. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1567. (let ((file "._Icon\015"))
  1568. (when nil (file-readable-p file)
  1569. (delete-file file)))))
  1570. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/pack.el"
  1571. t)
  1572. (lazy-load-eval 'pack '(dired-do-pack-or-unpack pack))
  1573. (add-hook 'dired-mode-hook
  1574. (lambda ()
  1575. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack))))
  1576. (and (fetch-library
  1577. "https://raw.github.com/10sr/emacs-lisp/master/dired-list-all-mode.el"
  1578. t)
  1579. (lazy-load-eval 'dired-list-all-mode)
  1580. (setq dired-listing-switches "-lhF")
  1581. (add-hook 'dired-mode-hook
  1582. (lambda ()
  1583. (define-key dired-mode-map "a" 'dired-list-all-mode)
  1584. )))
  1585. ) ; when dired locate
  1586. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1587. (defun my-dired-toggle-mark()
  1588. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1589. (t dired-marker-char))))
  1590. (delete-char 1)
  1591. (insert cur)))
  1592. (defun my-dired-mark (arg)
  1593. "Toggle mark the current (or next ARG) files.
  1594. If on a subdir headerline, mark all its files except `.' and `..'.
  1595. Use \\[dired-unmark-all-files] to remove all marks
  1596. and \\[dired-unmark] on a subdir to remove the marks in
  1597. this subdir."
  1598. (interactive "P")
  1599. (if (dired-get-subdir)
  1600. (save-excursion (dired-mark-subdir-files))
  1601. (let ((inhibit-read-only t))
  1602. (dired-repeat-over-lines
  1603. (prefix-numeric-value arg)
  1604. 'my-dired-toggle-mark))))
  1605. (defun my-dired-mark-backward (arg)
  1606. "In Dired, move up lines and toggle mark there.
  1607. Optional prefix ARG says how many lines to unflag; default is one line."
  1608. (interactive "p")
  1609. (my-dired-mark (- arg)))
  1610. (add-hook 'dired-mode-hook
  1611. (lambda ()
  1612. (local-set-key (kbd "SPC") 'my-dired-mark)
  1613. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1614. )
  1615. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1616. ;; eshell
  1617. (lazy-load-eval 'eshell nil
  1618. (defvar eshell-text-mode-map
  1619. (let ((map (make-sparse-keymap)))
  1620. (define-key map (kbd "C-x t") 'eshell-text-mode-toggle)
  1621. map))
  1622. (define-derived-mode eshell-text-mode text-mode
  1623. "Eshell-Text"
  1624. "Text-mode for Eshell."
  1625. nil)
  1626. (defun eshell-text-mode-toggle ()
  1627. "Toggle eshell-text-mode and eshell-mode."
  1628. (interactive)
  1629. (cond ((eq major-mode
  1630. 'eshell-text-mode)
  1631. (goto-char (point-max))
  1632. (eshell-mode))
  1633. ((eq major-mode
  1634. 'eshell-mode)
  1635. (eshell-text-mode))
  1636. (t
  1637. (message "Not in eshell buffer")
  1638. nil)))
  1639. (defun my-eshell-backward-delete-char ()
  1640. (interactive)
  1641. (when (< (save-excursion
  1642. (eshell-bol)
  1643. (point))
  1644. (point))
  1645. (backward-delete-char 1)))
  1646. (defun my-file-owner-p (file)
  1647. "t if FILE is owned by me."
  1648. (eq (user-uid) (nth 2 (file-attributes file))))
  1649. "http://www.bookshelf.jp/pukiwiki/pukiwiki.php\
  1650. ?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9"
  1651. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1652. ;; (defun eshell/less (&rest args)
  1653. ;; "Invoke `view-file' on the file.
  1654. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1655. ;; (if args
  1656. ;; (while args
  1657. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1658. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1659. ;; (file (pop args)))
  1660. ;; (view-file file)
  1661. ;; (goto-line line))
  1662. ;; (view-file (pop args))))))
  1663. (defun eshell/o (&optional file)
  1664. (my-x-open (or file ".")))
  1665. ;; (defun eshell/vi (&rest args)
  1666. ;; "Invoke `find-file' on the file.
  1667. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1668. ;; (while args
  1669. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1670. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1671. ;; (file (pop args)))
  1672. ;; (find-file file)
  1673. ;; (goto-line line))
  1674. ;; (find-file (pop args)))))
  1675. (defun eshell/clear ()
  1676. "Clear the current buffer, leaving one prompt at the top."
  1677. (interactive)
  1678. (let ((inhibit-read-only t))
  1679. (erase-buffer)))
  1680. (defun eshell-clear ()
  1681. (interactive)
  1682. (let ((inhibit-read-only t))
  1683. (erase-buffer)
  1684. (insert (funcall eshell-prompt-function))))
  1685. (defun eshell/d (&optional dirname switches)
  1686. "if first arg is omitted open current directory."
  1687. (dired (or dirname ".") switches))
  1688. (defun eshell/v ()
  1689. (view-mode 1))
  1690. ;; (defun eshell/aaa (&rest args)
  1691. ;; (message "%S"
  1692. ;; args))
  1693. (defvar eshell/git-cat-command
  1694. nil
  1695. "List of git commands that cat just return strings as results.")
  1696. (setq eshell/git-cat-command
  1697. '("status" "st" "b" "branch" "ls" "ls-files")
  1698. )
  1699. (defun eshell/git (&rest args)
  1700. (if (member (car args)
  1701. eshell/git-cat-command)
  1702. (shell-command-to-string (mapconcat 'shell-quote-argument
  1703. `("git"
  1704. "-c"
  1705. "color.ui=always"
  1706. ,@args)
  1707. " "))
  1708. ;; (eshell-git-shell-command-to-string args)
  1709. (if (require 'git-command nil t)
  1710. (git-command (mapconcat 'shell-quote-argument
  1711. args
  1712. " "))
  1713. (apply 'eshell-exec-visual "git" args))))
  1714. ;; (defun eshell-git-shell-command-to-string (args)
  1715. ;; "Return string of output of ARGS."
  1716. ;; (let ((sargs (mapconcat 'shell-quote-argument
  1717. ;; args
  1718. ;; " ")))
  1719. ;; (if (require 'ansi-color nil t)
  1720. ;; (identity
  1721. ;; (shell-command-to-string (concat "git "
  1722. ;; "-c color.ui=always "
  1723. ;; sargs)))
  1724. ;; (shell-command-to-string (concat "git "
  1725. ;; sargs)))))
  1726. (defalias 'eshell/g 'eshell/git)
  1727. (defalias 'eshell/: 'ignore)
  1728. (defalias 'eshell/type 'eshell/which)
  1729. ;; (defalias 'eshell/vim 'eshell/vi)
  1730. (defalias 'eshell/ff 'find-file)
  1731. (defalias 'eshell/q 'eshell/exit)
  1732. (defun eshell-goto-prompt ()
  1733. ""
  1734. (interactive)
  1735. (goto-char (point-max)))
  1736. (defun eshell-delete-char-or-logout (n)
  1737. (interactive "p")
  1738. (if (equal (eshell-get-old-input)
  1739. "")
  1740. (progn
  1741. (insert "exit")
  1742. (eshell-send-input))
  1743. (delete-char n)))
  1744. (defun eshell-kill-input ()
  1745. (interactive)
  1746. (delete-region (point)
  1747. (progn (eshell-bol)
  1748. (point))))
  1749. (defalias 'eshell/logout 'eshell/exit)
  1750. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1751. "open eshell and change wd
  1752. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1753. (interactive)
  1754. (let ((dir (expand-file-name default-directory)))
  1755. (switch-to-buffer (or eshell-buffer-or-name
  1756. (eshell t)))
  1757. (unless (equal dir (expand-file-name default-directory))
  1758. ;; (cd dir)
  1759. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1760. ;; (eshell-emit-prompt)
  1761. (goto-char (point-max))
  1762. (eshell-kill-input)
  1763. (insert "cd " dir)
  1764. (eshell-send-input))))
  1765. (defadvice eshell-next-matching-input-from-input
  1766. ;; do not cycle history
  1767. (around eshell-history-do-not-cycle activate)
  1768. (if (= 0
  1769. (or eshell-history-index
  1770. 0))
  1771. (progn
  1772. (delete-region eshell-last-output-end (point))
  1773. (insert-and-inherit eshell-matching-input-from-input-string)
  1774. (setq eshell-history-index nil))
  1775. ad-do-it))
  1776. (setq eshell-directory-name "~/.emacs.d/eshell/")
  1777. (setq eshell-term-name "eterm-color")
  1778. (setq eshell-scroll-to-bottom-on-input t)
  1779. (setq eshell-cmpl-ignore-case t)
  1780. (setq eshell-cmpl-cycle-completions nil)
  1781. (setq eshell-highlight-prompt nil)
  1782. (setq eshell-ls-initial-args '("-hCFG"
  1783. "--color=auto"
  1784. "--time-style=long-iso")) ; "-hF")
  1785. (setq eshell-prompt-function
  1786. 'my-eshell-prompt-function)
  1787. (defun my-eshell-prompt-function ()
  1788. (with-temp-buffer
  1789. (let (p1 p2 p3 p4)
  1790. (insert ":: [")
  1791. (setq p1 (point))
  1792. (insert user-login-name
  1793. "@"
  1794. (car (split-string system-name
  1795. "\\."))
  1796. )
  1797. (setq p2 (point))
  1798. (insert ":")
  1799. (setq p3 (point))
  1800. (insert (abbreviate-file-name default-directory))
  1801. (setq p4 (point))
  1802. (insert "]")
  1803. (insert "\n:: ")
  1804. (unless (eq 0
  1805. eshell-last-command-status)
  1806. (insert (format "[STATUS:%d] "
  1807. eshell-last-command-status)))
  1808. (insert (if (= (user-uid)
  1809. 0)
  1810. "# "
  1811. "$ "))
  1812. (add-text-properties p1
  1813. p2
  1814. '(face underline))
  1815. (add-text-properties p3
  1816. p4
  1817. '(face underline))
  1818. (buffer-substring (point-min)
  1819. (point-max)))))
  1820. (add-hook 'eshell-mode-hook
  1821. (lambda ()
  1822. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1823. ;; (interactive)
  1824. ;; (switch-to-buffer (other-buffer))))
  1825. ;; (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1826. ;; (interactive)
  1827. ;; (eshell-goto-prompt)
  1828. ;; (keyboard-quit)))
  1829. (define-key eshell-mode-map (kbd "C-x t")
  1830. 'eshell-text-mode-toggle)
  1831. (define-key eshell-mode-map (kbd "C-u")
  1832. 'eshell-kill-input)
  1833. (define-key eshell-mode-map (kbd "C-d")
  1834. 'eshell-delete-char-or-logout)
  1835. ;; (define-key eshell-mode-map (kbd "C-l")
  1836. ;; 'eshell-clear)
  1837. (define-key eshell-mode-map (kbd "DEL")
  1838. 'my-eshell-backward-delete-char)
  1839. (define-key eshell-mode-map
  1840. (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1841. (define-key eshell-mode-map
  1842. (kbd "C-n") 'eshell-next-matching-input-from-input)
  1843. (apply 'eshell/addpath exec-path)
  1844. (set (make-local-variable 'scroll-margin) 0)
  1845. ;; (eshell/export "GIT_PAGER=")
  1846. ;; (eshell/export "GIT_EDITOR=")
  1847. (eshell/export "LC_MESSAGES=C")
  1848. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1849. (set (make-local-variable 'hl-line-range-function)
  1850. (lambda ()
  1851. '(0 . 0)))
  1852. (add-to-list 'eshell-virtual-targets
  1853. '("/dev/less"
  1854. (lambda (str)
  1855. (if str
  1856. (with-current-buffer nil)))
  1857. nil))
  1858. ))
  1859. (add-hook 'eshell-mode-hook
  1860. (lambda ()
  1861. (add-to-list 'eshell-visual-commands "vim")
  1862. ;; (add-to-list 'eshell-visual-commands "git")
  1863. (add-to-list 'eshell-output-filter-functions
  1864. 'eshell-truncate-buffer)
  1865. (mapcar (lambda (alias)
  1866. (add-to-list 'eshell-command-aliases-list
  1867. alias))
  1868. '(
  1869. ; ("ll" "ls -l $*")
  1870. ; ("la" "ls -a $*")
  1871. ; ("lla" "ls -al $*")
  1872. ("eless"
  1873. (concat "cat >>> (with-current-buffer "
  1874. "(get-buffer-create \"*eshell output\") "
  1875. "(erase-buffer) "
  1876. "(setq buffer-read-only nil) "
  1877. "(current-buffer)) "
  1878. "(view-buffer (get-buffer \"*eshell output*\"))")
  1879. ))
  1880. )))
  1881. ) ; eval after load eshell
  1882. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1883. ;; my-term
  1884. (defvar my-term nil
  1885. "My terminal buffer.")
  1886. (defvar my-term-function nil
  1887. "Function to create terminal buffer.
  1888. This function accept no argument and return newly created buffer of terminal.")
  1889. (defun my-term (&optional arg)
  1890. "Open terminal buffer and return that buffer.
  1891. ARG is ignored."
  1892. (interactive "P")
  1893. (if (and my-term
  1894. (buffer-name my-term))
  1895. (pop-to-buffer my-term)
  1896. (setq my-term
  1897. (save-window-excursion
  1898. (funcall my-term-function)))
  1899. (and my-term
  1900. (my-term))))
  1901. ;; (setq my-term-function
  1902. ;; (lambda ()
  1903. ;; (if (eq system-type 'windows-nt)
  1904. ;; (eshell)
  1905. ;; (if (require 'multi-term nil t)
  1906. ;; (multi-term)
  1907. ;; (ansi-term shell-file-name)))))
  1908. (setq my-term-function 'eshell)
  1909. (define-key my-prefix-map (kbd "C-s") 'my-term)
  1910. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1911. ;; x open
  1912. (defvar my-filer nil)
  1913. (setq my-filer (or (executable-find "pcmanfm")
  1914. (executable-find "nautilus")))
  1915. (defun my-x-open (file)
  1916. "open FILE."
  1917. (interactive "FOpen File: ")
  1918. (setq file (expand-file-name file))
  1919. (message "Opening %s..." file)
  1920. (cond ((eq system-type 'windows-nt)
  1921. (call-process "cmd.exe" nil 0 nil
  1922. "/c" "start" "" (convert-standard-filename file)))
  1923. ((eq system-type 'darwin)
  1924. (call-process "open" nil 0 nil file))
  1925. ((getenv "DISPLAY")
  1926. (call-process (or my-filer "xdg-open") nil 0 nil file))
  1927. (t
  1928. (find-file file))
  1929. )
  1930. ;; (recentf-add-file file)
  1931. (message "Opening %s...done" file))
  1932. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1933. ;; misc funcs
  1934. (defun memo (&optional dir)
  1935. "Open memo.txt in DIR."
  1936. (interactive)
  1937. (pop-to-buffer (find-file-noselect (concat (if dir
  1938. (file-name-as-directory dir)
  1939. "")
  1940. "memo.txt"))))
  1941. (defvar my-rgrep-alist
  1942. `(
  1943. ;; the silver searcher
  1944. ("ag"
  1945. (executable-find "ag")
  1946. "ag --nocolor --nogroup --nopager ")
  1947. ;; ack
  1948. ("ack"
  1949. (executable-find "ack")
  1950. "ack --nocolor --nogroup --nopager --with-filename ")
  1951. ;; gnu global
  1952. ("global"
  1953. (and (require 'gtags nil t)
  1954. (executable-find "global")
  1955. (gtags-get-rootpath))
  1956. "global --result grep ")
  1957. ;; git grep
  1958. ("gitgrep"
  1959. (eq 0
  1960. (shell-command "git rev-parse --git-dir"))
  1961. "git --no-pager -c color.grep=false grep -nH -e ")
  1962. ;; grep
  1963. ("grep"
  1964. t
  1965. ,(concat "find . "
  1966. "-path '*/.git' -prune -o "
  1967. "-path '*/.svn' -prune -o "
  1968. "-type f -print0 | "
  1969. "xargs -0 grep -nH -e "))
  1970. )
  1971. "Alist of rgrep command.
  1972. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1973. condition to choose COMMAND when evaluated.")
  1974. (defvar my-rgrep-default nil
  1975. "Default command name for my-rgrep.")
  1976. (defun my-rgrep-grep-command (&optional name alist)
  1977. "Return recursive grep command for current directory or nil.
  1978. If NAME is given, use that without testing.
  1979. Commands are searched from ALIST."
  1980. (if alist
  1981. (if name
  1982. ;; if name is given search that from alist and return the command
  1983. (nth 2 (assoc name
  1984. alist))
  1985. ;; if name is not given try test in 1th elem
  1986. (let ((car (car alist))
  1987. (cdr (cdr alist)))
  1988. (if (eval (nth 1 car))
  1989. ;; if the condition is true return the command
  1990. (nth 2 car)
  1991. ;; try next one
  1992. (and cdr
  1993. (my-rgrep-grep-command name cdr)))))
  1994. ;; if alist is not given set default value
  1995. (my-rgrep-grep-command name my-rgrep-alist)))
  1996. (my-rgrep-grep-command "ag" nil)
  1997. (defun my-rgrep (command-args)
  1998. "My recursive grep. Run COMMAND-ARGS."
  1999. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  2000. nil)))
  2001. (if cmd
  2002. (list (read-shell-command "grep command: "
  2003. cmd
  2004. 'grep-find-history))
  2005. (error "my-rgrep: Command for rgrep not found")
  2006. )))
  2007. (compilation-start command-args
  2008. 'grep-mode))
  2009. ;; (defun my-rgrep-symbol-at-point (command-args)
  2010. ;; "My recursive grep. Run COMMAND-ARGS."
  2011. ;; (interactive (list (read-shell-command "grep command: "
  2012. ;; (concat (my-rgrep-grep-command)
  2013. ;; " "
  2014. ;; (thing-at-point 'symbol))
  2015. ;; 'grep-find-history)))
  2016. ;; (compilation-start command-args
  2017. ;; 'grep-mode))
  2018. (defmacro define-my-rgrep (name)
  2019. "Define rgrep for NAME."
  2020. `(defun ,(intern (concat "my-rgrep-"
  2021. name)) ()
  2022. ,(format "My recursive grep by %s."
  2023. name)
  2024. (interactive)
  2025. (let ((my-rgrep-default ,name))
  2026. (if (called-interactively-p 'any)
  2027. (call-interactively 'my-rgrep)
  2028. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2029. )
  2030. (define-my-rgrep "ack")
  2031. (define-my-rgrep "ag")
  2032. (define-my-rgrep "gitgrep")
  2033. (define-my-rgrep "grep")
  2034. (define-my-rgrep "global")
  2035. (define-key ctl-x-map "s" 'my-rgrep)
  2036. ;; (defun make ()
  2037. ;; "Run \"make -k\" in current directory."
  2038. ;; (interactive)
  2039. ;; (compile "make -k"))
  2040. (defalias 'make 'compile)
  2041. (defvar sed-in-place-history nil
  2042. "History of `sed-in-place'.")
  2043. (defvar sed-in-place-command "sed --in-place=.bak -e")
  2044. (defun sed-in-place (command)
  2045. "Issue sed in place COMMAND."
  2046. (interactive (list (read-shell-command "sed in place: "
  2047. (concat sed-in-place-command " ")
  2048. 'sed-in-place-history)))
  2049. (shell-command command
  2050. "*sed in place*"))
  2051. (defun dired-do-sed-in-place (&optional arg)
  2052. "Issue sed in place dired. If ARG is given, use the next ARG files."
  2053. (interactive "p")
  2054. (require 'dired-aux)
  2055. (let* ((files (dired-get-marked-files t arg))
  2056. (expr (dired-mark-read-string "Run sed-in-place for %s: "
  2057. nil
  2058. 'sed-in-place
  2059. arg
  2060. files)))
  2061. (if (equal expr
  2062. "")
  2063. (error "No expression specified")
  2064. (shell-command (concat sed-in-place-command
  2065. " '"
  2066. expr
  2067. "' "
  2068. (mapconcat 'shell-quote-argument
  2069. files
  2070. " "))
  2071. "*sed in place*"))))
  2072. (defun dir-show (&optional dir)
  2073. "Show DIR list."
  2074. (interactive)
  2075. (let ((bf (get-buffer-create "*dir show*"))
  2076. (list-directory-brief-switches "-C"))
  2077. (with-current-buffer bf
  2078. (list-directory (or nil
  2079. default-directory)
  2080. nil))
  2081. ))
  2082. (defun my-convmv-sjis2utf8-test ()
  2083. "Run `convmv -r -f sjis -t utf8 *'.
  2084. this is test, does not rename files."
  2085. (interactive)
  2086. (shell-command "convmv -r -f sjis -t utf8 *"))
  2087. (defun my-convmv-sjis2utf8-notest ()
  2088. "Run `convmv -r -f sjis -t utf8 * --notest'."
  2089. (interactive)
  2090. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  2091. (defun kill-ring-save-buffer-file-name ()
  2092. "Get current filename."
  2093. (interactive)
  2094. (let ((file buffer-file-name))
  2095. (if file
  2096. (progn (kill-new file)
  2097. (message file))
  2098. (message "not visiting file."))))
  2099. (defvar kill-ring-buffer-name "*kill-ring*"
  2100. "Buffer name for `kill-ring-buffer'.")
  2101. (defun open-kill-ring-buffer ()
  2102. "Open kill- ring buffer."
  2103. (interactive)
  2104. (pop-to-buffer
  2105. (with-current-buffer (get-buffer-create kill-ring-buffer-name)
  2106. (erase-buffer)
  2107. (yank)
  2108. (text-mode)
  2109. (current-local-map)
  2110. (goto-char (point-min))
  2111. (yank)
  2112. (current-buffer))))
  2113. (defun set-terminal-header (string)
  2114. "Set terminal header STRING."
  2115. (let ((savepos "\033[s")
  2116. (restorepos "\033[u")
  2117. (movecursor "\033[0;%dH")
  2118. (inverse "\033[7m")
  2119. (restorecolor "\033[0m")
  2120. (cols (frame-parameter nil 'width))
  2121. (length (length string)))
  2122. ;; (redraw-frame (selected-frame))
  2123. (send-string-to-terminal (concat savepos
  2124. (format movecursor
  2125. (1+ (- cols length)))
  2126. inverse
  2127. string
  2128. restorecolor
  2129. restorepos))
  2130. ))
  2131. (defun my-set-terminal-header ()
  2132. "Set terminal header."
  2133. (set-terminal-header (concat " "
  2134. user-login-name
  2135. "@"
  2136. (car (split-string system-name
  2137. "\\."))
  2138. " "
  2139. (format-time-string "%Y/%m/%d %T %z")
  2140. " ")))
  2141. ;; (run-with-timer
  2142. ;; 0.1
  2143. ;; 1
  2144. ;; 'my-set-terminal-header)
  2145. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2146. ;; ;; savage emacs
  2147. ;; ;; when enabled emacs fails to complete
  2148. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  2149. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  2150. ;; (setq arg
  2151. ;; (concat arg
  2152. ;; (if (eq nil
  2153. ;; (string-match "\\. *$"
  2154. ;; arg))
  2155. ;; ".")
  2156. ;; " Stupid!")))
  2157. (defvar info-in-prompt
  2158. nil
  2159. "System info in the form of \"[user@host] \".")
  2160. (setq info-in-prompt
  2161. (concat "["
  2162. user-login-name
  2163. "@"
  2164. (car (split-string system-name
  2165. "\\."))
  2166. "]"))
  2167. (defun my-real-function-subr-p (function)
  2168. "Return t if FUNCTION is a built-in function even if it is advised."
  2169. (let* ((advised (and (symbolp function)
  2170. (featurep 'advice)
  2171. (ad-get-advice-info function)))
  2172. (real-function
  2173. (or (and advised (let ((origname (cdr (assq 'origname advised))))
  2174. (and (fboundp origname)
  2175. origname)))
  2176. function))
  2177. (def (if (symbolp real-function)
  2178. (symbol-function real-function)
  2179. function)))
  2180. (subrp def)))
  2181. ;; (my-real-function-subr-p 'my-real-function-subr-p)
  2182. ;; (defadvice read-from-minibuffer (before info-in-prompt activate)
  2183. ;; "Show system info when use `read-from-minibuffer'."
  2184. ;; (ad-set-arg 0
  2185. ;; (concat my-system-info
  2186. ;; (ad-get-arg 0))))
  2187. ;; (defadvice read-string (before info-in-prompt activate)
  2188. ;; "Show system info when use `read-string'."
  2189. ;; (ad-set-arg 0
  2190. ;; (concat my-system-info
  2191. ;; (ad-get-arg 0))))
  2192. ;; (when (< emacs-major-version 24)
  2193. ;; (defadvice completing-read (before info-in-prompt activate)
  2194. ;; "Show system info when use `completing-read'."
  2195. ;; (ad-set-arg 0
  2196. ;; (concat my-system-info
  2197. ;; (ad-get-arg 0)))))
  2198. (defmacro info-in-prompt-set (&rest functions)
  2199. "Set info-in-prompt advices for FUNCTIONS."
  2200. `(progn
  2201. ,@(mapcar (lambda (f)
  2202. `(defadvice ,f (before info-in-prompt activate)
  2203. "Show info in prompt."
  2204. (let ((orig (ad-get-arg 0)))
  2205. (unless (string-match-p (regexp-quote info-in-prompt)
  2206. orig)
  2207. (ad-set-arg 0
  2208. (concat info-in-prompt
  2209. " "
  2210. orig))))))
  2211. functions)))
  2212. (info-in-prompt-set read-from-minibuffer
  2213. read-string
  2214. completing-read)
  2215. ;;; emacs.el ends here