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

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