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#30187: M-e should restore isearch correctly in special modes Date: Sat, 20 Jan 2018 23:10:16 +0200 Organization: LINKOV.NET Message-ID: <87607wnsnb.fsf@mail.linkov.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1516484300 22223 195.159.176.226 (20 Jan 2018 21:38:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 20 Jan 2018 21:38:20 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) To: 30187@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jan 20 22:38:15 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 1ed0q5-0005OE-Qu for geb-bug-gnu-emacs@m.gmane.org; Sat, 20 Jan 2018 22:38:14 +0100 Original-Received: from localhost ([::1]:37238 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ed0s6-0004Db-2V for geb-bug-gnu-emacs@m.gmane.org; Sat, 20 Jan 2018 16:40:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53427) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ed0ru-0004CX-4I for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2018 16:40:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ed0rr-0002ZW-N8 for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2018 16:40:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:56713) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ed0rr-0002ZM-J4 for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2018 16:40:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ed0rr-0000jO-BX for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2018 16:40:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 20 Jan 2018 21:40:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 30187 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15164843832763 (code B ref -1); Sat, 20 Jan 2018 21:40:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Jan 2018 21:39:43 +0000 Original-Received: from localhost ([127.0.0.1]:36375 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ed0rW-0000iV-VE for submit@debbugs.gnu.org; Sat, 20 Jan 2018 16:39:43 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:34125) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ed0rT-0000i3-BF for submit@debbugs.gnu.org; Sat, 20 Jan 2018 16:39:39 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ed0rM-0001qv-PP for submit@debbugs.gnu.org; Sat, 20 Jan 2018 16:39:34 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:56208) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ed0rM-0001qi-Km for submit@debbugs.gnu.org; Sat, 20 Jan 2018 16:39:32 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ed0rL-00046a-6u for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2018 16:39:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ed0rI-0001lp-33 for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2018 16:39:31 -0500 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:42395 helo=homiemail-a21.g.dreamhost.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ed0rH-0001kh-PB for bug-gnu-emacs@gnu.org; Sat, 20 Jan 2018 16:39:28 -0500 Original-Received: from homiemail-a21.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a21.g.dreamhost.com (Postfix) with ESMTP id 98D221C0066 for ; Sat, 20 Jan 2018 13:39:25 -0800 (PST) Original-Received: from localhost.linkov.net (m91-129-108-180.cust.tele2.ee [91.129.108.180]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by homiemail-a21.g.dreamhost.com (Postfix) with ESMTPSA id BB8F51C0065 for ; Sat, 20 Jan 2018 13:39:24 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:142333 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable There was an old problem that =E2=80=98isearch-edit-string=E2=80=99 incor= rectly restored a previous isearch mode in such commands as =E2=80=98comint-history-isearch-backward=E2=80=99 and =E2=80=98dired-isea= rch-filenames=E2=80=99 because they let-bind variables that affects the search parameters, e.g. =E2=80=98(let ((dired-isearch-filenames t)))=E2=80=99 only at the st= arting isearch, but when =E2=80=98M-e=E2=80=99 (isearch-edit-string) exits isear= ch, and later starts again, these let-binding are not in effect and thus restore the wrong search state. All imaginable solutions were very bad. But now I found a solution that at least not bad. It changes the global value of customizable variables for the time while isearch is active (including the time when isearch is suspended temporarily), and restores the original value afterwards. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=isearch-suspended.patch diff --git a/lisp/comint.el b/lisp/comint.el index a79e34b..8dba317 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -1434,14 +1434,14 @@ comint-history-isearch (defun comint-history-isearch-backward () "Search for a string backward in input history using Isearch." (interactive) - (let ((comint-history-isearch t)) - (isearch-backward nil t))) + (setq comint-history-isearch t) + (isearch-backward nil t)) (defun comint-history-isearch-backward-regexp () "Search for a regular expression backward in input history using Isearch." (interactive) - (let ((comint-history-isearch t)) - (isearch-backward-regexp nil t))) + (setq comint-history-isearch t) + (isearch-backward-regexp nil t)) (defvar-local comint-history-isearch-message-overlay nil) @@ -1472,7 +1472,9 @@ comint-history-isearch-end (setq isearch-message-function nil) (setq isearch-wrap-function nil) (setq isearch-push-state-function nil) - (remove-hook 'isearch-mode-end-hook 'comint-history-isearch-end t)) + (remove-hook 'isearch-mode-end-hook 'comint-history-isearch-end t) + (unless isearch-suspended + (custom-reevaluate-setting 'comint-history-isearch))) (defun comint-goto-input (pos) "Put input history item of the absolute history position POS." diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 223b254..55b68a3 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -2766,7 +2766,9 @@ dired-isearch-filenames-end "Clean up the Dired file name search after terminating isearch." (define-key isearch-mode-map "\M-sff" nil) (dired-isearch-filenames-mode -1) - (remove-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end t)) + (remove-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end t) + (unless isearch-suspended + (custom-reevaluate-setting 'dired-isearch-filenames))) (defun dired-isearch-filter-filenames (beg end) "Test whether some part of the current search match is inside a file name. @@ -2779,15 +2781,15 @@ dired-isearch-filter-filenames (defun dired-isearch-filenames () "Search for a string using Isearch only in file names in the Dired buffer." (interactive) - (let ((dired-isearch-filenames t)) - (isearch-forward nil t))) + (setq dired-isearch-filenames t) + (isearch-forward nil t)) ;;;###autoload (defun dired-isearch-filenames-regexp () "Search for a regexp using Isearch only in file names in the Dired buffer." (interactive) - (let ((dired-isearch-filenames t)) - (isearch-forward-regexp nil t))) + (setq dired-isearch-filenames t) + (isearch-forward-regexp nil t)) ;; Functions for searching in tags style among marked files. diff --git a/lisp/isearch.el b/lisp/isearch.el index 3725779..b131437 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -1233,6 +1233,8 @@ isearch-new-regexp-function (define-obsolete-variable-alias 'isearch-new-word 'isearch-new-regexp-function "25.1") +(defvar isearch-suspended nil) + (defmacro with-isearch-suspended (&rest body) "Exit Isearch mode, run BODY, and reinvoke the pending search. You can update the global isearch variables by setting new values to @@ -1299,6 +1301,8 @@ with-isearch-suspended isearch-original-minibuffer-message-timeout) old-point old-other-end) + (setq isearch-suspended t) + ;; Actually terminate isearching until editing is done. ;; This is so that the user can do anything without failure, ;; like switch buffers and start another isearch, and return. @@ -1313,6 +1317,8 @@ with-isearch-suspended (unwind-protect (progn ,@body) + (setq isearch-suspended nil) + ;; Always resume isearching by restarting it. (isearch-mode isearch-forward isearch-regexp @@ -1374,6 +1380,7 @@ with-isearch-suspended (message ""))))) (quit ; handle abort-recursive-edit + (setq isearch-suspended nil) (isearch-abort) ;; outside of let to restore outside global values ))) --=-=-=--