Emacs 再び

半年程Vimを使っていたが、気になっていたプラグインの使い勝手を試したくてゼロからEmacs環境を作った


拡張

  • anything
  • autoinsert
  • auto-complete
  • auto-install
  • color-moccur
  • elscreen
  • jaunte
  • multiterm
  • simple-hatena
  • undo-tree
  • vimpulse
  • yasnippet
  • zencoding

vimpulse + jaute + elscreen + anything で、かなり vimperator っぽくなった
hit-a-hintできるjaunteかなり素敵。キーバインドはもう vim じゃないと生きて行けないんだが、vimpulse のおかげでかなり忠実な挙動をする
vimのpathogenの管理が楽だったので、基本 ~/.emacs.d/plugin/ 以下に拡張ごとのディレクトリ掘って汚染しないようにした
再帰的に読み込むには以下のようにする

(let ((default-directory "~/.emacs.d/plugin/"))
    (setq load-path (cons default-directory load-path))
    (normal-top-level-add-subdirs-to-load-path))

が、auto-install で突っ込んだ拡張はバラバラに展開されるのでauto-install依存のものは諦めた

以下設定 vimpulse の設定
参考:vimpulseとanythingを使う設定とか - *iroi*

; vimpulse
(setq viper-mode t)
(setq backup-inhibited t)
(require 'vimpulse)
(setq vimpulse-cjk-want-japanese-phrase-as-word t)
(require 'vimpulse-cjk)
(defun vimpulse-set-mode-line-face ()
  (unless (minibufferp (current-buffer))
    (set-face-background 'mode-line
                         (cdr (assq viper-current-state
                                    '((vi-state       . "Black")
                                      (insert-state   . "Red")
                                      (emacs-state    . "Wheat")
                                      (operator-state . "Green")
                                      (visual-state   . "Blue")))))))

(add-hook 'viper-vi-state-hook    'vimpulse-set-mode-line-face)
(setq visible-bell nil)
(add-hook 'viper-insert-state-hook      'vimpulse-set-mode-line-face)
(add-hook 'viper-emacs-state-hook       'vimpulse-set-mode-line-face)
(add-hook 'vimpulse-operator-state-hook 'vimpulse-set-mode-line-face)
(add-hook 'vimpulse-visual-state-hook   'vimpulse-set-mode-line-face)
(defadvice set-buffer (after vimpulse-mode-line-face activate)
  (vimpulse-set-mode-line-face))
(defadvice find-file (after vimpulse-mode-line-face activate)
  (vimpulse-set-mode-line-face))
(defadvice kill-buffer (after vimpulse-mode-line-face activate)
  (vimpulse-set-mode-line-face))
(defadvice switch-to-buffer (after vimpulse-mode-line-face activate)
  (vimpulse-set-mode-line-face))
(defadvice select-window (after vimpulse-mode-line-face activate)
  (vimpulse-set-mode-line-face))
(defadvice delete-window (after vimpulse-mode-line-face activate)
  (vimpulse-set-mode-line-face))	


; comibinate with anything
(defun my-minibuffer-minor-mode ()
  (when (fboundp my-minibuffer-minor-mode)
    (funcall (symbol-function my-minibuffer-minor-mode))))
(add-hook 'minibuffer-setup-hook 'my-minibuffer-minor-mode)
;;(add-hook 'minibuffer-exit-hook 'my-minibuffer-minor-mode)
(defadvice anything (around set-major-mode activate)
  (let ((my-minibuffer-minor-mode 'my-anything-minibuffer-mode))
    ad-do-it))
(easy-mmode-define-minor-mode
 my-anything-minibuffer-mode
 "Anything MiniBuffer Mode"
 nil
 " Anything MiniBuffer"
 '())
(vimpulse-map ";" 'viper-ex)
(vimpulse-map ":" 'anything-M-x)
(vimpulse-map "?" 'describe-bindings)
(vimpulse-map "l" 'forward-char)
(vimpulse-map "h" 'backward-char)
(vimpulse-map "F" 'find-file)
(vimpulse-map "f" 'jaunte)
(vimpulse-map "m" 'hs-toggle-hiding)
(vimpulse-map "M" 'my-toggle-hideshow-all)
(vimpulse-map " " 'anything)
(vimpulse-map "\C-r" 'anything-recentf)
(vimpulse-map "\C-y" 'yas/insert-snippet)
(vimpulse-map "\C-j" 'yafastnav-jump-to-forward)
(vimpulse-map "b" '(lambda ()
                     (interactive)
                     (anything 'anything-c-source-elscreen)
	))

(vimpulse-map "!" '(lambda ()
                     (interactive)
                     (anything 'anything-c-source-shell-command)
	))

(vimpulse-map "\C-s" 'anything-c-moccur-occur-by-moccur) ;バッファ内検索
(vimpulse-map "td" 'elscreen-kill)
(vimpulse-map "tt" '(lambda ()
                     (interactive)
		     (elscreen-create)
		     (anything-recentf)
	))
(vimpulse-map "H" 'elscreen-previous)
(vimpulse-map "L" 'elscreen-next)
(define-key viper-minibuffer-map "\C-g" 'keyboard-escape-quit)
(define-key viper-insert-global-user-map "\C-g" 'viper-exit-insert-state)
(define-key viper-insert-global-user-map "\C-h" 'delete-backward-char)
(define-key viper-insert-global-user-map "\C-b" 'backward-char)
(define-key viper-insert-global-user-map "\C-f" 'forward-char)
(define-key viper-insert-global-user-map "\C-n" 'next-line)
(define-key viper-insert-global-user-map "\C-p" 'previous-line)
(define-key viper-insert-global-user-map "\C-a" 'move-beginning-of-line)
(define-key viper-insert-global-user-map "\C-e" 'end-of-line)
(define-key viper-insert-global-user-map "\C-h" 'delete-backward-char)
(define-key viper-insert-global-user-map "\C-i" 'yas/expand)
(define-key viper-insert-global-user-map "\C-y" 'yas/insert-snippet)
(define-key vimpulse-visual-basic-map "v" 'end-of-line)
(define-key vimpulse-visual-basic-map ";" 'comment-dwim)

(vimpulse-define-key 'my-anything-minibuffer-mode 'insert-state "\C-n" 'anything-next-line)
(vimpulse-define-key 'my-anything-minibuffer-mode 'insert-state "\C-p" 'anything-previous-line)
(vimpulse-define-key 'my-anything-minibuffer-mode 'insert-state "\C-f" 'anything-next-page)
(vimpulse-define-key 'my-anything-minibuffer-mode 'insert-state "\C-b" 'anything-previous-page)
(vimpulse-define-key 'my-anything-minibuffer-mode 'insert-state "\C-l" 'anything-force-update)
(vimpulse-define-key 'my-anything-minibuffer-mode 'vi-state "o" 'anything-follow-mode)
(vimpulse-define-key 'my-anything-minibuffer-mode 'vi-state "j" 'anything-next-line)
(vimpulse-define-key 'my-anything-minibuffer-mode 'vi-state "k" 'anything-previous-line)
(vimpulse-define-key 'my-anything-minibuffer-mode 'vi-state "\C-f" 'anything-next-page)
(vimpulse-define-key 'my-anything-minibuffer-mode 'vi-state "\C-b" 'anything-previous-page)
(vimpulse-define-key 'my-anything-minibuffer-mode 'vi-state "\C-l" 'anything-force-update)
(vimpulse-define-key 'my-anything-minibuffer-mode 'vi-state "}" 'anything-next-source)
(vimpulse-define-key 'my-anything-minibuffer-mode 'vi-state "{" 'anything-previous-source)
(vimpulse-define-key 'my-anything-minibuffer-mode 'vi-state "gg" 'anything-beginning-of-buffer)
(vimpulse-define-key 'my-anything-minibuffer-mode 'vi-state "G" 'anything-end-of-buffer)
(vimpulse-define-key 'my-anything-minibuffer-mode 'vi-state "/" 'anything-isearch)