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.
 
 
 
 
 
 

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