anything.el を終了せずにアクションを実行する方法
anything.el はとても便利だが、通常の anything はアクションを実行したら*Anything*バッファが消えてしまう。たとえば、 anything.el でマニュアルを参照する 場合は絞り込んだ候補を次々と見たいものである。以下のコマンドを定義すれば、 anything 実行中に C-z を押せば anything を終了せずにアクションを実行できる。マニュアル参照以外にも、ファイルを「チラ見」するときも便利だ。チラ見ウィンドウのスクロールは通常の C-M-v で実行できる。チラ見し終わったら C-g で anything を強制終了すれば元々の画面( window-configuration )に戻る。
source に persistent-action 属性が設定できる。それは、 C-z を押したときに実行される関数だ。指定しなければ、 action 属性の先頭が実行される。
こんな感じになる→ http://www.rubyist.net/~rubikitch/archive/persistent-action.jpg
(defun anything-execute-persistent-action () "If a candidate was selected then perform the associated action without quitting anything." (interactive) (save-selected-window (select-window (get-buffer-window anything-buffer)) (select-window (setq minibuffer-scroll-window (if (one-window-p t) (split-window) (next-window (selected-window) 1)))) (let* ((anything-window (get-buffer-window anything-buffer)) (selection (if anything-saved-sources ;; the action list is shown anything-saved-selection (anything-get-selection))) (default-action (anything-get-action)) (action (assoc-default 'persistent-action (anything-get-current-source)))) (setq action (or action default-action)) (if (and (listp action) (not (functionp action))) ; lambda ;; select the default action (setq action (cdar action))) (set-window-dedicated-p anything-window t) (unwind-protect (and action selection (funcall action selection)) (set-window-dedicated-p anything-window nil))))) (define-key anything-map "\C-z" 'anything-execute-persistent-action)