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.
 
 
 
 
 
 

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