您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

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