From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#11378: 24.1.50; Suggestion: Let M-i in isearch cycle `search-invisible' Date: Tue, 24 Apr 2018 22:50:12 +0300 Organization: LINKOV.NET Message-ID: <87vacg4c5n.fsf@mail.linkov.net> References: <87haw32hly.fsf@web.de> <87397m6oxf.fsf@mail.jurta.org> <87y5pcdzxx.fsf@mail.jurta.org> <874nqzgcuk.fsf@mail.jurta.org> <87vcjesccy.fsf@mail.jurta.org> <87y5o9nobl.fsf@mail.jurta.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1524599892 13693 195.159.176.226 (24 Apr 2018 19:58:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 24 Apr 2018 19:58:12 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: michael_heerdegen@web.de, 11378@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 24 21:58:08 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fB44i-0003Nf-Lu for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Apr 2018 21:58:05 +0200 Original-Received: from localhost ([::1]:60631 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fB46p-0000gN-MO for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Apr 2018 16:00:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fB46h-0000gH-9V for bug-gnu-emacs@gnu.org; Tue, 24 Apr 2018 16:00:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fB46c-00023I-Tl for bug-gnu-emacs@gnu.org; Tue, 24 Apr 2018 16:00:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58815) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fB46c-000239-Pl for bug-gnu-emacs@gnu.org; Tue, 24 Apr 2018 16:00:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fB46c-0000pd-JH for bug-gnu-emacs@gnu.org; Tue, 24 Apr 2018 16:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Apr 2018 20:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11378 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 11378-submit@debbugs.gnu.org id=B11378.15245999483104 (code B ref 11378); Tue, 24 Apr 2018 20:00:02 +0000 Original-Received: (at 11378) by debbugs.gnu.org; 24 Apr 2018 19:59:08 +0000 Original-Received: from localhost ([127.0.0.1]:38479 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fB45j-0000o0-RJ for submit@debbugs.gnu.org; Tue, 24 Apr 2018 15:59:08 -0400 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:37845 helo=homiemail-a101.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fB45i-0000ns-47 for 11378@debbugs.gnu.org; Tue, 24 Apr 2018 15:59:06 -0400 Original-Received: from homiemail-a101.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a101.g.dreamhost.com (Postfix) with ESMTP id 80EC5117E081; Tue, 24 Apr 2018 12:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=jurta.org; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=jurta.org; bh=C7Jf9K3 oXz/Ynbl8K/LJc7XkdYI=; b=dTf70tqYltsNIuvf7kr3LaoG2YdlX9yViqyvYwt Q8ejm74q517g/V35+VlvG8B2ac4h/0+hMRPMprFPXEfu3DnY09OWNkUoYF7dwCxN /ilF6EYW90LYpoYmUBKnJKboEMJRHc/ZBO9GXvpK+mBuSVEboqUhw2nB0uvy/QS2 gFC0= Original-Received: from localhost.linkov.net (m91-129-103-238.cust.tele2.ee [91.129.103.238]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by homiemail-a101.g.dreamhost.com (Postfix) with ESMTPSA id 3490D117E06C; Tue, 24 Apr 2018 12:59:04 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Thu, 31 May 2012 17:25:28 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:145737 Archived-At: >>> I was thinking that maybe a cycling behavior would be better than >>> toggling for these: off / foo-only / foo-excluded. >> >> Maybe something like this: > > Sounds about right, thank you, Now that text proprieties on the search string can be saved in the deskto= p file, I tried to save the isearch-filter-predicate with advice-functions, and set it back to the search string, but this fails. An example of the search string saved in the search ring in the desktop f= ile: #("string" 0 6 (isearch-filter-predicate #1=3D#[128 #2=3D"\300\301\2\"\20= 5\13\0\300\302\2\"\207" [apply isearch-filter-textual #[128 #3=3D"\301\302\300!\2\"= \207" [isearch-filter-predicate apply default-value] 4 #4=3D"\n\n= (fn &rest ARGS)"] #5=3D((isearch-message-prefix . "textual "))] 4 nil])) After it's restored by desktop.el using `load' and set from the restored = string with (setq isearch-filter-predicate ...) it goes into an infinite loop: Debugger entered--Lisp error: (error "Lisp nesting exceeds =E2=80=98max-l= isp-eval-depth=E2=80=99") ... apply(#f(compiled-function (&rest args) #) (12237 1= 2244)) #f(advice-wrapper :before-while #f(compiled-function (&rest args) #) isearch-filter-nontextual ((isearch-message-prefix . "n= ontextual ")))(12237 12244) apply(#f(advice-wrapper :before-while #f(compiled-function #f(compiled-function (&rest args) #)(12237 12244) apply(#f(compiled-function (&rest args) #) (12237 1= 2244)) #f(advice-wrapper :before-while #f(compiled-function (&rest args) #) isearch-filter-nontextual ((isearch-message-prefix . "n= ontextual ")))(12237 12244) apply(#f(advice-wrapper :before-while #f(compiled-function #f(compiled-function (&rest args) #)(12237 12244) apply(#f(compiled-function (&rest args) #) (12237 1= 2244)) #f(advice-wrapper :before-while #f(compiled-function (&rest args) #) isearch-filter-nontextual ((isearch-message-prefix . "n= ontextual ")))(12237 12244) funcall(#f(advice-wrapper :before-while #f(compiled-function (not (funcall isearch-filter-predicate (nth 0 real-match-data) (nth 1 r= eal-match-data))) If it's impossible to restore its value, then maybe better to save only function names, and on restoring explicitly call add-function with restor= ed function names as symbols? A complete patch is here: diff --git a/lisp/isearch.el b/lisp/isearch.el index 5cbb4c9..70e3e44 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -1136,7 +1141,8 @@ isearch-update-ring (defun isearch-string-propertize (string &optional properties) "Add isearch properties to the isearch string." (unless properties - (setq properties `(isearch-case-fold-search ,isearch-case-fold-searc= h)) + (setq properties `(isearch-case-fold-search ,isearch-case-fold-searc= h + isearch-filter-predicate ,isearch-filter-predicat= e)) (unless isearch-regexp (setq properties (append properties `(isearch-regexp-function ,ise= arch-regexp-function))))) (apply 'propertize string properties)) @@ -1146,6 +1152,9 @@ isearch-update-from-string-properties (when (plist-member (text-properties-at 0 string) 'isearch-case-fold-s= earch) (setq isearch-case-fold-search (get-text-property 0 'isearch-case-fold-search string))) + (when (plist-member (text-properties-at 0 string) 'isearch-filter-pred= icate) + (setq isearch-filter-predicate + (get-text-property 0 'isearch-filter-predicate string))) (when (plist-member (text-properties-at 0 string) 'isearch-regexp-func= tion) (setq isearch-regexp-function (get-text-property 0 'isearch-regexp-function string)))) @@ -1640,6 +1648,38 @@ isearch--momentary-message "match invisible text" "match visible text"))) =20 +(isearch-define-mode-toggle textual "ft" nil + "This determines whether to search inside or outside textual parts. +Toggles the variable `isearch-filter-predicate' between three states: +searching inside strings or comments, searching outside of strings or +comments, the third state removes the filtering altogether." + (cond + ((advice-function-member-p #'isearch-filter-textual + isearch-filter-predicate) + (remove-function (local 'isearch-filter-predicate) + #'isearch-filter-textual) + (add-function :before-while (local 'isearch-filter-predicate) + #'isearch-filter-nontextual + '((isearch-message-prefix . "nontextual ")))) + ((advice-function-member-p #'isearch-filter-nontextual + isearch-filter-predicate) + (remove-function (local 'isearch-filter-predicate) + #'isearch-filter-nontextual)) + (t + (add-function :before-while (local 'isearch-filter-predicate) + #'isearch-filter-textual + '((isearch-message-prefix . "textual ")))))) + +(defun isearch-filter-textual (_beg _end) + "Test whether the current search hit inside a string or comment." + (save-match-data + (or (nth 3 (syntax-ppss)) + (nth 4 (syntax-ppss))))) + +(defun isearch-filter-nontextual (beg end) + "Test whether the current search hit outside a string or comment." + (not (isearch-filter-textual beg end))) + =0C ;; Word search =20 @@ -3179,6 +3219,7 @@ isearch-lazy-highlight-window-group (defvar isearch-lazy-highlight-window-start nil) (defvar isearch-lazy-highlight-window-end nil) (defvar isearch-lazy-highlight-case-fold-search nil) +(defvar isearch-lazy-highlight-filter-predicate nil) (defvar isearch-lazy-highlight-regexp nil) (defvar isearch-lazy-highlight-lax-whitespace nil) (defvar isearch-lazy-highlight-regexp-lax-whitespace nil) @@ -3218,6 +3259,8 @@ isearch-lazy-highlight-new-loop isearch-lazy-highlight-window-group)) (not (eq isearch-lazy-highlight-case-fold-search isearch-case-fold-search)) + (not (equal isearch-lazy-highlight-filter-predicate + isearch-filter-predicate)) (not (eq isearch-lazy-highlight-regexp isearch-regexp)) (not (eq isearch-lazy-highlight-regexp-function @@ -3259,6 +3302,7 @@ isearch-lazy-highlight-new-loop isearch-lazy-highlight-wrapped nil isearch-lazy-highlight-last-string isearch-string isearch-lazy-highlight-case-fold-search isearch-case-fold-search + isearch-lazy-highlight-filter-predicate isearch-filter-predicate isearch-lazy-highlight-regexp isearch-regexp isearch-lazy-highlight-lax-whitespace isearch-lax-whitespace isearch-lazy-highlight-regexp-lax-whitespace isearch-regexp-lax-white= space diff --git a/lisp/replace.el b/lisp/replace.el index 3503b65..2f297b1 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2383,7 +2383,10 @@ perform-replace ;; If non-nil, it is marker saying where in the buffer to stop. (limit nil) ;; Use local binding in add-function below. - (isearch-filter-predicate isearch-filter-predicate) + (isearch-filter-predicate + (or (and (plist-member (text-properties-at 0 from-string) 'ise= arch-filter-predicate) + (get-text-property 0 'isearch-filter-predicate from-s= tring)) + isearch-filter-predicate)) (region-bounds nil) =20 ;; Data for the next match. If a cons, it has the same format = as @@ -2395,6 +2398,15 @@ perform-replace (apply 'propertize (concat "Query replacing " (if backward "backward " "") + (if (not case-fold-search) + "case-sensitive ") + (let ((prefix "")) + (advice-function-mapc + (lambda (_ props) + (let ((np (cdr (assq 'isearch-message-= prefix props)))) + (if np (setq prefix (concat np prefi= x))))) + isearch-filter-predicate) + prefix) (if delimited-flag (or (and (symbolp delimited-flag) (get delimited-flag