Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

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