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#22479: 25.0.50; isearch and query-replace histories do not remember if we were looking for symbols Date: Mon, 12 Mar 2018 23:43:54 +0200 Organization: LINKOV.NET Message-ID: <87bmftotph.fsf@mail.linkov.net> References: <87zivq8xp2.fsf@secretsauce.net> <87r3h2boyj.fsf@mail.linkov.net> <89D2C9D3-7CA3-49A8-9BFC-CE455C91A8A8@secretsauce.net> <87io2apqad.fsf@mail.linkov.net> <87k2mk3orm.fsf@secretsauce.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1520891897 28316 195.159.176.226 (12 Mar 2018 21:58:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 12 Mar 2018 21:58:17 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: 22479@debbugs.gnu.org To: Dima Kogan Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Mar 12 22:58:13 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 1evVSO-0007E9-Oi for geb-bug-gnu-emacs@m.gmane.org; Mon, 12 Mar 2018 22:58:12 +0100 Original-Received: from localhost ([::1]:35686 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evVUR-0002Ie-L3 for geb-bug-gnu-emacs@m.gmane.org; Mon, 12 Mar 2018 18:00:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evVUH-0002ED-5x for bug-gnu-emacs@gnu.org; Mon, 12 Mar 2018 18:00:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evVUC-0005Gx-1v for bug-gnu-emacs@gnu.org; Mon, 12 Mar 2018 18:00:09 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49848) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evVUB-0005GH-Os for bug-gnu-emacs@gnu.org; Mon, 12 Mar 2018 18:00:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1evVUB-00051D-H0 for bug-gnu-emacs@gnu.org; Mon, 12 Mar 2018 18:00:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Mar 2018 22:00:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22479 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22479-submit@debbugs.gnu.org id=B22479.152089195619171 (code B ref 22479); Mon, 12 Mar 2018 22:00:03 +0000 Original-Received: (at 22479) by debbugs.gnu.org; 12 Mar 2018 21:59:16 +0000 Original-Received: from localhost ([127.0.0.1]:57740 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evVTP-0004z9-Vy for submit@debbugs.gnu.org; Mon, 12 Mar 2018 17:59:16 -0400 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:47908 helo=homiemail-a15.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1evVTO-0004yz-3O for 22479@debbugs.gnu.org; Mon, 12 Mar 2018 17:59:14 -0400 Original-Received: from homiemail-a15.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a15.g.dreamhost.com (Postfix) with ESMTP id E2C5D76C06B; Mon, 12 Mar 2018 14:59:12 -0700 (PDT) Original-Received: from localhost.linkov.net (m91-129-108-46.cust.tele2.ee [91.129.108.46]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by homiemail-a15.g.dreamhost.com (Postfix) with ESMTPSA id D315276C065; Mon, 12 Mar 2018 14:59:11 -0700 (PDT) In-Reply-To: <87k2mk3orm.fsf@secretsauce.net> (Dima Kogan's message of "Wed, 03 Feb 2016 23:42:21 -0800") 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:144161 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >> Yes, this is a harder problem. We have to remember meta-data for >> every search history element. There are several possibilities: >> >> 4. Adding meta-data by text-properties to the strings in >> =E2=80=98search-ring=E2=80=99 and =E2=80=98regexp-search-ring=E2=80= =99 poses a problem of saving >> the values in the desktop and restoring in another session. > > This feels like the best solution. I looked at desktop.el, and it > doesn't save the properties, as you say. But it could be made to. Do yo= u > think some external packages would get broken by this change? This seems to be the least radical change as concluded in https://lists.gnu.org/archive/html/emacs-devel/2018-03/msg00296.html The patch makes the search mode to be remembered in isearch as well as in query-replace. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=isearch-text-properties.2.patch diff --git a/lisp/isearch.el b/lisp/isearch.el index 84b121a..56a44d8 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -1103,7 +1111,9 @@ isearch-done (if (and (> (length isearch-string) 0) (not nopush)) ;; Update the ring data. - (isearch-update-ring isearch-string isearch-regexp)) + (isearch-update-ring isearch-string isearch-regexp + `(regexp-function ,isearch-regexp-function + case-fold-search ,isearch-case-fold-search))) (let ((isearch-mode-end-hook-quit (and nopush (not edit)))) (run-hooks 'isearch-mode-end-hook)) @@ -1119,13 +1129,14 @@ isearch-done (and (not edit) isearch-recursive-edit (exit-recursive-edit))) -(defun isearch-update-ring (string &optional regexp) +(defun isearch-update-ring (string &optional regexp properties) "Add STRING to the beginning of the search ring. REGEXP if non-nil says use the regexp search ring." (add-to-history (if regexp 'regexp-search-ring 'search-ring) - string - (if regexp regexp-search-ring-max search-ring-max))) + (if properties (apply 'propertize string properties) string) + (if regexp regexp-search-ring-max search-ring-max) + t)) ;; Switching buffers should first terminate isearch-mode. ;; ;; For Emacs 19, the frame switch event is handled. @@ -1834,7 +1845,11 @@ isearch-query-replace ;; `exit-recursive-edit' in `isearch-done' that terminates ;; the execution of this command when it is non-nil. ;; We call `exit-recursive-edit' explicitly at the end below. - (isearch-recursive-edit nil)) + (isearch-recursive-edit nil) + (isearch-string-propertized + (propertize isearch-string + 'isearch-regexp-function isearch-regexp-function + 'isearch-case-fold-search isearch-case-fold-search))) (isearch-done nil t) (isearch-clean-overlays) (if (and isearch-other-end @@ -1847,12 +1862,12 @@ isearch-query-replace (< (mark) (point)))))) (goto-char isearch-other-end)) (set query-replace-from-history-variable - (cons isearch-string + (cons isearch-string-propertized (symbol-value query-replace-from-history-variable))) (perform-replace - isearch-string + isearch-string-propertized (query-replace-read-to - isearch-string + isearch-string-propertized (concat "Query replace" (isearch--describe-regexp-mode (or delimited isearch-regexp-function) t) (if backward " backward" "") @@ -2556,7 +2575,13 @@ isearch-ring-adjust1 length))) (setq isearch-string (nth yank-pointer ring) isearch-message (mapconcat 'isearch-text-char-description - isearch-string ""))))) + isearch-string "")) + (when (memq 'regexp-function (text-properties-at 0 isearch-string)) + (setq isearch-regexp-function + (get-text-property 0 'regexp-function isearch-string))) + (when (memq 'case-fold-search (text-properties-at 0 isearch-string)) + (setq isearch-case-fold-search + (get-text-property 0 'case-fold-search isearch-string)))))) (defun isearch-ring-adjust (advance) ;; Helper for isearch-ring-advance and isearch-ring-retreat @@ -2772,11 +2797,16 @@ isearch-search-fun (defun isearch--lax-regexp-function-p () "Non-nil if next regexp-function call should be lax." + ;; FIXME: maybe simpler to use this: + ;; (or (memq this-command '(isearch-printing-char isearch-del-char)) + ;; isearch-yank-flag) (not (or isearch-nonincremental (null (car isearch-cmds)) (eq (length isearch-string) (length (isearch--state-string - (car isearch-cmds))))))) + (car isearch-cmds)))) + ;; Search string comes from the history with text properties + (memq 'regexp-function (text-properties-at 0 isearch-string))))) (defun isearch-search-fun-default () "Return default functions to use for the search." diff --git a/lisp/replace.el b/lisp/replace.el index c28c9b3..ac37bd7 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -301,7 +301,9 @@ query-replace-read-args (to (if (consp from) (prog1 (cdr from) (setq from (car from))) (query-replace-read-to from prompt regexp-flag)))) (list from to - (and current-prefix-arg (not (eq current-prefix-arg '-))) + (or (and current-prefix-arg (not (eq current-prefix-arg '-))) + (and (memq 'isearch-regexp-function (text-properties-at 0 from)) + (get-text-property 0 'isearch-regexp-function from))) (and current-prefix-arg (eq current-prefix-arg '-))))) (defun query-replace (from-string to-string &optional delimited start end backward region-noncontiguous-p) @@ -2361,8 +2363,17 @@ perform-replace (message (if query-flag (apply 'propertize - (substitute-command-keys - "Query replacing %s with %s: (\\\\[help] for help) ") + (concat "Query replacing " + (if backward "backward " "") + (if delimited-flag + (or (and (symbolp delimited-flag) + (get delimited-flag + 'isearch-message-prefix)) + "word ") "") + (if regexp-flag "regexp " "") + "%s with %s: " + (substitute-command-keys + "(\\\\[help] for help) ")) minibuffer-prompt-properties)))) ;; Unless a single contiguous chunk is selected, operate on multiple chunks. @@ -2580,13 +2591,13 @@ perform-replace (with-output-to-temp-buffer "*Help*" (princ (concat "Query replacing " + (if backward "backward " "") (if delimited-flag (or (and (symbolp delimited-flag) (get delimited-flag 'isearch-message-prefix)) "word ") "") (if regexp-flag "regexp " "") - (if backward "backward " "") from-string " with " next-replacement ".\n\n" (substitute-command-keys --=-=-=--