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.
 
 
 
 
 
 

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