persistent-actionで一時メッセージを表示してみるテスト
範囲内で文字を書き換えてスクロールのように見せる - asdfではanything.elのヘッダを常に見せようと格闘しているようだ。けど、むしろ新しいoverlayを導入してそこに一時メッセージを表示させたほうがいい気がする。
(defvar anything-c-source-persistent-action-overlay-test '((name . "test") (candidates . (lambda () (loop for i from 1 to 30 collect (int-to-string i)))) (persistent-action . anything-c-source-persistent-action-overlay-test-doit) (cleanup . anything-c-source-persistent-action-overlay-test-delete-overlay))) (defvar anything-persistent-action-overlay nil) (defun anything-c-source-persistent-action-overlay-test-delete-overlay () (and anything-persistent-action-overlay (delete-overlay anything-persistent-action-overlay))) (defun anything-c-source-persistent-action-overlay-test-doit (cand) (with-anything-window (anything-c-source-persistent-action-overlay-test-delete-overlay) (save-excursion (goto-char (window-start)) (setq anything-persistent-action-overlay (make-overlay (point-at-bol) (1+ (point-at-eol)))) (overlay-put anything-persistent-action-overlay 'face 'highlight) (overlay-put anything-persistent-action-overlay 'display (concat "<<<<" cand ">>>>" "\n" "((((" cand "))))" "\n"))) (message cand))) ;; (anything 'anything-c-source-persistent-action-overlay-test)
これは数字の候補でpersistent-actionを実行すると画面上部にメッセージを表示する実験的なコード。overlayが乗っている候補の上にカーソルが行くと見えなくなるから、anything-move-selectionも書き換える必要がある。さらに、move-overlayを使うべき。まあとりあえずさっと書いてみた。
anything-c-source-buffers2は気に入ったので設定に加えておいた^^
anything-c-source-bmをさらに改造
Visible Bookmarks 用 anything-source - プログラム番長のヲボエガキ
anything-c-source-bmはMatsuyamaさん作です:-)
このままだと出現順に並ばないのでsortしておいた。sort*に:keyキーワードをつけるとそこに指定されたものが基準にソートされる。rubyでいうEnumerable#sort_by。
candidates-in-buffer をつかうならばリストを作成する必要はなくなる。リストを作成するならば従来通りcandidatesを設定したほうが簡潔になる。
(defvar anything-c-source-bm '((name . "Visible Bookmarks") (init . anything-c-source-bm-init) (candidates-in-buffer) (action . (("Goto line" . (lambda (candidate) (goto-line (string-to-number candidate)))))))) (defun anything-c-source-bm-init () (let ((bookmarks (bm-lists)) (buf (anything-candidate-buffer 'global))) (dolist (bm (sort* (append (car bookmarks) (cdr bookmarks)) '< :key 'overlay-start)) (let ((start (overlay-start bm)) (end (overlay-end bm)) (annotation (or (overlay-get bm 'annotation) ""))) (unless (< (- end start) 1) ; org => (if (< (- end start) 2) (let ((str (format "%7d: [%s]: %s\n" (line-number-at-pos start) annotation (buffer-substring start (1- end))))) (with-current-buffer buf (insert str))))))))