Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

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