all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Why don't `occur`, `search-forward*` and `string-match*` respect `isearch-filter-predicate`?
@ 2024-02-26 18:02 Gabriele Nicolardi
  2024-02-28 14:06 ` Basil L. Contovounesios
  0 siblings, 1 reply; 8+ messages in thread
From: Gabriele Nicolardi @ 2024-02-26 18:02 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2040 bytes --]

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

​

[-- Attachment #2: Type: text/html, Size: 9579 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-03-04 14:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-26 18:02 Why don't `occur`, `search-forward*` and `string-match*` respect `isearch-filter-predicate`? Gabriele Nicolardi
2024-02-28 14:06 ` Basil L. Contovounesios
2024-02-28 14:18   ` Alfred M. Szmidt
2024-02-28 14:24   ` Gabriele Nicolardi
2024-02-28 16:53     ` [External] : " Drew Adams
2024-02-28 17:19       ` Gabriele Nicolardi
2024-02-29 17:47   ` Juri Linkov
2024-03-04 14:44     ` Gabriele Nicolardi

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.