読者です 読者をやめる 読者になる 読者になる

*iroi*

mechairoi の Blog

vimpulseとanythingを使う設定とか

emacs vimpulse anything

vimpulseを使っているとanythingとかでminibufferに入ったときにinsert-stateになっててC-nとかC-zが使えなくて悲しいのでなんとかしてみた.

vimpulseはvimpulse-define-keyでmodeのkeybindを拡張できるようなのでまずminibufferにminor-modeをつける. よくわからないがこんな感じのをminibuffer-setup-hookに追加する.

;; ---- minibuffer with minor mode ----
(defvar my-minibuffer-minor-mode nil)
(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)

これで minibuffer-minor-modeにminor-modeを入れとくとminibufferに入ったときにminor-modeがonになる.

(minor-modeがもともとonになってるとoffになってしまうがあまり気にならない? exit-hookでoffにした方がよいと思ったんですが無いほうが良さそうです.)

さらに専用のminor-modeを作って、anythingを呼ぶときにadviceでmy-mininbuffer-minor-modeをセットする.

;; --- anything minibuffer 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"
 '())

これでanythingからminibufferに入ったときにminor-modeがonになってるはず. あとはdefine-keyするだけで, vi-stateも使えてうはうはである.

(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)

minibufferに入ったらanything-follow-modeするとか,
anything-*-from-here的なのは即vi-stateにするとかもしている.

(defvar anything-follow-mode-flag nil)
(defvar anything-with-vi-state nil)
(add-hook 'minibuffer-setup-hook
          (lambda ()
            (when anything-follow-mode-flag (anything-follow-mode))
            (when anything-with-vi-state (viper-change-state-to-vi))) t)
(defadvice anything-for-lines-from-here (around anything-auto-follow-mode activate)
  (let ((anything-follow-mode-flag t)
        (anything-with-vi-state t))
    ad-do-it))

elispはどう書くのがいいのかよくわからないな..