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.
 
 
 
 
 
 

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