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.
 
 
 
 
 
 

1817 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 "LC_MESSAGES=C")
  1200. ))
  1201. ;; (eval-after-load "em-alias"
  1202. ;; '(progn ;; (eshell/alias "ll" "ls -l")
  1203. ;; ;; (eshell/alias "la" "ls -a")
  1204. ;; ;; (eshell/alias "lla" "ls -al")
  1205. ;; (eshell/alias "sgcc" (if (eq system-type 'windows-nt)
  1206. ;; "gcc -o win.$1.exe $1"
  1207. ;; "gcc -o ${uname}.$1.out $1"))
  1208. ;; (eshell/alias "slmgcc" (if (eq system-type 'windows-nt)
  1209. ;; "gcc -lm -o win.$1.exe $1"
  1210. ;; "gcc -lm -o ${uname}.$1.out $1"))
  1211. ;; ;; (eshell/alias "ut" "ssh g841105@un001.ecc.u-tokyo.ac.jp")
  1212. ;; (add-to-list 'recentf-exclude (concat eshell-directory-name "alias"))))
  1213. (define-key my-prefix-map (kbd "C-s") (lambda ()
  1214. (interactive)
  1215. (eshell-cd-default-directory (buffer-name (or (my-eshell-frame-buffer (selected-frame))
  1216. (eshell t))))))
  1217. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1218. ;; 最終更新日時を得る
  1219. (defvar my-buffer-file-last-modified-time nil "")
  1220. (make-variable-buffer-local 'my-buffer-file-last-modified-time)
  1221. (defun my-get-file-last-modified-time (file)
  1222. ""
  1223. (nth 5
  1224. (file-attributes file)))
  1225. (defun my-set-buffer-file-last-modified-time ()
  1226. ""
  1227. (make-local-variable 'my-buffer-file-last-modified-time)
  1228. (setq my-buffer-file-last-modified-time
  1229. (format-time-string "%Y/%m/%d %H:%M" (my-get-file-last-modified-time buffer-file-name))))
  1230. (add-hook 'find-file-hook
  1231. 'my-set-buffer-file-last-modified-time)
  1232. (add-hook 'after-save-hook
  1233. 'my-set-buffer-file-last-modified-time)
  1234. (add-hook 'after-revert-hook
  1235. 'my-set-buffer-file-last-modified-time)
  1236. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1237. ;; auto saving
  1238. (defun my-save-this-buffer (silent-p)
  1239. "save current buffer if can without asking"
  1240. (let ((cm (if (current-message)
  1241. (format "%s\n" (current-message))
  1242. ""))
  1243. (fun (symbol-function (if silent-p
  1244. 'ignore
  1245. 'message))))
  1246. (cond ((active-minibuffer-window) nil)
  1247. ((not buffer-file-name) (funcall fun "%ssaving... this buffer doesn't visit any file." cm) nil)
  1248. (buffer-read-only (funcall fun "%ssaving... this buffer is read-only." cm) nil)
  1249. ((not (buffer-modified-p)) (funcal fun "%ssaving... not modified yet." cm) nil)
  1250. ((not (file-writable-p buffer-file-name)) (funcall fun "%ssaving... you cannot change this file." cm) nil)
  1251. (t (funcall fun "%ssaving..." cm)
  1252. (save-buffer)
  1253. (funcall fun "%ssaving... done." cm)))))
  1254. ;; (if (and buffer-file-name
  1255. ;; (not buffer-read-only)
  1256. ;; (buffer-modified-p)
  1257. ;; (file-writable-p buffer-file-name))
  1258. ;; (save-buffer))) ; 静かな方
  1259. (defvar my-auto-save-this-buffer nil "auto save timer object")
  1260. (defun my-auto-save-this-buffer (secs &optional silent-p)
  1261. "auto save current buffer if idle for SEC.
  1262. when SEC is nil, stop auto save if enabled."
  1263. (if secs
  1264. (progn (when my-auto-save-this-buffer
  1265. (cancel-timer my-auto-save-this-buffer)
  1266. (setq my-auto-save-this-buffer nil))
  1267. (setq my-auto-save-this-buffer (run-with-idle-timer secs t 'my-save-this-buffer silent-p)))
  1268. (when my-auto-save-this-buffer
  1269. (cancel-timer my-auto-save-this-buffer)
  1270. (setq my-auto-save-this-buffer nil))))
  1271. (my-auto-save-this-buffer 2 t)
  1272. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1273. ;; misc funcs
  1274. (defun my-format-time-string (&optional time)
  1275. ""
  1276. (let ((system-time-locale "C"))
  1277. (format-time-string "%a, %d %b %Y %T" time)))
  1278. (defvar my-filer nil)
  1279. (setq my-filer (or (executable-find "pcmanfm")
  1280. (executable-find "nautilus")))
  1281. (defun my-x-open (file)
  1282. "open file."
  1283. (interactive "FOpen File: ")
  1284. (setq file (expand-file-name file))
  1285. (message "Opening %s..." file)
  1286. (cond ((eq system-type 'windows-nt)
  1287. (call-process "cmd.exe" nil 0 nil "/c" "start" "" (convert-standard-filename file)))
  1288. ((eq system-type 'darwin)
  1289. (call-process "open" nil 0 nil file))
  1290. ((not (getenv "DESKTOP_SESSION"))
  1291. (find-file file))
  1292. (t
  1293. (if (file-directory-p file)
  1294. (call-process my-filer nil 0 nil file)
  1295. (call-process "xdg-open" nil 0 nil file))))
  1296. (recentf-add-file file)
  1297. (message "Opening %s...done" file))
  1298. (defvar my-indent-buffer-mode-list
  1299. '(emacs-lisp-mode
  1300. sh-mode
  1301. js-mode
  1302. sgml-mode
  1303. c-mode))
  1304. (defun my-indent-buffer ()
  1305. ""
  1306. (interactive)
  1307. (indent-region (point-min)
  1308. (point-max)))
  1309. (add-hook 'before-save-hook
  1310. (lambda ()
  1311. (when (memq major-mode my-indent-buffer-mode-list)
  1312. (my-indent-buffer))))
  1313. (defun my-keyboard-quit ()
  1314. ""
  1315. (interactive)
  1316. (run-hooks 'before-keyboard-quit-hook)
  1317. (redisplay)
  1318. (keyboard-quit)
  1319. (run-hooks 'after-keyboard-quit-hook))
  1320. (substitute-key-definition 'keyboard-quit 'my-keyboard-quit global-map)
  1321. ;; (global-set-key (kbd "C-g") 'my-keyboard-quit)
  1322. (defun my-convmv-sjis2utf8-test ()
  1323. "run `convmv -r -f sjis -t utf8 *'
  1324. this is test, does not rename files"
  1325. (interactive)
  1326. (shell-command "convmv -r -f sjis -t utf8 *"))
  1327. (defun my-convmv-sjis2utf8-notest ()
  1328. "run `convmv -r -f sjis -t utf8 * --notest'"
  1329. (interactive)
  1330. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  1331. (defun my-copy-whole-line ()
  1332. ""
  1333. (interactive)
  1334. (kill-new (concat (buffer-substring (point-at-bol)
  1335. (point-at-eol))
  1336. "\n")))
  1337. (defun kill-ring-save-buffer-file-name ()
  1338. "get current filename"
  1339. (interactive)
  1340. (let ((file buffer-file-name))
  1341. (if file
  1342. (progn (kill-new file)
  1343. (message file))
  1344. (message "not visiting file."))))
  1345. ;; ;; コマンド的な
  1346. ;; (defvar my-execute-func-list nil "func list")
  1347. ;; (defvar my-execute-func-hist-list nil "func hist list")
  1348. ;; (setq my-execute-func-list '("(call-interactively 'my-francaiscd-b)"
  1349. ;; "(call-interactively 'my-francaiscd-a)"
  1350. ;; "parsec47"
  1351. ;; "chromium-browser"
  1352. ;; "inkscape"
  1353. ;; "audacious"
  1354. ;; "gnome-terminal"
  1355. ;; "zkaicd.py"
  1356. ;; "glchess"))
  1357. ;; (defun my-execute-start-process-or-eval-sexp ()
  1358. ;; "execute something"
  1359. ;; (interactive)
  1360. ;; (let ((func (completing-read "command?: " my-execute-func-list nil nil "" my-execute-func-hist-list)))
  1361. ;; (if (string= "(" (substring func 0 1))
  1362. ;; (with-temp-buffer (insert func)
  1363. ;; (eval-buffer))
  1364. ;; (start-process "ps"
  1365. ;; nil
  1366. ;; func))))
  1367. ;; delete-trailing-whitespace
  1368. ;; (defun my-delete-blanks-on-eol ()
  1369. ;; ""
  1370. ;; (interactive)
  1371. ;; (save-excursion
  1372. ;; (goto-char (point-min))
  1373. ;; (while (re-search-forward "[ \t]+$" nil t)
  1374. ;; (replace-match "" nil nil))))
  1375. (defun my-revert-buffer-if-needed ()
  1376. ""
  1377. (interactive)
  1378. (unless (verify-visited-file-modtime (current-buffer))
  1379. (revert-buffer t t)))
  1380. (add-hook 'window-configuration-change-hook
  1381. (lambda ()
  1382. (run-with-timer 0.5
  1383. nil
  1384. 'my-revert-buffer-if-needed)))
  1385. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1386. ;; forked from http://d.hatena.ne.jp/khiker/20100119/window_resize
  1387. (define-key my-prefix-map (kbd "C-w") 'my-window-organizer)
  1388. (defun my-window-organizer ()
  1389. "Control window size and position."
  1390. (interactive)
  1391. (save-selected-window
  1392. (select-window (window-at 0 0))
  1393. (let ( ;; (window-obj (selected-window))
  1394. ;; (current-width (window-width))
  1395. ;; (current-height (window-height))
  1396. action
  1397. c)
  1398. (catch 'end-flag
  1399. (while t
  1400. (setq action
  1401. (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."
  1402. (window-width)
  1403. (window-height))))
  1404. (setq c (aref action 0))
  1405. (cond ((= c ?l)
  1406. (unless (eq (window-width) (frame-width))
  1407. (enlarge-window-horizontally 1)))
  1408. ((= c ?h)
  1409. (unless (eq (window-width) (frame-width))
  1410. (shrink-window-horizontally 1)))
  1411. ((= c ?j)
  1412. (enlarge-window 1))
  1413. ((= c ?k)
  1414. (shrink-window 1))
  1415. ((= c ?o)
  1416. (other-window 1))
  1417. ((memq c '(?d ?0))
  1418. (unless (eq (selected-window) (next-window (selected-window) 0 1))
  1419. (delete-window (selected-window))))
  1420. ((= c ?1)
  1421. (delete-other-windows))
  1422. ((= c ?2)
  1423. (split-window-vertically))
  1424. ((= c ?3)
  1425. (split-window-horizontally))
  1426. ((memq c '(?q ?\C-g))
  1427. (message "Quit")
  1428. (throw 'end-flag t))
  1429. (t
  1430. (beep))))))))
  1431. ;; (aref (read-key-sequence-vector "aa") 0)
  1432. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1433. ;; save and restore frame size
  1434. ;;http://www.bookshelf.jp/soft/meadow_30.html#SEC416
  1435. (defun my-window-size-save ()
  1436. (let* ((rlist (frame-parameters (selected-frame)))
  1437. (ilist initial-frame-alist)
  1438. (nCHeight (frame-height))
  1439. (nCWidth (frame-width))
  1440. (tMargin (if (integerp (cdr (assoc 'top rlist)))
  1441. (cdr (assoc 'top rlist)) 0))
  1442. (lMargin (if (integerp (cdr (assoc 'left rlist)))
  1443. (cdr (assoc 'left rlist)) 0))
  1444. buf
  1445. (file "~/.emacs.d/.framesize.el")
  1446. (recentf-exclude '("\\.emacs\\.d/\\.framesize\\.el$")))
  1447. (if (get-file-buffer (expand-file-name file))
  1448. (setq buf (get-file-buffer (expand-file-name file)))
  1449. (setq buf (find-file-noselect file)))
  1450. (set-buffer buf)
  1451. (erase-buffer)
  1452. (insert (concat
  1453. ;; 初期値をいじるよりも modify-frame-parameters
  1454. ;; で変えるだけの方がいい?
  1455. "(delete 'width default-frame-alist)\n"
  1456. "(delete 'height default-frame-alist)\n"
  1457. "(delete 'top default-frame-alist)\n"
  1458. "(delete 'left default-frame-alist)\n"
  1459. "(setq default-frame-alist (append (list\n"
  1460. "'(width . " (int-to-string nCWidth) ")\n"
  1461. "'(height . " (int-to-string nCHeight) ")\n"
  1462. "'(top . " (int-to-string tMargin) ")\n"
  1463. "'(left . " (int-to-string lMargin) "))\n"
  1464. "default-frame-alist))\n"
  1465. ;;"(setq default-frame-alist default-frame-alist)"
  1466. ))
  1467. (save-buffer)
  1468. ))
  1469. (defun my-window-size-load ()
  1470. (let* ((file "~/.emacs.d/.framesize.el"))
  1471. (if (file-exists-p file)
  1472. (load file))))
  1473. (when window-system
  1474. (my-window-size-load)
  1475. (add-hook 'after-init-hook ;何かがframeの大きさ勝手に変えやがる
  1476. (lambda ()
  1477. (run-with-timer 1
  1478. nil
  1479. (lambda ()
  1480. (modify-frame-parameters (selected-frame)
  1481. default-frame-alist))))
  1482. t)
  1483. ;; (add-hook 'make-frame-hook
  1484. ;; (lambda ()
  1485. ;; (run-with-timer 1
  1486. ;; nil
  1487. ;; (lambda ()
  1488. ;; (modify-frame-parameters (selected-frame)
  1489. ;; initial-frame-alist))))
  1490. ;; t)
  1491. (add-hook 'kill-emacs-hook
  1492. 'my-window-size-save))
  1493. ;; windowサイズを固定
  1494. ;; setq default-frame-alist
  1495. ;; (append (list '(width . 80)
  1496. ;; '(height . 35)
  1497. ;; )
  1498. ;; default-frame-alist)
  1499. ;; ) ;;デフォルトのフレーム設定
  1500. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1501. ;; 現在行をハイライト
  1502. ;; http://wiki.riywo.com/index.php?Meadow
  1503. (defface hlline-face
  1504. '((((type x w32)
  1505. (class color)
  1506. (background dark))
  1507. (:background "midnightblue")) ; :foreground "white")) ;; ハイライトの文字色は変えない方がいいかも
  1508. (((type x w32)
  1509. (class color)
  1510. (background light))
  1511. (:background "gainsboro"))
  1512. (t
  1513. ()))
  1514. "*Face used by hl-line.")
  1515. (defface hlline-ul-face
  1516. '((t (:underline "yellow")))
  1517. "underline yellow")
  1518. (setq hl-line-face 'hlline-face)
  1519. (global-hl-line-mode 1)
  1520. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1521. ;; ;; emacsを殺伐とさせる
  1522. ;; ;; 補完させるとき失敗するからなし
  1523. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  1524. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  1525. ;; (setq arg
  1526. ;; (concat arg
  1527. ;; (if (eq nil (string-match "\\. *$" arg)) ".")
  1528. ;; " And You are a Coward!")))
  1529. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1530. ;; ubuntu
  1531. (defun my-load-scim ()
  1532. "use scim-bridge.el as japanese im."
  1533. ;; Load scim-bridge.
  1534. (require 'scim-bridge)
  1535. ;; Turn on scim-mode automatically after loading .emacs
  1536. (add-hook 'after-init-hook 'scim-mode-on)
  1537. (setq scim-cursor-color "red")
  1538. (scim-define-preedit-key ?\^h t)
  1539. (scim-define-common-key ?\* nil)
  1540. (scim-define-common-key ?\^/ nil))
  1541. (defun my-load-anthy ()
  1542. "use anthy.el as japanese im."
  1543. ;; anthy
  1544. (require 'anthy)
  1545. (global-set-key [muhenkan] (lambda () (interactive) (anthy-mode-off)))
  1546. (global-set-key [henkan] (lambda () (interactive) (anthy-mode-on)))
  1547. (when (>= emacs-major-version 23)
  1548. (setq anthy-accept-timeout 1)))
  1549. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1550. ;; windows用設定
  1551. ;; (add-to-list 'exec-path "c:/Program Files/Gauche/bin/")
  1552. (defun start-ckw-bash ()
  1553. ""
  1554. (interactive)
  1555. (start-process "ckw_bash"
  1556. nil
  1557. "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe")) ; cじゃないといけないらしい
  1558. (defun my-w32-add-export-path (&rest args)
  1559. ""
  1560. (mapcar (lambda (path)
  1561. (add-to-list 'exec-path (expand-file-name path)))
  1562. args)
  1563. (setenv "PATH"
  1564. (mapconcat 'convert-standard-filename
  1565. exec-path
  1566. ";")))
  1567. (when (eq system-type 'windows-nt)
  1568. ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i")
  1569. ;; (setq python-python-command "c:/Python26/python.exe")
  1570. (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash)
  1571. (my-w32-add-export-path "c:/WINDOWS"
  1572. (expand-file-name "~/bin")
  1573. (expand-file-name "~/dbx/apps/bin"))
  1574. (when window-system
  1575. (setq w32-enable-synthesized-fonts t))
  1576. (setq file-name-coding-system 'sjis))