0

If I consult the definition of isearch-filter-predicate, I find:

Predicate to filter hits of Isearch and replace commands. Isearch hits that don’t satisfy the predicate will be skipped.

Over the years, I have found this option very useful as it allows me to perform targeted searches and replacements in certain parts of the LaTeX documents I edit for work. For example, by creating custom predicates, I can ensure that I operate only on the mathematical part of the document, or only on cross-reference labels; I can ignore comments inserted by the authors, and so on.

Unfortunately, however, some functions such as occur, search-forward-*, string-match*, do not take this variable into account.

For some of them, I managed to create modified versions:

(defun search-forward-ifp (STRING &optional BOUND NOERROR COUNT)
  "Modified version of `search-forward` that filters (skips)
matches according to `isearch-filter-predicate'."

  (let ((POINT (point)))
    (catch 'filtered
      (while (search-forward STRING BOUND NOERROR COUNT)
        (let ((B (match-beginning 0))
              (E (match-end 0)))
          ;; 1 - If all points of the region matching the search from
          ;; the previous `search-forward` fit the criteria accepted
          ;; by the filter, then the loop stops (throw) and
          ;; returns the position `(point)`:
          (when (funcall isearch-filter-predicate B E)
            (throw 'filtered (point)))))
      ;; 2 - If the search is unsuccessful, or it doesn't fit
      ;; the criteria accepted by the filter, then return to
      ;; the starting position and return `nil`.
      (goto-char POINT)
      nil)))

However, I couldn't modify, for instance, occur and string-match(-p). Is there a reason why these functions don't adopt this mechanism? Or is it simply a lack of interest in implementing this option?

(I understand that the "i" in [i]search stands for "incremental", but I often find myself using functions that are not "incremental" but within functions that are "interactive".)

2
  • 1
    Your question is a "why" design question. You'll have better luck getting a reasonable answer at [email protected].
    – Drew
    Commented Feb 26 at 17:53
  • Thank you, I will forward this question to the indicated mailing list.
    – Gabriele
    Commented Feb 26 at 17:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.