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.
 
 
 
 
 
 

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