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.
 
 
 
 
 
 

1877 lines
65 KiB

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