選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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