バッファ内を走査してregexpにマッチしたストリングのリストを返す関数
よく使うので汎用的な関数を作って、それを使うことにしました。
codereposのブランチで作業しているperl-completion.elのversion1.0で使う予定です。
(eval-when-compile (require 'cl)) (defun* plcmp-collect-matches (re &optional (count 0) (match-string-fn 'match-string) (point-min (point-min)) (point-max (point-max))) (save-excursion (loop initially (goto-char point-min) while (re-search-forward re point-max t) collect (funcall match-string-fn count))))
regexpを組み立ててから呼ぶとわかりやすいかも。
useしているモジュール収得部分から抜粋
(let ((re (rx-to-string `(and bol (* space) "use" (+ space) (group ;1 package (regexp ,plcmp-perl-package-re)) (* not-newline) ";")))) (plcmp-collect-matches re 1 'match-string-no-properties))
気になった点のメモ:
*1:pointを移動させないと無限ループになるため、多分