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.
 
 
 
 
 
 

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