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.
 
 
 
 
 
 

1930 lines
68 KiB

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