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.
 
 
 
 
 
 

1892 lines
66 KiB

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