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.
 
 
 
 
 
 

1833 lines
64 KiB

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