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.
 
 
 
 
 
 

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