Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

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