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.
 
 
 
 
 
 

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