25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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