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#25482: 26.0.50; Allow setting `query-replace-from-to-separator` to nil Date: Thu, 16 Feb 2017 22:43:08 +0200 Organization: LINKOV.NET Message-ID: <87d1ehzx2b.fsf@localhost> References: <871svzzcn4.fsf@gmail.com> <83lgu76nuf.fsf@gnu.org> <87vatac0a2.fsf@gmail.com> <83a8am6u6q.fsf@gnu.org> <87y3y6ezge.fsf@gmail.com> <8337gd7udo.fsf@gnu.org> <87o9z1n4o3.fsf@gmail.com> <83lgu252zc.fsf@gnu.org> <87o9yy26pg.fsf@gmail.com> <83fuka4yzj.fsf@gnu.org> <87vat65h3o.fsf@gmail.com> <87r33n3cgk.fsf@gmail.com> <83tw8jzllx.fsf@gnu.org> <87poj7wjkr.fsf@gmail.com> <83inozzbvz.fsf@gnu.org> <87mvebwhpx.fsf@gmail.com> <83h94jz42j.fsf@gnu.org> <87h94jyvx6.fsf@gmail.com> <87mvdrncwh.fsf@localhost> <87h93yhc0v.fsf@gmail.com> 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 1487279180 17513 195.159.176.226 (16 Feb 2017 21:06:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 16 Feb 2017 21:06:20 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (x86_64-pc-linux-gnu) Cc: 25482@debbugs.gnu.org To: Thierry Volpiatto Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Feb 16 22:06:13 2017 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 1ceTFh-0003pE-6X for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 Feb 2017 22:06:09 +0100 Original-Received: from localhost ([::1]:50333 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceTFm-0002fQ-SL for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 Feb 2017 16:06:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45125) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceTFd-0002fD-7t for bug-gnu-emacs@gnu.org; Thu, 16 Feb 2017 16:06:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceTFa-0002s4-1i for bug-gnu-emacs@gnu.org; Thu, 16 Feb 2017 16:06:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:44474) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceTFZ-0002ry-UH for bug-gnu-emacs@gnu.org; Thu, 16 Feb 2017 16:06:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ceTFZ-0001px-Mx for bug-gnu-emacs@gnu.org; Thu, 16 Feb 2017 16:06:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <871svzzcn4.fsf@gmail.com> Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Feb 2017 21:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25482 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25482-submit@debbugs.gnu.org id=B25482.14872791497035 (code B ref 25482); Thu, 16 Feb 2017 21:06:01 +0000 Original-Received: (at 25482) by debbugs.gnu.org; 16 Feb 2017 21:05:49 +0000 Original-Received: from localhost ([127.0.0.1]:42671 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ceTFN-0001pO-GE for submit@debbugs.gnu.org; Thu, 16 Feb 2017 16:05:49 -0500 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:40112 helo=homiemail-a39.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ceTFL-0001pA-Ld for 25482@debbugs.gnu.org; Thu, 16 Feb 2017 16:05:48 -0500 Original-Received: from homiemail-a39.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a39.g.dreamhost.com (Postfix) with ESMTP id 0950015007E; Thu, 16 Feb 2017 13:05:46 -0800 (PST) Original-Received: from localhost.linkov.net (m83-191-240-183.cust.tele2.ee [83.191.240.183]) (Authenticated sender: jurta@jurta.org) by homiemail-a39.g.dreamhost.com (Postfix) with ESMTPA id 2BBB0150074; Thu, 16 Feb 2017 13:05:44 -0800 (PST) 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:129419 Archived-At: >> As for your idea of using plain ASCII separators without text properti= es, >> the problem is that it will not work if the user wants to replace >> the same string as is used for the separator, e.g. to replace >> =E2=86=92 with -> in the current buffer. > > So yes, this is a good reason. Wait, maybe you are right in the idea to use the separator string as is, instead of the null character. We still need to use text properties to unambiguously mark separator boundaries, so we can't rely on regexp matching to find separator boundaries. But at least =E2=80=9C =E2= =86=92 =E2=80=9D is not more frequent string to replace than the null character. Putting special text properties on the separator itself instead of the null character might be more beneficial for such situations where the separator is exposed without text properties, e.g. when copying the contents of the minibuffer. However, one drawback is that searching in the replacement minibuffer history for the same string as the separator (e.g. =E2=80=9C=E2=86=92=E2=80=9D) will find matc= hes in the separator, not only in replacement strings. This patch demonstrates what we could do. It still uses the =E2=80=98dis= play=E2=80=99 property because I see no other simple way to make the separator string intangible. diff --git a/lisp/replace.el b/lisp/replace.el index b96c883..6600ff6 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -149,14 +149,17 @@ query-replace-descr (mapconcat 'isearch-text-char-description string "")) =20 (defun query-replace--split-string (string) - "Split string STRING at a character with property `separator'" + "Split string STRING at a substring with property `separator'" (let* ((length (length string)) (split-pos (text-property-any 0 length 'separator t string))) (if (not split-pos) (substring-no-properties string) - (cl-assert (not (text-property-any (1+ split-pos) length 'separato= r t string))) (cons (substring-no-properties string 0 split-pos) - (substring-no-properties string (1+ split-pos) length))))) + (substring-no-properties + string (or (text-property-not-all + (1+ split-pos) length 'separator t string) + length) + length))))) =20 (defun query-replace-read-from (prompt regexp-flag) "Query and return the `from' argument of a query-replace operation. @@ -165,17 +168,19 @@ query-replace-read-from (if query-replace-interactive (car (if regexp-flag regexp-search-ring search-ring)) (let* ((history-add-new-input nil) + (separator-string + (when query-replace-from-to-separator + ;; Check if the first non-whitespace char is displayable + (if (char-displayable-p + (string-to-char (replace-regexp-in-string + " " "" query-replace-from-to-separat= or))) + query-replace-from-to-separator + " -> "))) (separator - (when query-replace-from-to-separator - (propertize "\0" - 'display - (propertize - (if (char-displayable-p - (string-to-char (replace-regexp-in-strin= g - " " "" query-replace-fr= om-to-separator))) - query-replace-from-to-separator - " -> ") - 'face 'minibuffer-prompt) + (when separator-string + (propertize separator-string + 'display separator-string + 'face 'minibuffer-prompt 'separator t))) (minibuffer-history (append @@ -203,7 +210,8 @@ query-replace-read-from (minibuffer-with-setup-hook (lambda () (setq-local text-property-default-nonsticky - (cons '(separator . t) text-property-def= ault-nonsticky))) + (append '((separator . t) (face . t)) + text-property-default-nonsticky)= )) (if regexp-flag (read-regexp prompt nil 'minibuffer-history) (read-from-minibuffer