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.
 
 
 
 
 
 

1925 lines
65 KiB

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