25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

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