Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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