Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

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