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.
 
 
 
 
 
 

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