Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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