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.
 
 
 
 
 
 

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