Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

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