From unknown Fri Jun 20 07:18:28 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#69542 <69542@debbugs.gnu.org> To: bug#69542 <69542@debbugs.gnu.org> Subject: Status: Feature request: making occur obey isearch-filter-predicate Reply-To: bug#69542 <69542@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:18:28 +0000 retitle 69542 Feature request: making occur obey isearch-filter-predicate reassign 69542 emacs submitter 69542 Gabriele Nicolardi severity 69542 wishlist thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 04 06:45:37 2024 Received: (at submit) by debbugs.gnu.org; 4 Mar 2024 11:45:37 +0000 Received: from localhost ([127.0.0.1]:42196 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rh6lE-0001lf-On for submit@debbugs.gnu.org; Mon, 04 Mar 2024 06:45:37 -0500 Received: from lists.gnu.org ([209.51.188.17]:50186) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rh6lC-0001gI-Tu for submit@debbugs.gnu.org; Mon, 04 Mar 2024 06:45:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rh6kf-000802-FL for bug-gnu-emacs@gnu.org; Mon, 04 Mar 2024 06:45:02 -0500 Received: from smtp02.cbsolt.net ([185.97.217.41]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rh6kb-0006l7-9V for bug-gnu-emacs@gnu.org; Mon, 04 Mar 2024 06:45:01 -0500 Received: from [10.0.2.15] (host-79-16-242-199.retail.telecomitalia.it [79.16.242.199]) by smtp02.cbsolt.net (Postfix) with ESMTPSA id 4TpH1G1H8zz3wbB for ; Mon, 4 Mar 2024 12:44:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cbsolt.net; s=201504-di4k2w; t=1709552691; bh=vLY9SZaq3M1s16W8tnjAfGutHaN9DH2VnOK/gluJjc0=; h=Date:To:From:Subject:From; b=URHBGVly+KQ+sbUhuiWLFRzmq97Fn3KRFxwljrbDkQdFQUl5Id/8iuwn9E9uQDEQf NeBVFaYvQNfayCL3rdW/t1mMBStoN7PvJhrc2KOf2r9mI80/mCYYHGpuM5i9z+S2hZ Thq93CMBaQrroc1jp7uur0xLKF7pJMP22sE2nObE= Content-Type: multipart/alternative; boundary="------------zrEEoRN1SeuqiwV3Q46w2Jya" Message-ID: <6071eb9a-fa15-45fb-9917-7a35c7556680@medialab.sissa.it> Date: Mon, 4 Mar 2024 12:44:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: bug-gnu-emacs@gnu.org Content-Language: en-US From: Gabriele Nicolardi Subject: Feature request: making occur obey isearch-filter-predicate Received-SPF: pass client-ip=185.97.217.41; envelope-from=gabriele@medialab.sissa.it; helo=smtp02.cbsolt.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) This is a multi-part message in MIME format. --------------zrEEoRN1SeuqiwV3Q46w2Jya Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi, I’d like occur to obey to |isearch-filter-predicate| like query-replace* and |isearch*| commands. This is an example of what I do: |(defmacro with-ifp-predicates (PREDICATES &rest body) "Allows assigning a list of predicates to the variable `isearch-filter-predicate'. | Below is an example of usage: |(with-ifp-predicates '(skip-maths skip-comments) (query-replace \"foo\" \"bar\" nil (point-min) (point-max)))" (declare (indent 1)) `(let ((isearch-filter-predicate isearch-filter-predicate)) (mapc (lambda (predicate) (add-function :before-while isearch-filter-predicate predicate)) ,PREDICATES) ,@body)) | (I always use let-binding for operations that involve |isearch-filter-predicate|.) In some cases, I would like to have something like this: |(with-ifp-predicates '(predicate1 predicate2) (save-window-excursion (occur "foo") (query-replace \"foo\" \"bar\" nil (point-min) (point-max)))) | with |occur| showing me only the strings that match the active predicates. I wrote a mail to emacs-devel@gnu.org and I have verified that others also believe that this solution would be helpful and consistent with the functioning of some other functions defined in |replace.el|. I’d also like to add this feature to the |how-many| function. I already wrote this modified version (Emacs 29.2): |(defun re-search-forward-ifp (REGEXP &optional BOUND NOERROR COUNT) "Modified version of `search-forward-regexp' that filters (skips) matches according to `isearch-filter-predicate'." (let ((POINT (point))) (catch 'filtered (while (search-forward-regexp REGEXP BOUND NOERROR COUNT) (let ((B (match-beginning 0)) (E (match-end 0))) (when (funcall isearch-filter-predicate B E) (throw 'filtered (point))))) (goto-char POINT) nil))) (defalias 'search-forward-regexp-ifp 're-search-forward-ifp) (defun how-many-ifp (regexp &optional rstart rend interactive) "Modified version of `how-many' that filters (skips) matches according to `isearch-filter-predicate'." (interactive (keep-lines-read-args "How many matches for regexp")) (save-excursion (if rstart (if rend (progn (goto-char (min rstart rend)) (setq rend (max rstart rend))) (goto-char rstart) (setq rend (point-max))) (if (and interactive (use-region-p)) (setq rstart (region-beginning) rend (region-end)) (setq rstart (point) rend (point-max))) (goto-char rstart)) (let ((count 0) (case-fold-search (if (and case-fold-search search-upper-case) (isearch-no-upper-case-p regexp t) case-fold-search))) (while (and (< (point) rend) (re-search-forward-ifp regexp rend t)) ;; Ensure forward progress on zero-length matches like "^$". (when (and (= (match-beginning 0) (match-end 0)) (not (eobp))) (forward-char 1)) (setq count (1+ count))) (when interactive (message (ngettext "%d occurrence" "%d occurrences" count) count)) count))) (defalias 'count-matches-ifp 'how-many-ifp) | Best regards, Gabriele Nicolardi ​ --------------zrEEoRN1SeuqiwV3Q46w2Jya Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi,

I’d like occur to obey to isearch-filter-predicate like query-replace* and isearch* commands.

This is an example of what I do:

(defmacro with-ifp-predicates (PREDICATES &rest body)
   "Allows assigning a list of predicates to the
 variable `isearch-filter-predicate'.

Below is an example of usage:

(with-ifp-predicates '(skip-maths skip-comments)
  (query-replace \"foo\" \"bar\" nil (point-min) (point-max)))"
  (declare (indent 1))
  `(let ((isearch-filter-predicate isearch-filter-predicate))
     (mapc (lambda (predicate)
               (add-function :before-while isearch-filter-predicate predicate))
             ,PREDICATES)
     ,@body))

(I always use let-binding for operations that involve isearch-filter-predicate.)

In some cases, I would like to have something like this:

(with-ifp-predicates '(predicate1 predicate2)
   (save-window-excursion
     (occur "foo")
     (query-replace \"foo\" \"bar\" nil (point-min) (point-max)))) 

with occur showing me only the strings that match the active predicates.

I wrote a mail to emacs-devel@gnu.org and I have verified that others also believe that this solution would be helpful and consistent with the functioning of some other functions defined in replace.el.

I’d also like to add this feature to the how-many function.

I already wrote this modified version (Emacs 29.2):


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

  (let ((POINT (point)))
    (catch 'filtered
      (while (search-forward-regexp REGEXP BOUND NOERROR COUNT)
        (let ((B (match-beginning 0))
              (E (match-end 0)))
          (when (funcall isearch-filter-predicate B E)
            (throw 'filtered (point)))))
      (goto-char POINT)
      nil)))
(defalias 'search-forward-regexp-ifp 're-search-forward-ifp)

(defun how-many-ifp (regexp &optional rstart rend interactive)
  "Modified version of `how-many' that filters (skips) matches
    according to `isearch-filter-predicate'."

  (interactive
   (keep-lines-read-args "How many matches for regexp"))
  (save-excursion
    (if rstart
        (if rend
            (progn
              (goto-char (min rstart rend))
              (setq rend (max rstart rend)))
          (goto-char rstart)
          (setq rend (point-max)))
      (if (and interactive (use-region-p))
          (setq rstart (region-beginning)
                rend (region-end))
        (setq rstart (point)
              rend (point-max)))
      (goto-char rstart))
    (let ((count 0)
          (case-fold-search
           (if (and case-fold-search search-upper-case)
               (isearch-no-upper-case-p regexp t)
             case-fold-search)))
      (while (and (< (point) rend)
                  (re-search-forward-ifp regexp rend t))
        ;; Ensure forward progress on zero-length matches like "^$".
        (when (and (= (match-beginning 0) (match-end 0))
                   (not (eobp)))
          (forward-char 1))
        (setq count (1+ count)))
      (when interactive (message (ngettext "%d occurrence"
                                           "%d occurrences"
                                           count)
                                 count))
      count)))
(defalias 'count-matches-ifp 'how-many-ifp)

Best regards,

Gabriele Nicolardi

--------------zrEEoRN1SeuqiwV3Q46w2Jya-- From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 05 11:36:12 2024 Received: (at 69542) by debbugs.gnu.org; 5 Mar 2024 16:36:12 +0000 Received: from localhost ([127.0.0.1]:48782 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhXly-0000kr-DT for submit@debbugs.gnu.org; Tue, 05 Mar 2024 11:36:11 -0500 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:41295) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhXlv-0000k7-El for 69542@debbugs.gnu.org; Tue, 05 Mar 2024 11:36:09 -0500 Received: by mail.gandi.net (Postfix) with ESMTPSA id 124F5C0007; Tue, 5 Mar 2024 16:35:09 +0000 (UTC) From: Juri Linkov To: Gabriele Nicolardi Subject: Re: bug#69542: Feature request: making occur obey isearch-filter-predicate In-Reply-To: <6071eb9a-fa15-45fb-9917-7a35c7556680@medialab.sissa.it> (Gabriele Nicolardi's message of "Mon, 4 Mar 2024 12:44:48 +0100") Organization: LINKOV.NET References: <6071eb9a-fa15-45fb-9917-7a35c7556680@medialab.sissa.it> Date: Tue, 05 Mar 2024 18:30:20 +0200 Message-ID: <86msrdnjdn.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 69542 Cc: 69542@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > I’d like occur to obey to isearch-filter-predicate like query-replace* and > isearch* commands. > > This is an example of what I do: > > (defmacro with-ifp-predicates (PREDICATES &rest body) > "Allows assigning a list of predicates to the > variable `isearch-filter-predicate'. > > Below is an example of usage: > > (with-ifp-predicates '(skip-maths skip-comments) > (query-replace \"foo\" \"bar\" nil (point-min) (point-max)))" > (declare (indent 1)) > `(let ((isearch-filter-predicate isearch-filter-predicate)) > (mapc (lambda (predicate) > (add-function :before-while isearch-filter-predicate predicate)) > ,PREDICATES) > ,@body)) > > (I always use let-binding for operations that involve > isearch-filter-predicate.) > > In some cases, I would like to have something like this: > > (with-ifp-predicates '(predicate1 predicate2) > (save-window-excursion > (occur "foo") > (query-replace \"foo\" \"bar\" nil (point-min) (point-max)))) > > with occur showing me only the strings that match the active predicates. > > I wrote a mail to emacs-devel@gnu.org and I have verified that others also > believe that this solution would be helpful and consistent with the > functioning of some other functions defined in replace.el. > > I’d also like to add this feature to the how-many function. > > I already wrote this modified version (Emacs 29.2): > > (defun re-search-forward-ifp (REGEXP &optional BOUND NOERROR COUNT) > "Modified version of `search-forward-regexp' that > filters (skips) matches according to `isearch-filter-predicate'." > > (let ((POINT (point))) > (catch 'filtered > (while (search-forward-regexp REGEXP BOUND NOERROR COUNT) > (let ((B (match-beginning 0)) > (E (match-end 0))) > (when (funcall isearch-filter-predicate B E) > (throw 'filtered (point))))) > (goto-char POINT) > nil))) > (defalias 'search-forward-regexp-ifp 're-search-forward-ifp) So you rewrote the loop from isearch-search: (while retry (setq isearch-success (isearch-search-string isearch-string nil t)) (if (or (not isearch-success) (funcall isearch-filter-predicate (match-beginning 0) (match-end 0))) (setq retry nil) But this doesn't answer the question whether and how this could affect re-search-forward in a non-hackish way. Adding an option? Not sure. > (defun how-many-ifp (regexp &optional rstart rend interactive) > "Modified version of `how-many' that filters (skips) matches > according to `isearch-filter-predicate'." > > (interactive > (keep-lines-read-args "How many matches for regexp")) > (save-excursion > (if rstart > (if rend > (progn > (goto-char (min rstart rend)) > (setq rend (max rstart rend))) > (goto-char rstart) > (setq rend (point-max))) > (if (and interactive (use-region-p)) > (setq rstart (region-beginning) > rend (region-end)) > (setq rstart (point) > rend (point-max))) > (goto-char rstart)) > (let ((count 0) > (case-fold-search > (if (and case-fold-search search-upper-case) > (isearch-no-upper-case-p regexp t) > case-fold-search))) > (while (and (< (point) rend) > (re-search-forward-ifp regexp rend t)) > ;; Ensure forward progress on zero-length matches like "^$". > (when (and (= (match-beginning 0) (match-end 0)) > (not (eobp))) > (forward-char 1)) > (setq count (1+ count))) > (when interactive (message (ngettext "%d occurrence" > "%d occurrences" > count) > count)) > count))) > (defalias 'count-matches-ifp 'how-many-ifp) I think duplicating the whole body of functions is not better than using advice. An alternative would be to add a new variable 're-search-forward-function' and then to use it like '(funcall re-search-forward-function)'. From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 05 12:12:26 2024 Received: (at 69542) by debbugs.gnu.org; 5 Mar 2024 17:12:26 +0000 Received: from localhost ([127.0.0.1]:48869 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhYL0-0004Zn-Gz for submit@debbugs.gnu.org; Tue, 05 Mar 2024 12:12:26 -0500 Received: from smtp05.cbsolt.net ([185.97.217.44]:44380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhYKv-0004ZX-Gx for 69542@debbugs.gnu.org; Tue, 05 Mar 2024 12:12:21 -0500 Received: from [10.0.2.15] (host-79-16-242-199.retail.telecomitalia.it [79.16.242.199]) by smtp05.cbsolt.net (Postfix) with ESMTPSA id 4Tq2Cv5sQtz3wfg; Tue, 5 Mar 2024 18:11:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cbsolt.net; s=201504-di4k2w; t=1709658701; bh=eIlXfByBNEMl3WxVbnT7BYgNoeK1dlLfUQU19b9TJhs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=J0v9hwApmT9KjzAfjBryO08/j9Voi6MHot6n8Wt3ETNunCfP5m4DAz+U17Gm4MTBR TPcNgGKPuu+FdDSz9MqBEJu/YPYCGQmALa1ysvDLV4qRzOOHGkpbuHu8reXqryNEeQ quu5bhSk+nXb7bk/+L4/DQkOGea9MPosxv5O4o8A= Content-Type: multipart/alternative; boundary="------------iVWKVnOq03f7hFV9tkDybpPV" Message-ID: Date: Tue, 5 Mar 2024 18:11:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#69542: Feature request: making occur obey isearch-filter-predicate Content-Language: en-US To: Juri Linkov References: <6071eb9a-fa15-45fb-9917-7a35c7556680@medialab.sissa.it> <86msrdnjdn.fsf@mail.linkov.net> From: Gabriele Nicolardi In-Reply-To: <86msrdnjdn.fsf@mail.linkov.net> X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 69542 Cc: 69542@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) This is a multi-part message in MIME format. --------------iVWKVnOq03f7hFV9tkDybpPV Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit > I think duplicating the whole body of functions is not better > than using advice. Until yesterday, I had no idea how to advise a function. Now I'm experimenting with this code to obtain modified versions of |occur| and |how-many| that are sensitive to |isearch-filter-predicate|. I'm not a programmer, so my code may not be very rigorous: ;; I need a copy of `re-search-forward' because it will be temporary adviced in ;; `how-many-ifp' and `occur-ifp' functions: (defalias 're-search-forward-copy   (symbol-function 're-search-forward)   "Copy of `re-search-forward'") (defun re-search-forward-ifp (REGEXP &optional BOUND NOERROR COUNT)   "Modified version of `search-forward-regexp' that filters (skips) matches according to `isearch-filter-predicate'."   (let ((POINT (point)))     (catch 'filtered       (while (re-search-forward-copy REGEXP BOUND NOERROR COUNT)         (let ((B (match-beginning 0))               (E (match-end 0)))           (when (funcall isearch-filter-predicate B E)             (throw 'filtered (point)))))       (goto-char POINT)       nil))) (defalias 'search-forward-regexp-ifp 're-search-forward-ifp) (defun override-re-search-forward (orig-fun &rest args)   "Temporary advice the `re-search-forward' function, overriding it with `re-search-forward-ifp' to make it sensitive to `isearch-filter-predicate'"   (unwind-protect       (progn         (advice-add 're-search-forward :override #'re-search-forward-ifp)         (apply orig-fun args))     (advice-remove 're-search-forward #'re-search-forward-ifp))) (defalias 'how-many-ifp   (symbol-function 'how-many)   "Copy of the `how-many' function (to be) adviced to obey to `isearch-filter-predicate'") (defalias 'count-matches-ifp 'how-many-ifp) (advice-add 'how-many-ifp :around #'override-re-search-forward) (defalias 'occur-ifp   (symbol-function 'occur)   "Copy of the `occur' function (to be) adviced to obey to  `isearch-filter-predicate'") (advice-add 'occur-ifp :around #'override-re-search-forward) The key is the `re-search-forward` function used in `how-many` and `occur` definition. If you make it sensible to `isearch-filter-predicate` also `how-many` and `occur` will be. I don't know if advicing a function to advice a function inside it is a good idea but it seem to work (I need more tests). Now I discovered how to build these functions I could be fine with my modified ones, but making this feature avaible (maybe not default) in the original functions could be a better idea. > An alternative would be to add a new variable > 're-search-forward-function' and then to use it like > '(funcall re-search-forward-function)'. The idea of a new function seems good to me. --------------iVWKVnOq03f7hFV9tkDybpPV Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
I think duplicating the whole body of functions is not better
than using advice. 

Until yesterday, I had no idea how to advise a function.

Now I'm experimenting with this code to obtain modified versions of occur and how-many that are sensitive to isearch-filter-predicate.

I'm not a programmer, so my code may not be very rigorous:

;; I need a copy of `re-search-forward' because it will be temporary adviced in
;; `how-many-ifp' and `occur-ifp' functions:
(defalias 're-search-forward-copy
  (symbol-function 're-search-forward)
  "Copy of `re-search-forward'")

(defun re-search-forward-ifp (REGEXP &optional BOUND NOERROR COUNT)
  "Modified version of `search-forward-regexp' that filters (skips) matches
according to `isearch-filter-predicate'."
  (let ((POINT (point)))
    (catch 'filtered
      (while (re-search-forward-copy REGEXP BOUND NOERROR COUNT)
        (let ((B (match-beginning 0))
              (E (match-end 0)))
          (when (funcall isearch-filter-predicate B E)
            (throw 'filtered (point)))))
      (goto-char POINT)
      nil)))
(defalias 'search-forward-regexp-ifp 're-search-forward-ifp)

(defun override-re-search-forward (orig-fun &rest args)
  "Temporary advice the `re-search-forward' function, overriding it with
`re-search-forward-ifp' to make it sensitive to `isearch-filter-predicate'"
  (unwind-protect
      (progn
        (advice-add 're-search-forward :override #'re-search-forward-ifp)
        (apply orig-fun args))
    (advice-remove 're-search-forward #'re-search-forward-ifp)))

(defalias 'how-many-ifp
  (symbol-function 'how-many)
  "Copy of the `how-many' function (to be) adviced to obey to
`isearch-filter-predicate'")
(defalias 'count-matches-ifp 'how-many-ifp)

(advice-add 'how-many-ifp :around #'override-re-search-forward)

(defalias 'occur-ifp
  (symbol-function 'occur)
  "Copy of the `occur' function (to be) adviced to obey to
 `isearch-filter-predicate'")

(advice-add 'occur-ifp :around #'override-re-search-forward)

The key is the `re-search-forward` function used in `how-many` and `occur` definition. If you make it sensible to `isearch-filter-predicate` also `how-many` and `occur` will be.

I don't know if advicing a function to advice a function inside it is a good idea but it seem to work (I need more tests).

Now I discovered how to build these functions I could be fine with my modified ones, but making this feature avaible (maybe not default) in the original functions could be a better idea.

 An alternative would be to add a new variable
're-search-forward-function' and then to use it like
'(funcall re-search-forward-function)'.

The idea of a new function seems good to me.


--------------iVWKVnOq03f7hFV9tkDybpPV-- From debbugs-submit-bounces@debbugs.gnu.org Wed Mar 06 12:49:50 2024 Received: (at 69542) by debbugs.gnu.org; 6 Mar 2024 17:49:50 +0000 Received: from localhost ([127.0.0.1]:51353 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhvOo-0005EI-0T for submit@debbugs.gnu.org; Wed, 06 Mar 2024 12:49:50 -0500 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:50427) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhvOn-0005DO-0F for 69542@debbugs.gnu.org; Wed, 06 Mar 2024 12:49:49 -0500 Received: by mail.gandi.net (Postfix) with ESMTPSA id DF0B1E0009; Wed, 6 Mar 2024 17:48:51 +0000 (UTC) From: Juri Linkov To: Gabriele Nicolardi Subject: Re: bug#69542: Feature request: making occur obey isearch-filter-predicate In-Reply-To: (Gabriele Nicolardi's message of "Tue, 5 Mar 2024 18:11:37 +0100") Organization: LINKOV.NET References: <6071eb9a-fa15-45fb-9917-7a35c7556680@medialab.sissa.it> <86msrdnjdn.fsf@mail.linkov.net> Date: Wed, 06 Mar 2024 19:47:50 +0200 Message-ID: <86plw7xp5t.fsf@mail.linkov.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain X-GND-Sasl: juri@linkov.net X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 69542 Cc: 69542@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > An alternative would be to add a new variable > 're-search-forward-function' and then to use it like > '(funcall re-search-forward-function)'. > > The idea of a new function seems good to me. Indeed, and this will require only a simple change in 'how-many' and other functions to replace such calls (re-search-forward regexp rend t) with (funcall re-search-forward-function regexp rend t) From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 08 18:10:42 2024 Received: (at 69542) by debbugs.gnu.org; 8 Mar 2024 23:10:42 +0000 Received: from localhost ([127.0.0.1]:59931 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rijMQ-0004xh-9C for submit@debbugs.gnu.org; Fri, 08 Mar 2024 18:10:42 -0500 Received: from smtp03.cbsolt.net ([185.97.217.42]:45400) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rijMM-0004xP-Ml for 69542@debbugs.gnu.org; Fri, 08 Mar 2024 18:10:40 -0500 Received: from [10.0.2.15] (host-79-45-241-136.retail.telecomitalia.it [79.45.241.136]) by smtp03.cbsolt.net (Postfix) with ESMTPSA id 4Ts21z4gCHz3wc3; Sat, 9 Mar 2024 00:09:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cbsolt.net; s=201504-di4k2w; t=1709939400; bh=cEgMOQzs5S/8aW/7urrmjCTVRVyPNKWBBJCYTunfkWo=; h=Date:Subject:From:To:Cc:References:In-Reply-To:From; b=V7oV+bl8mwuqkKWnq86fdAUyIu4XzKnPmlVHzjJhlnR9EGvtNP3MuFWEugFy6RwLG tsVj+CfOhHyf+5XnlsZcn78SHTiSgi4O/9TTzP5xrPjlGrAO5ZN1odT27/tybKYD5k VOXMqGg1+tGuXAcBkvJ91kgj7Tgh/5l0xBnxdXgw= Content-Type: multipart/alternative; boundary="------------HDa1MdMkPTE8nCKCJjHCTz5J" Message-ID: <1a877643-e543-433d-8ab2-acbe914d17a6@medialab.sissa.it> Date: Sat, 9 Mar 2024 00:09:58 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#69542: Feature request: making occur obey isearch-filter-predicate Content-Language: en-US From: Gabriele Nicolardi To: Juri Linkov References: <6071eb9a-fa15-45fb-9917-7a35c7556680@medialab.sissa.it> <86msrdnjdn.fsf@mail.linkov.net> In-Reply-To: X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 69542 Cc: 69542@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) This is a multi-part message in MIME format. --------------HDa1MdMkPTE8nCKCJjHCTz5J Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Il 05/03/24 18:11, Gabriele Nicolardi ha scritto: >> I think duplicating the whole body of functions is not better >> than using advice. > > Until yesterday, I had no idea how to advise a function. > > I don't know if advicing a function to advice a function inside it is > a good idea but it seem to work (I need more tests). > > Now I discovered how to build these functions I could be fine with my > modified ones, but making this feature avaible (maybe not default) in > the original functions could be a better idea > I found that advicing the |occur| and |how-many| function, overriding the |re-search-forward| function with my modified version of it (sensitive to |isearch-filter-predicate|) it’s not good at all. That because some predicates, like e.g. |texmathp| provided by AUCTeX, use |re-search-forward| too. > . > >> An alternative would be to add a new variable >> 're-search-forward-function' and then to use it like >> '(funcall re-search-forward-function)'. > > The idea of a new function seems good to me. > > ​ --------------HDa1MdMkPTE8nCKCJjHCTz5J Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Il 05/03/24 18:11, Gabriele Nicolardi ha scritto:

I think duplicating the whole body of functions is not better
than using advice. 

Until yesterday, I had no idea how to advise a function.

I don't know if advicing a function to advice a function inside it is a good idea but it seem to work (I need more tests).

Now I discovered how to build these functions I could be fine with my modified ones, but making this feature avaible (maybe not default) in the original functions could be a better idea

I found that advicing the occur and how-many function, overriding the re-search-forward function with my modified version of it (sensitive to isearch-filter-predicate) it’s not good at all.

That because some predicates, like e.g. texmathp provided by AUCTeX, use re-search-forward too.

.

 An alternative would be to add a new variable
're-search-forward-function' and then to use it like
'(funcall re-search-forward-function)'.

The idea of a new function seems good to me.


--------------HDa1MdMkPTE8nCKCJjHCTz5J--