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.
 
 
 
 
 
 

1939 lines
69 KiB

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