You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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