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.
 
 
 
 
 
 

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