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.
 
 
 
 
 
 

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