You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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