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.
 
 
 
 
 
 

1924 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-variable-buffer-local 'scroll-margin) 0)
  717. ;; (set (make-variable-buffer-local '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. ))
  723. ;; (add-hook 'term-exec-hook 'forward-char)
  724. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  725. ;; buffer switching
  726. (when (require 'bs nil t)
  727. ;; (global-set-key "\C-x\C-b" 'bs-show)
  728. (defalias 'list-buffers 'bs-show))
  729. ;; (add-to-list 'bs-configurations '("processes" nil get-buffer-process ".*" nil nil))
  730. (add-to-list 'bs-configurations '("same-dir" nil buffer-same-dir-p ".*" nil nil))
  731. (add-to-list 'bs-configurations '("this-frame" nil (lambda (buf) (memq buf (my-frame-buffer-get))) ".*" nil nil))
  732. ;; (setq bs-configurations (list '("processes" nil get-buffer-process ".*" nil nil)
  733. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil bs-visits-non-file bs-sort-buffer-interns-are-last)))
  734. (setq bs-default-configuration "this-frame")
  735. (setq bs-default-sort-name "by name")
  736. (add-hook 'bs-mode-hook
  737. (lambda ()
  738. (setq bs-default-configuration "this-frame")
  739. ;; (and bs--show-all
  740. ;; (call-interactively 'bs-toggle-show-all))
  741. (set (make-variable-buffer-local 'scroll-margin) 0)
  742. ))
  743. (defun buffer-same-dir-p (bf)
  744. "return t if BF's dir is same as current dir, otherwise nil."
  745. (let ((cdir (expand-file-name default-directory)))
  746. (with-current-buffer bf
  747. (equal (expand-file-name default-directory) cdir))))
  748. (iswitchb-mode 1)
  749. (defun iswitchb-buffer-display-other-window ()
  750. ""
  751. (interactive)
  752. (let ((iswitchb-default-method 'display))
  753. (call-interactively 'iswitchb-buffer)))
  754. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  755. ;; sdic
  756. (defun sdic-describe-word-at-point-echo ()
  757. ""
  758. (interactive)
  759. (save-window-excursion
  760. (sdic-describe-word-at-point))
  761. (save-excursion
  762. (set-buffer sdic-buffer-name)
  763. (message (buffer-substring (point-min)
  764. (progn (goto-char (point-min))
  765. (or (and (re-search-forward "^\\w" nil t 4)
  766. (progn (previous-line) t)
  767. (point-at-eol))
  768. (point-max)))))))
  769. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  770. (setq sdic-waei-dictionary-list '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  771. (setq sdic-disable-select-window t)
  772. (setq sdic-window-height 7)
  773. (when (require 'sdic nil t)
  774. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  775. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo))
  776. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  777. ;; vc
  778. ;; (require 'vc)
  779. (setq vc-handled-backends nil)
  780. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  781. ;; gauche-mode
  782. (setq scheme-program-name
  783. (setq gauche-program-name "gosh"))
  784. (defun run-gauche-other-window ()
  785. "Run gauche on other window"
  786. (interactive)
  787. (switch-to-buffer-other-window
  788. (get-buffer-create "*scheme*"))
  789. (run-gauche))
  790. (defun run-gauche ()
  791. "run gauche"
  792. (run-scheme gauche-program-name)
  793. )
  794. (defun scheme-send-buffer ()
  795. ""
  796. (interactive)
  797. (scheme-send-region (point-min) (point-max))
  798. (set-window-text-height (display-buffer "*scheme*"
  799. t)
  800. 7)
  801. )
  802. (add-hook 'scheme-mode-hook
  803. (lambda ()
  804. nil))
  805. (add-hook 'inferior-scheme-mode-hook
  806. (lambda ()
  807. (set-window-text-height (display-buffer "*scheme*")
  808. 7)
  809. ))
  810. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  811. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  812. (when (dllib-if-unfound "gauche-mode"
  813. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  814. t)
  815. (setq auto-mode-alist
  816. (cons '("\.gosh$" . gauche-mode) auto-mode-alist))
  817. (setq auto-mode-alist
  818. (cons '("\.gaucherc$" . gauche-mode) auto-mode-alist))
  819. (autoload 'gauche-mode "gauche-mode" "Major mode for Scheme." t)
  820. (autoload 'run-scheme "gauche-mode" "Run an inferior Scheme process." t)
  821. (add-hook 'gauche-mode-hook
  822. (lambda ()
  823. (define-key gauche-mode-map "\C-c\C-z" 'run-gauche-other-window)
  824. (define-key scheme-mode-map "\C-c\C-c" 'scheme-send-buffer)
  825. )))
  826. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  827. ;; recentf-mode
  828. (add-hook 'recentf-dialog-mode-hook
  829. 'my-recentf-abbrev-list)
  830. (defun my-recentf-delete-entry ()
  831. ""
  832. (interactive)
  833. (let ((p (point)))
  834. (setq recentf-list
  835. (delete (my-recentf-get-filename) recentf-list))
  836. (recentf-open-files)
  837. (goto-char p)))
  838. (defun my-recentf-abbrev-list ()
  839. ""
  840. (setq recentf-list
  841. (mapcar 'abbreviate-file-name
  842. recentf-list)))
  843. (defun my-recentf-view-file ()
  844. ""
  845. (interactive)
  846. (view-file (my-recentf-get-filename)))
  847. (defun my-recentf-dired ()
  848. ""
  849. (interactive)
  850. (let ((file (my-recentf-get-filename)))
  851. (if (file-directory-p file)
  852. (dired file)
  853. (dired (or (file-name-directory file)
  854. ".")))))
  855. (defun my-recentf-x-open ()
  856. ""
  857. (interactive)
  858. (my-x-open (my-recentf-get-filename)))
  859. (defun my-recentf-cd-and-find-file ()
  860. ""
  861. (interactive)
  862. (cd (file-name-directory (my-recentf-get-filename)))
  863. (call-interactively 'find-file))
  864. (defun my-recentf-get-filename ()
  865. "get file name in recentf-mode"
  866. (replace-regexp-in-string " \\(\\[.+?\\] \\)?" ; " " or " [\\d] "
  867. ""
  868. (buffer-substring-no-properties (point-at-bol)
  869. (point-at-eol))))
  870. (setq recentf-save-file (expand-file-name "~/.emacs.d/.recentf")
  871. recentf-max-menu-items 20
  872. recentf-max-saved-items 30
  873. recentf-show-file-shortcuts-flag nil)
  874. (when (require 'recentf nil t)
  875. (global-set-key "\C-x\C-r" 'recentf-open-files)
  876. ;; (add-hook 'find-file-hook
  877. ;; (lambda ()
  878. ;; (recentf-add-file default-directory)))
  879. (recentf-mode 1)
  880. (add-to-list 'recentf-filename-handlers 'abbreviate-file-name)
  881. (add-to-list 'recentf-exclude "\\.emacs\\.d/\\.recentf"))
  882. (add-hook 'recentf-dialog-mode-hook
  883. (lambda ()
  884. (recentf-save-list)
  885. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f") 'my-recentf-cd-and-find-file)
  886. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  887. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  888. (define-key recentf-dialog-mode-map "o" 'my-recentf-x-open)
  889. (define-key recentf-dialog-mode-map "d" 'my-recentf-delete-entry)
  890. (define-key recentf-dialog-mode-map "@" 'my-recentf-dired)
  891. (define-key recentf-dialog-mode-map "v" 'my-recentf-view-file)
  892. (cd "~/")))
  893. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  894. ;; dired
  895. (require 'dired)
  896. (defun my-dired-echo-file-head (&optional arg)
  897. ""
  898. (interactive "P")
  899. (let ((f (dired-get-filename)))
  900. (message "%s"
  901. (with-temp-buffer
  902. (insert-file-contents f)
  903. (buffer-substring-no-properties (point-min)
  904. (progn (goto-line (if arg
  905. (prefix-numeric-value arg)
  906. 10))
  907. (point-at-eol)))))))
  908. (defun my-dired-diff ()
  909. ""
  910. (interactive)
  911. (let ((files (dired-get-marked-files nil nil nil t)))
  912. (if (eq (car files)
  913. t)
  914. (diff (cadr files) (dired-get-filename))
  915. (message "One files must be marked!"))))
  916. (require 'dired-aux) ;; needed to use dired-dwim-target-directory
  917. (defun my-dired-do-pack-or-unpack ()
  918. "pack or unpack files.
  919. if targetting one file and that is archive file defined in `pack-program-alist', unpack that.
  920. otherwise, pack marked files. prompt user to decide filename for archive."
  921. (interactive)
  922. (let* ((infiles (dired-get-marked-files t))
  923. (onefile (and (eq 1 ; filename if only one file targeted, otherwise nil.
  924. (length infiles))
  925. (car infiles))))
  926. (if (and onefile
  927. (my-pack-file-name-association onefile))
  928. (when (y-or-n-p (format "unpack %s? " onefile))
  929. (my-unpack onefile))
  930. (let* ((dir-default (dired-dwim-target-directory))
  931. (archive-default (my-pack-file-extension (file-name-nondirectory (car infiles))))
  932. (archive ;; (if (interactive-p)
  933. (read-file-name "Output file to pack : "
  934. dir-default
  935. nil
  936. nil
  937. archive-default)
  938. ;; (concat dir-default archive-default)
  939. ))
  940. (apply 'my-pack
  941. archive
  942. infiles))))
  943. (revert-buffer)
  944. ;; (dired-unmark-all-marks)
  945. )
  946. (defun my-file-name-extension-with-tar (filename)
  947. "if FILENAME has extension with tar, like \"tar.gz\", return that.
  948. otherwise, return extension normally."
  949. (if (string-equal "tar" (file-name-extension (file-name-sans-extension filename)))
  950. (concat "tar."
  951. (file-name-extension filename))
  952. (file-name-extension filename)))
  953. (defun my-pack-file-extension (filename)
  954. "if FILENAME has extension and it can be used for pack, return FILENAME.
  955. otherwise, return FILENAME with `my-pack-default-extension'"
  956. (if (my-pack-file-name-association filename)
  957. filename
  958. (concat filename "." my-pack-default-extension)))
  959. (defvar my-7z-program-name
  960. (or (executable-find "7z")
  961. (executable-find "7za")
  962. (executable-find "7zr"))
  963. "7z program.")
  964. (defvar my-pack-default-extension
  965. "7z"
  966. "default suffix for packing. filename with this suffix must matches one of `pack-program-alist'")
  967. (defun my-pack-file-name-association (filename)
  968. "if the pattern matching FILENAME is found at car of the list in `pack-program-alist', return cdr of that list.
  969. otherwise, return nil."
  970. (let ((case-fold-search nil))
  971. (assoc-default filename
  972. my-pack-program-alist
  973. 'string-match-p
  974. nil)))
  975. (defvar my-pack-program-alist
  976. `(
  977. ("\\.7z\\'" ,(concat my-7z-program-name " a") ,(concat my-7z-program-name " x"))
  978. ("\\.zip\\'" "zip -r" "unzip")
  979. ("\\.tar\\'" "tar cf" "tar xf")
  980. ("\\.tgz\\'" "tar czf" "tar xzf")
  981. ("\\.tar\\.gz\\'" "tar czf" "tar xzf")
  982. )
  983. "Alist of filename patterns, command for pack and unpack.
  984. Each element looks like (REGEXP PACKING-COMMAND UNPACKING-COMMAND).
  985. PACKING-COMMAND and UNPACKING-COMMAND can be nil if the command is not available.
  986. alist is searched from the beginning so pattern for \".tar.gz\" should be ahead of pattern for \".gz\"")
  987. ;; (string-match-p "\\.gz\\'" "aaa.gz") ; \' matches string end, $ also matches the point before newline.
  988. (defun my-unpack (archive)
  989. "unpack ARCHIVE. command for unpacking is defined in `pack-program-alist'"
  990. (interactive "fArchive to extract: ")
  991. (let* ((earchive (expand-file-name archive))
  992. (cmd (nth 1
  993. (my-pack-file-name-association earchive)))
  994. )
  995. (if cmd
  996. (shell-command (concat cmd
  997. " "
  998. (shell-quote-argument earchive)))
  999. (message "this is not archive file defined in `pack-program-alist'!"))))
  1000. (defun my-pack (archive &rest files)
  1001. "pack FILES into ARCHIVE.
  1002. if ARCHIVE have extension defined in `pack-program-alist', use that command.
  1003. otherwise, use `pack-default-extension' for pack."
  1004. (let* ((archive-ext (my-pack-file-extension (expand-file-name archive)))
  1005. (cmd (car (my-pack-file-name-association archive-ext)))
  1006. )
  1007. (if cmd
  1008. (shell-command (concat cmd
  1009. " "
  1010. (shell-quote-argument archive-ext)
  1011. " "
  1012. (mapconcat 'shell-quote-argument
  1013. files
  1014. " ")))
  1015. (message "invalid extension for packing!"))))
  1016. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1017. "pop up buffer using `display-buffer' and return that buffer."
  1018. (let ((bf (get-buffer-create buffer-or-name)))
  1019. (with-current-buffer bf
  1020. (cd ".")
  1021. (erase-buffer))
  1022. (display-buffer bf)
  1023. bf))
  1024. (defun my-replace-nasi-none ()
  1025. ""
  1026. (save-excursion
  1027. (let ((buffer-read-only nil))
  1028. (goto-char (point-min))
  1029. (while (search-forward "なし" nil t)
  1030. (replace-match "none")))))
  1031. (defun dired-get-du () ;em-unix.el使えるかも
  1032. "dired get disk usage"
  1033. (interactive)
  1034. (message "calculating du...")
  1035. (dired-do-shell-command "du -hs * " nil (dired-get-marked-files)))
  1036. (defun my-dired-scroll-up ()
  1037. ""
  1038. (interactive)
  1039. (my-dired-previous-line (- (window-height) 1)))
  1040. (defun my-dired-scroll-down ()
  1041. ""
  1042. (interactive)
  1043. (my-dired-next-line (- (window-height) 1)))
  1044. (defun my-dired-previous-line (&optional arg)
  1045. ""
  1046. (interactive)
  1047. (dired-previous-line (or arg 1))
  1048. (my-dired-print-current-dir-and-file))
  1049. (defun my-dired-next-line (&optional arg)
  1050. ""
  1051. (interactive)
  1052. (dired-next-line (or arg 1))
  1053. (my-dired-print-current-dir-and-file))
  1054. (defun my-dired-print-current-dir-and-file ()
  1055. (message "%s %s"
  1056. default-directory
  1057. (buffer-substring-no-properties (point-at-bol)
  1058. (point-at-eol))))
  1059. (defun dired-do-execute-as-command ()
  1060. ""
  1061. (interactive)
  1062. (let ((file (dired-get-filename t)))
  1063. (if (file-executable-p file)
  1064. (start-process file nil file)
  1065. (when (y-or-n-p "this file cant be executed. mark as executable and go? : ")
  1066. (set-file-modes file (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1067. (start-process file nil file)))))
  1068. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1069. (defun my-dired-x-open ()
  1070. ""
  1071. (interactive)
  1072. (my-x-open (dired-get-filename t t)))
  1073. (if (eq window-system 'mac)
  1074. (setq dired-listing-switches "-lhFG")
  1075. (setq dired-listing-switches "-lhFG --time-style=long-iso")
  1076. )
  1077. (setq dired-listing-switches "-lhFG")
  1078. (define-minor-mode my-dired-display-all-mode
  1079. ""
  1080. :init-value nil
  1081. :global nil
  1082. :lighter " ALL"
  1083. (when (eq major-mode 'dired-mode)
  1084. (my-dired-display-all-set)
  1085. (revert-buffer)))
  1086. (defun my-dired-display-all-set ()
  1087. ""
  1088. (if my-dired-display-all-mode
  1089. (or (string-match-p my-dired-display-all-switch
  1090. dired-actual-switches)
  1091. (setq dired-actual-switches
  1092. (concat my-dired-display-all-switch
  1093. " "
  1094. dired-actual-switches)))
  1095. (setq dired-actual-switches
  1096. (replace-regexp-in-string (concat my-dired-display-all-switch
  1097. " ")
  1098. ""
  1099. dired-actual-switches))))
  1100. (defvar my-dired-display-all-switch "-A")
  1101. (add-hook 'dired-mode-hook
  1102. 'my-dired-display-all-set)
  1103. (put 'dired-find-alternate-file 'disabled nil)
  1104. (setq dired-ls-F-marks-symlinks t)
  1105. (require 'ls-lisp)
  1106. (setq ls-lisp-use-insert-directory-program nil)
  1107. (setq ls-lisp-dirs-first t)
  1108. (setq ls-lisp-use-localized-time-format t)
  1109. (setq ls-lisp-format-time-list
  1110. '("%Y-%m-%d %H:%M"
  1111. "%Y-%m-%d "))
  1112. (setq dired-dwim-target t)
  1113. ;; (add-hook 'dired-after-readin-hook
  1114. ;; 'my-replace-nasi-none)
  1115. ;; (add-hook 'after-init-hook
  1116. ;; (lambda ()
  1117. ;; (dired ".")))
  1118. (add-hook 'dired-mode-hook
  1119. (lambda ()
  1120. (define-key dired-mode-map "o" 'my-dired-x-open)
  1121. (define-key dired-mode-map "i" 'dired-get-du)
  1122. (define-key dired-mode-map "!" 'shell-command)
  1123. (define-key dired-mode-map "&" 'async-shell-command)
  1124. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1125. (define-key dired-mode-map "=" 'my-dired-diff)
  1126. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1127. (define-key dired-mode-map "b" 'gtkbm)
  1128. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1129. (define-key dired-mode-map "@" (lambda () (interactive) (my-x-open ".")))
  1130. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1131. (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1132. (define-key dired-mode-map "a" 'my-dired-display-all-mode)
  1133. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1134. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1135. (substitute-key-definition 'dired-next-line 'my-dired-next-line dired-mode-map)
  1136. (substitute-key-definition 'dired-previous-line 'my-dired-previous-line dired-mode-map)
  1137. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1138. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1139. (let ((file "._Icon\015"))
  1140. (when (file-readable-p file)
  1141. (delete-file file)))))
  1142. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1143. (defun my-dired-toggle-mark()
  1144. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1145. (t dired-marker-char))))
  1146. (delete-char 1)
  1147. (insert cur)))
  1148. (defun my-dired-mark (arg)
  1149. "toggle mark the current (or next ARG) files.
  1150. If on a subdir headerline, mark all its files except `.' and `..'.
  1151. Use \\[dired-unmark-all-files] to remove all marks
  1152. and \\[dired-unmark] on a subdir to remove the marks in
  1153. this subdir."
  1154. (interactive "P")
  1155. (if (dired-get-subdir)
  1156. (save-excursion (dired-mark-subdir-files))
  1157. (let ((inhibit-read-only t))
  1158. (dired-repeat-over-lines
  1159. (prefix-numeric-value arg)
  1160. 'my-dired-toggle-mark))))
  1161. (defun my-dired-mark-backward (arg)
  1162. "In Dired, move up lines and toggle mark there.
  1163. Optional prefix ARG says how many lines to unflag; default is one line."
  1164. (interactive "p")
  1165. (my-dired-mark (- arg)))
  1166. (defun dired-mode-hooks()
  1167. (local-set-key (kbd "SPC") 'my-dired-mark)
  1168. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1169. (add-hook 'dired-mode-hook 'dired-mode-hooks)
  1170. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1171. ;; eshell
  1172. (defun my-eshell-backward-delete-char ()
  1173. (interactive)
  1174. (when (< (save-excursion
  1175. (eshell-bol)
  1176. (point))
  1177. (point))
  1178. (backward-delete-char 1)))
  1179. (defun my-file-owner-p (file)
  1180. "t if FILE is owned by me."
  1181. (eq (user-uid) (nth 2 (file-attributes file))))
  1182. ;; ;; http://www.bookshelf.jp/pukiwiki/pukiwiki.php?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9
  1183. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1184. ;; (defun eshell/less (&rest args)
  1185. ;; "Invoke `view-file' on the file.
  1186. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1187. ;; (if args
  1188. ;; (while args
  1189. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1190. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1191. ;; (file (pop args)))
  1192. ;; (view-file file)
  1193. ;; (goto-line line))
  1194. ;; (view-file (pop args))))))
  1195. ;; (defun eshell/git (&rest args)
  1196. ;; ""
  1197. ;; )
  1198. (defun eshell/o (&optional file)
  1199. (my-x-open (or file ".")))
  1200. ;; (defun eshell/vi (&rest args)
  1201. ;; "Invoke `find-file' on the file.
  1202. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1203. ;; (while args
  1204. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1205. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1206. ;; (file (pop args)))
  1207. ;; (find-file file)
  1208. ;; (goto-line line))
  1209. ;; (find-file (pop args)))))
  1210. (defun eshell/clear ()
  1211. "Clear the current buffer, leaving one prompt at the top."
  1212. (let ((inhibit-read-only t))
  1213. (erase-buffer)))
  1214. (defun eshell/d (&optional dirname switches)
  1215. "if first arg is omitted open current directory."
  1216. (dired (or dirname ".") switches))
  1217. (defun eshell/v ()
  1218. (view-mode 1))
  1219. (defalias 'eshell/: 'ignore)
  1220. (defalias 'eshell/type 'eshell/which)
  1221. ;; (defalias 'eshell/vim 'eshell/vi)
  1222. (defalias 'eshell/ff 'find-file)
  1223. (defalias 'eshell/q 'eshell/exit)
  1224. (defun eshell-goto-prompt ()
  1225. ""
  1226. (interactive)
  1227. (goto-char (point-max)))
  1228. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1229. "open eshell and change wd
  1230. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1231. (interactive)
  1232. (let ((dir (expand-file-name default-directory)))
  1233. (switch-to-buffer (or eshell-buffer-or-name
  1234. (eshell t)))
  1235. (unless (equal dir (expand-file-name default-directory))
  1236. ;; (cd dir)
  1237. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1238. ;; (eshell-emit-prompt)
  1239. (goto-char (point-max))
  1240. (eshell-kill-input)
  1241. (insert "cd " dir)
  1242. (eshell-send-input))))
  1243. (setq eshell-directory-name "~/.emacs.d/eshell/")
  1244. (setq eshell-term-name "eterm-color")
  1245. (setq eshell-scroll-to-bottom-on-input t)
  1246. (setq eshell-cmpl-ignore-case t)
  1247. (setq eshell-cmpl-cycle-completions nil)
  1248. (setq eshell-highlight-prompt nil)
  1249. (setq eshell-ls-initial-args "-FG") ; "-hF")
  1250. (setq eshell-prompt-function
  1251. (lambda ()
  1252. (with-temp-buffer
  1253. (let (p1 p2 p3 p4)
  1254. (insert " [")
  1255. (setq p1 (point))
  1256. (insert (abbreviate-file-name default-directory))
  1257. (setq p2 (point))
  1258. (insert "]"
  1259. "\n")
  1260. (setq p3 (point))
  1261. (insert user-login-name
  1262. "@"
  1263. (or (getenv "HOSTNAME")
  1264. (substring (shell-command-to-string (or (executable-find "hostname")
  1265. "echo ''"))
  1266. 0
  1267. -1)))
  1268. (setq p4 (point))
  1269. (insert " "
  1270. (format-time-string "%a, %d %b %Y %T %z")
  1271. " eshell\n"
  1272. "last:"
  1273. (number-to-string eshell-last-command-status)
  1274. (if (= (user-uid)
  1275. 0)
  1276. " # "
  1277. " $ "))
  1278. (add-text-properties p1
  1279. p2
  1280. '(face ((foreground-color . "yellow"))))
  1281. (add-text-properties p3
  1282. p4
  1283. '(face ((foreground-color . "cyan"))))
  1284. (buffer-substring (point-min)
  1285. (point-max))))))
  1286. (add-hook 'eshell-mode-hook
  1287. (lambda ()
  1288. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1289. ;; (interactive)
  1290. ;; (switch-to-buffer (other-buffer))))
  1291. (define-key eshell-mode-map (kbd "C-u") (lambda ()
  1292. (interactive)
  1293. (eshell-goto-prompt)
  1294. (eshell-kill-input)))
  1295. (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1296. (interactive)
  1297. (eshell-goto-prompt)
  1298. (my-keyboard-quit)))
  1299. (define-key eshell-mode-map (kbd "DEL") 'my-eshell-backward-delete-char)
  1300. (define-key eshell-mode-map (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1301. (define-key eshell-mode-map (kbd "C-n") 'eshell-next-matching-input-from-input)
  1302. (mapcar (lambda (alias)
  1303. (add-to-list 'eshell-command-aliases-list
  1304. alias))
  1305. '(
  1306. ; ("ll" "ls -l $*")
  1307. ; ("la" "ls -a $*")
  1308. ; ("lla" "ls -al $*")
  1309. ("ut" "slogin 03110414@un001.ecc.u-tokyo.ac.jp $*")
  1310. ("aptin" "apt-get install $*")
  1311. ("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*\"))")
  1312. ("g" "git $*")
  1313. ))
  1314. ; (eshell/alias "g" "git $*")
  1315. (add-to-list 'eshell-output-filter-functions 'eshell-truncate-buffer)
  1316. (apply 'eshell/addpath exec-path)
  1317. (set (make-variable-buffer-local 'scroll-margin) 0)
  1318. ;; (eshell/export "GIT_PAGER=")
  1319. ;; (eshell/export "GIT_EDITOR=")
  1320. (eshell/export "LC_MESSAGES=C")
  1321. (add-to-list 'eshell-visual-commands "vim")
  1322. (add-to-list 'eshell-visual-commands "git")
  1323. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1324. ))
  1325. ;; (eval-after-load "em-alias"
  1326. ;; '(progn ;; (eshell/alias "ll" "ls -l")
  1327. ;; ;; (eshell/alias "la" "ls -a")
  1328. ;; ;; (eshell/alias "lla" "ls -al")
  1329. ;; (eshell/alias "sgcc" (if (eq system-type 'windows-nt)
  1330. ;; "gcc -o win.$1.exe $1"
  1331. ;; "gcc -o ${uname}.$1.out $1"))
  1332. ;; (eshell/alias "slmgcc" (if (eq system-type 'windows-nt)
  1333. ;; "gcc -lm -o win.$1.exe $1"
  1334. ;; "gcc -lm -o ${uname}.$1.out $1"))
  1335. ;; ;; (eshell/alias "ut" "ssh g841105@un001.ecc.u-tokyo.ac.jp")
  1336. ;; (add-to-list 'recentf-exclude (concat eshell-directory-name "alias"))))
  1337. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1338. ;; 最終更新日時を得る
  1339. (defvar my-buffer-file-last-modified-time nil "")
  1340. (make-variable-buffer-local 'my-buffer-file-last-modified-time)
  1341. (defun my-get-file-last-modified-time (file)
  1342. ""
  1343. (nth 5
  1344. (file-attributes file)))
  1345. (defun my-set-buffer-file-last-modified-time ()
  1346. ""
  1347. (make-local-variable 'my-buffer-file-last-modified-time)
  1348. (setq my-buffer-file-last-modified-time
  1349. (format-time-string "%Y/%m/%d %H:%M" (my-get-file-last-modified-time buffer-file-name))))
  1350. (add-hook 'find-file-hook
  1351. 'my-set-buffer-file-last-modified-time)
  1352. (add-hook 'after-save-hook
  1353. 'my-set-buffer-file-last-modified-time)
  1354. (add-hook 'after-revert-hook
  1355. 'my-set-buffer-file-last-modified-time)
  1356. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1357. ;; auto saving
  1358. (defun my-save-this-buffer (silent-p)
  1359. "save current buffer if can without asking"
  1360. (let ((cm (if (current-message)
  1361. (format "%s\n" (current-message))
  1362. ""))
  1363. (fun (symbol-function (if silent-p
  1364. 'ignore
  1365. 'message))))
  1366. (cond ((active-minibuffer-window) nil)
  1367. ((not buffer-file-name) (funcall fun "%ssaving... this buffer doesn't visit any file." cm) nil)
  1368. ((not (file-exists-p buffer-file-name)) (funcall fun "%ssaving... file not exist. save manually first." com) nil)
  1369. (buffer-read-only (funcall fun "%ssaving... this buffer is read-only." cm) nil)
  1370. ((not (buffer-modified-p)) (funcal fun "%ssaving... not modified yet." cm) nil)
  1371. ((not (file-writable-p buffer-file-name)) (funcall fun "%ssaving... you cannot change this file." cm) nil)
  1372. (t (funcall fun "%ssaving..." cm)
  1373. (save-buffer)
  1374. (funcall fun "%ssaving... done." cm)))))
  1375. ;; (if (and buffer-file-name
  1376. ;; (not buffer-read-only)
  1377. ;; (buffer-modified-p)
  1378. ;; (file-writable-p buffer-file-name))
  1379. ;; (save-buffer))) ; 静かな方
  1380. (defvar my-auto-save-this-buffer nil "auto save timer object")
  1381. (defun my-auto-save-this-buffer (sec &optional silent-p)
  1382. "auto save current buffer if idle for SEC.
  1383. when SEC is nil, stop auto save if enabled."
  1384. (if sec
  1385. (progn (when my-auto-save-this-buffer
  1386. (cancel-timer my-auto-save-this-buffer)
  1387. (setq my-auto-save-this-buffer nil))
  1388. (setq my-auto-save-this-buffer (run-with-idle-timer sec t 'my-save-this-buffer silent-p)))
  1389. (when my-auto-save-this-buffer
  1390. (cancel-timer my-auto-save-this-buffer)
  1391. (setq my-auto-save-this-buffer nil))))
  1392. (my-auto-save-this-buffer 2 t)
  1393. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1394. ;; misc funcs
  1395. (defun my-format-time-string (&optional time)
  1396. ""
  1397. (let ((system-time-locale "C"))
  1398. (format-time-string "%a, %d %b %Y %T" time)))
  1399. (defvar my-filer nil)
  1400. (setq my-filer (or (executable-find "pcmanfm")
  1401. (executable-find "nautilus")))
  1402. (defun my-x-open (file)
  1403. "open file."
  1404. (interactive "FOpen File: ")
  1405. (setq file (expand-file-name file))
  1406. (message "Opening %s..." file)
  1407. (cond ((eq system-type 'windows-nt)
  1408. (call-process "cmd.exe" nil 0 nil "/c" "start" "" (convert-standard-filename file)))
  1409. ((eq system-type 'darwin)
  1410. (call-process "open" nil 0 nil file))
  1411. ((not (getenv "DESKTOP_SESSION"))
  1412. (find-file file))
  1413. (t
  1414. (if (file-directory-p file)
  1415. (call-process my-filer nil 0 nil file)
  1416. (call-process "xdg-open" nil 0 nil file))))
  1417. (recentf-add-file file)
  1418. (message "Opening %s...done" file))
  1419. (defvar my-auto-indent-buffer-mode-list
  1420. '(emacs-lisp-mode
  1421. sh-mode
  1422. js-mode
  1423. sgml-mode
  1424. c-mode
  1425. c++-mode))
  1426. (setq my-auto-indent-buffer-mode-list nil) ;disable
  1427. (defun my-indent-buffer ()
  1428. "indent whole buffer."
  1429. (interactive)
  1430. (indent-region (point-min)
  1431. (point-max)))
  1432. (defun my-auto-indent-buffer ()
  1433. ""
  1434. (when (memq major-mode my-auto-indent-buffer-mode-list)
  1435. (my-indent-buffer)))
  1436. (add-hook 'before-save-hook
  1437. 'my-auto-indent-buffer)
  1438. (defun my-keyboard-quit ()
  1439. ""
  1440. (interactive)
  1441. (run-hooks 'before-keyboard-quit-hook)
  1442. ;; (redisplay t)
  1443. (redraw-display)
  1444. ;; (run-hooks 'window-configuration-change-hook)
  1445. (my-revert-buffer-if-needed)
  1446. ;; (revert-buffer t t)
  1447. (keyboard-quit)
  1448. (insert "insert me")
  1449. (run-hooks 'after-keyboard-quit-hook))
  1450. (substitute-key-definition 'keyboard-quit 'my-keyboard-quit global-map)
  1451. ;; (global-set-key (kbd "C-g") 'my-keyboard-quit)
  1452. (defun my-convmv-sjis2utf8-test ()
  1453. "run `convmv -r -f sjis -t utf8 *'
  1454. this is test, does not rename files"
  1455. (interactive)
  1456. (shell-command "convmv -r -f sjis -t utf8 *"))
  1457. (defun my-convmv-sjis2utf8-notest ()
  1458. "run `convmv -r -f sjis -t utf8 * --notest'"
  1459. (interactive)
  1460. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  1461. (defun my-copy-whole-line ()
  1462. ""
  1463. (interactive)
  1464. (kill-new (concat (buffer-substring (point-at-bol)
  1465. (point-at-eol))
  1466. "\n")))
  1467. (defun kill-ring-save-buffer-file-name ()
  1468. "get current filename"
  1469. (interactive)
  1470. (let ((file buffer-file-name))
  1471. (if file
  1472. (progn (kill-new file)
  1473. (message file))
  1474. (message "not visiting file."))))
  1475. ;; ;; コマンド的な
  1476. ;; (defvar my-execute-func-list nil "func list")
  1477. ;; (defvar my-execute-func-hist-list nil "func hist list")
  1478. ;; (setq my-execute-func-list '("(call-interactively 'my-francaiscd-b)"
  1479. ;; "(call-interactively 'my-francaiscd-a)"
  1480. ;; "parsec47"
  1481. ;; "chromium-browser"
  1482. ;; "inkscape"
  1483. ;; "audacious"
  1484. ;; "gnome-terminal"
  1485. ;; "zkaicd.py"
  1486. ;; "glchess"))
  1487. ;; (defun my-execute-start-process-or-eval-sexp ()
  1488. ;; "execute something"
  1489. ;; (interactive)
  1490. ;; (let ((func (completing-read "command?: " my-execute-func-list nil nil "" my-execute-func-hist-list)))
  1491. ;; (if (string= "(" (substring func 0 1))
  1492. ;; (with-temp-buffer (insert func)
  1493. ;; (eval-buffer))
  1494. ;; (start-process "ps"
  1495. ;; nil
  1496. ;; func))))
  1497. (defvar my-revert-buffer-if-needed-last-buffer nil)
  1498. (defun my-revert-buffer-if-needed ()
  1499. ""
  1500. (interactive)
  1501. (unless (eq my-revert-buffer-if-needed-last-buffer (current-buffer))
  1502. (setq my-revert-buffer-if-needed-last-buffer (current-buffer))
  1503. (when (or (eq major-mode 'dired-mode)
  1504. (not (verify-visited-file-modtime (current-buffer))))
  1505. (revert-buffer t t)
  1506. (message "%s reverted." (buffer-name)))))
  1507. (add-hook 'post-command-hook ; 'window-configuration-change-hook
  1508. 'my-revert-buffer-if-needed)
  1509. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1510. ;; forked from http://d.hatena.ne.jp/khiker/20100119/window_resize
  1511. (define-key my-prefix-map (kbd "C-w") 'my-window-organizer)
  1512. (defun my-window-organizer ()
  1513. "Control window size and position."
  1514. (interactive)
  1515. (save-selected-window
  1516. (select-window (window-at 0 0))
  1517. (let ( ;; (window-obj (selected-window))
  1518. ;; (current-width (window-width))
  1519. ;; (current-height (window-height))
  1520. action
  1521. c)
  1522. (catch 'end-flag
  1523. (while t
  1524. (setq action
  1525. (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."
  1526. (window-width)
  1527. (window-height))))
  1528. (setq c (aref action 0))
  1529. (cond ((= c ?l)
  1530. (unless (eq (window-width) (frame-width))
  1531. (enlarge-window-horizontally 1)))
  1532. ((= c ?h)
  1533. (unless (eq (window-width) (frame-width))
  1534. (shrink-window-horizontally 1)))
  1535. ((= c ?j)
  1536. (enlarge-window 1))
  1537. ((= c ?k)
  1538. (shrink-window 1))
  1539. ((= c ?o)
  1540. (other-window 1))
  1541. ((memq c '(?d ?0))
  1542. (unless (eq (selected-window) (next-window (selected-window) 0 1))
  1543. (delete-window (selected-window))))
  1544. ((= c ?1)
  1545. (delete-other-windows))
  1546. ((= c ?2)
  1547. (split-window-vertically))
  1548. ((= c ?3)
  1549. (split-window-horizontally))
  1550. ((memq c '(?q ?\C-g))
  1551. (message "Quit")
  1552. (throw 'end-flag t))
  1553. (t
  1554. (beep))))))))
  1555. ;; (aref (read-key-sequence-vector "aa") 0)
  1556. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1557. ;; save and restore frame size
  1558. ;;http://www.bookshelf.jp/soft/meadow_30.html#SEC416
  1559. (defun my-window-size-save ()
  1560. (let* ((rlist (frame-parameters (selected-frame)))
  1561. (ilist initial-frame-alist)
  1562. (nCHeight (frame-height))
  1563. (nCWidth (frame-width))
  1564. (tMargin (if (integerp (cdr (assoc 'top rlist)))
  1565. (cdr (assoc 'top rlist)) 0))
  1566. (lMargin (if (integerp (cdr (assoc 'left rlist)))
  1567. (cdr (assoc 'left rlist)) 0))
  1568. buf
  1569. (file "~/.emacs.d/.framesize.el")
  1570. (recentf-exclude '("\\.emacs\\.d/\\.framesize\\.el$")))
  1571. (if (get-file-buffer (expand-file-name file))
  1572. (setq buf (get-file-buffer (expand-file-name file)))
  1573. (setq buf (find-file-noselect file)))
  1574. (set-buffer buf)
  1575. (erase-buffer)
  1576. (insert (concat
  1577. ;; 初期値をいじるよりも modify-frame-parameters
  1578. ;; で変えるだけの方がいい?
  1579. "(delete 'width default-frame-alist)\n"
  1580. "(delete 'height default-frame-alist)\n"
  1581. "(delete 'top default-frame-alist)\n"
  1582. "(delete 'left default-frame-alist)\n"
  1583. "(setq default-frame-alist (append (list\n"
  1584. "'(width . " (int-to-string nCWidth) ")\n"
  1585. "'(height . " (int-to-string nCHeight) ")\n"
  1586. "'(top . " (int-to-string tMargin) ")\n"
  1587. "'(left . " (int-to-string lMargin) "))\n"
  1588. "default-frame-alist))\n"
  1589. ;;"(setq default-frame-alist default-frame-alist)"
  1590. ))
  1591. (save-buffer)
  1592. ))
  1593. (defun my-window-size-load ()
  1594. (let* ((file "~/.emacs.d/.framesize.el"))
  1595. (if (file-exists-p file)
  1596. (load file))))
  1597. (when window-system
  1598. (my-window-size-load)
  1599. (add-hook 'after-init-hook ;何かがframeの大きさ勝手に変えやがる
  1600. (lambda ()
  1601. (run-with-timer 1
  1602. nil
  1603. (lambda ()
  1604. (modify-frame-parameters (selected-frame)
  1605. default-frame-alist))))
  1606. t)
  1607. (add-hook 'kill-emacs-hook
  1608. 'my-window-size-save))
  1609. ;; windowサイズを固定
  1610. ;; setq default-frame-alist
  1611. ;; (append (list '(width . 80)
  1612. ;; '(height . 35)
  1613. ;; )
  1614. ;; default-frame-alist)
  1615. ;; ) ;;デフォルトのフレーム設定
  1616. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1617. ;; ;; emacsを殺伐とさせる
  1618. ;; ;; 補完させるとき失敗するからなし
  1619. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  1620. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  1621. ;; (setq arg
  1622. ;; (concat arg
  1623. ;; (if (eq nil (string-match "\\. *$" arg)) ".")
  1624. ;; " And You are a Coward!")))
  1625. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1626. ;; ubuntu
  1627. (defun my-load-scim ()
  1628. "use scim-bridge.el as japanese im."
  1629. ;; Load scim-bridge.
  1630. (require 'scim-bridge)
  1631. ;; Turn on scim-mode automatically after loading .emacs
  1632. (add-hook 'after-init-hook 'scim-mode-on)
  1633. (setq scim-cursor-color "red")
  1634. (scim-define-preedit-key ?\^h t)
  1635. (scim-define-common-key ?\* nil)
  1636. (scim-define-common-key ?\^/ nil))
  1637. (defun my-load-anthy ()
  1638. "use anthy.el as japanese im."
  1639. ;; anthy
  1640. (require 'anthy)
  1641. (global-set-key [muhenkan] (lambda () (interactive) (anthy-mode-off)))
  1642. (global-set-key [henkan] (lambda () (interactive) (anthy-mode-on)))
  1643. (when (>= emacs-major-version 23)
  1644. (setq anthy-accept-timeout 1)))
  1645. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1646. ;; windows用設定
  1647. ;; (add-to-list 'exec-path "c:/Program Files/Gauche/bin/")
  1648. (defun start-ckw-bash ()
  1649. ""
  1650. (interactive)
  1651. (start-process "ckw_bash"
  1652. nil
  1653. "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe")) ; cじゃないといけないらしい
  1654. (defun my-w32-add-export-path (&rest args)
  1655. ""
  1656. (mapcar (lambda (path)
  1657. (add-to-list 'exec-path (expand-file-name path)))
  1658. (reverse args))
  1659. (setenv "PATH"
  1660. (mapconcat 'convert-standard-filename
  1661. exec-path
  1662. ";")))
  1663. (when (eq system-type 'windows-nt)
  1664. ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i")
  1665. ;; (setq python-python-command "c:/Python26/python.exe")
  1666. (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash)
  1667. (my-w32-add-export-path "c:/WINDOWS"
  1668. (expand-file-name "~/bin")
  1669. (expand-file-name "~/dbx/apps/bin"))
  1670. (when window-system
  1671. (setq w32-enable-synthesized-fonts t))
  1672. (setq file-name-coding-system 'sjis))