Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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