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.
 
 
 
 
 
 

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