You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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