|
From: | Gabriele Nicolardi |
Subject: | Why don't `occur`, `search-forward*` and `string-match*` respect `isearch-filter-predicate`? |
Date: | Mon, 26 Feb 2024 19:02:11 +0100 |
User-agent: | Mozilla Thunderbird |
Hi,
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 interactive, but I often find myself using functions that are not strictly interactive within functions that are.)
It make sense to open a feature request?
Best regards,
Gabriele Nicolardi
[Prev in Thread] | Current Thread | [Next in Thread] |