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.
 
 
 
 
 
 

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