anything.elが複数行対応になった

anything.elは通常、複数行ある候補を扱えなかったのだが、今回のリリースから複数行文字列も扱えるようになった。
Matsuyamaさん、パッチどうもありがとう。

http://www.emacswiki.org/cgi-bin/wiki/download/anything.elからどうぞ。

anythingの候補は文字列リストを操作する。文字列リストは複数行あろうがお構いなしのデータ構造なので意味のある改良となっている。ただ、より高速なcandidates-in-bufferは1行が候補になるので対応していない。get-line関数をゴリゴリ書けば可能かもしれないが。

複数行対応にするには、sourceに(multiline)と入れるのみ。

(defvar anything-c-source-kill-ring
    '((name . "Kill Ring")
      (candidates . (lambda ()
                      (loop for kill in kill-ring
                            unless (string-match "^[\\s\\t]+$" kill)
                            collect kill)))
      (action . insert)
      (migemo)
      (multiline)))

(anything 'anything-c-source-kill-ring)
を実行時の*anything*バッファはこんな感じに「--------------------」で区切られる。

Kill Ring
      (get-line . (lambda (start end)
                    (let ((line (buffer-substring start end)))

--------------------
      (action . (("Jump" . (lambda (cand)
                             (goto-char (1- (get-text-property 0 'position cand))))) ))))

--------------------
  (defvar anything-c-source-occur
    '((name . "Occur")
      (init . (lambda ()
                (if (anything-current-buffer-is-modified)
                    (anything-candidate-buffer anything-current-buffer))))
      (candidates-in-buffer)
      (get-line . (lambda (start end)
                    (let ((line (buffer-substring start end)))
                      (put-text-property 0 (length line) 'position (match-beginning 0) line)
                      line)))
      (action . (("Jump" . (lambda (cand)
                             (goto-char (1- (get-text-property 0 'position cand)))))))))


--------------------
  ;; kill ring
  (defvar anything-c-kill-ring-threshold 10)

その他の改良点