Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

2085 řádky
71 KiB

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