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.
 
 
 
 
 
 

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