From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Isearch interaction model Date: Fri, 09 Mar 2018 00:55:17 +0200 Organization: LINKOV.NET Message-ID: <87y3j29nze.fsf@mail.linkov.net> References: <87po4slrg4.fsf@mail.linkov.net> <2854ae14-ad4a-2fa2-ff0f-652e1501819e@dancol.org> <87fu5jh14h.fsf_-_@mail.linkov.net> <6a3f7332ddb16531fd4dcdd5ec49f846.squirrel@dancol.org> <87po4kn58s.fsf@mail.linkov.net> <43455926-bd9b-37ee-2364-ac855781f463@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1520549878 28204 195.159.176.226 (8 Mar 2018 22:57:58 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 8 Mar 2018 22:57:58 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: emacs-devel@gnu.org To: =?iso-8859-1?Q?Cl=E9ment?= Pit-Claudel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Mar 08 23:57:54 2018 Return-path: Envelope-to: ged-emacs-devel@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 1eu4Tx-0007Eu-E9 for ged-emacs-devel@m.gmane.org; Thu, 08 Mar 2018 23:57:53 +0100 Original-Received: from localhost ([::1]:42331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eu4W0-0006iP-9b for ged-emacs-devel@m.gmane.org; Thu, 08 Mar 2018 18:00:00 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eu4Vo-0006gA-Sg for emacs-devel@gnu.org; Thu, 08 Mar 2018 17:59:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eu4Vl-00030T-72 for emacs-devel@gnu.org; Thu, 08 Mar 2018 17:59:48 -0500 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:32848 helo=homiemail-a15.g.dreamhost.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eu4Vk-00030H-UY for emacs-devel@gnu.org; Thu, 08 Mar 2018 17:59:45 -0500 Original-Received: from homiemail-a15.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a15.g.dreamhost.com (Postfix) with ESMTP id F090B76C06B; Thu, 8 Mar 2018 14:59:43 -0800 (PST) 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 E45E176C065; Thu, 8 Mar 2018 14:59:42 -0800 (PST) In-Reply-To: <43455926-bd9b-37ee-2364-ac855781f463@gmail.com> (=?iso-8859-1?Q?=22Cl=E9ment?= Pit-Claudel"'s message of "Sat, 3 Mar 2018 18:46:31 -0500") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 69.163.253.7 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:223520 Archived-At: --=-=-= Content-Type: text/plain >> because text properties on strings can't be saved >> in the desktop file or by other history saving libraries. > > Couldn't we change that instead? It seems text properties is the least bad of all other alternatives that are not backward compatible and don't allow adding support for search parameters to query-replace such as requested in bug#22479, so with text properties this seems to be a better way, and adding support to desktop for text properties is not unachievable: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=isearch-text-properties.patch diff --git a/lisp/desktop.el b/lisp/desktop.el index 8bd4465..a7e549f 100644 --- a/lisp/desktop.el +++ b/lisp/desktop.el @@ -852,10 +852,7 @@ desktop--v2s ((or (numberp value) (null value) (eq t value) (keywordp value)) (cons 'may value)) ((stringp value) - (let ((copy (copy-sequence value))) - (set-text-properties 0 (length copy) nil copy) - ;; Get rid of text properties because we cannot read them. - (cons 'may copy))) + (cons 'may value)) ((symbolp value) (cons 'must value)) ((vectorp value) diff --git a/lisp/isearch.el b/lisp/isearch.el index 4f5f494..0699868 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -1119,7 +1119,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)) @@ -1135,12 +1137,12 @@ 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 properties (apply 'propertize string properties) string) (if regexp regexp-search-ring-max search-ring-max))) ;; Switching buffers should first terminate isearch-mode. @@ -1850,7 +1852,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 @@ -1863,12 +1869,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" "") @@ -2572,7 +2578,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 @@ -2788,11 +2800,15 @@ 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 --=-=-=--