From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.bugs Subject: bug#25482: 26.0.50; Allow setting `query-replace-from-to-separator` to nil Date: Mon, 23 Jan 2017 09:13:31 +0100 Message-ID: <87vat65h3o.fsf@gmail.com> 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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1485159266 6837 195.159.176.226 (23 Jan 2017 08:14:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 23 Jan 2017 08:14:26 +0000 (UTC) User-Agent: mu4e 0.9.19; emacs 26.0.50.2 Cc: 25482@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jan 23 09:14:21 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 1cVZlP-00005k-1Y for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Jan 2017 09:14:07 +0100 Original-Received: from localhost ([::1]:39699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVZlT-00016P-Ue for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Jan 2017 03:14:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVZlN-00016J-I4 for bug-gnu-emacs@gnu.org; Mon, 23 Jan 2017 03:14:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cVZlK-0001jr-Ca for bug-gnu-emacs@gnu.org; Mon, 23 Jan 2017 03:14:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40466) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cVZlK-0001jj-89 for bug-gnu-emacs@gnu.org; Mon, 23 Jan 2017 03:14:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cVZlJ-0005jP-Ta for bug-gnu-emacs@gnu.org; Mon, 23 Jan 2017 03:14:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Thierry Volpiatto Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 23 Jan 2017 08:14: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.148515922421998 (code B ref 25482); Mon, 23 Jan 2017 08:14:01 +0000 Original-Received: (at 25482) by debbugs.gnu.org; 23 Jan 2017 08:13:44 +0000 Original-Received: from localhost ([127.0.0.1]:38665 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cVZl1-0005ik-Ip for submit@debbugs.gnu.org; Mon, 23 Jan 2017 03:13:43 -0500 Original-Received: from mail-wm0-f43.google.com ([74.125.82.43]:37729) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cVZkz-0005iW-K3 for 25482@debbugs.gnu.org; Mon, 23 Jan 2017 03:13:42 -0500 Original-Received: by mail-wm0-f43.google.com with SMTP id c206so141314753wme.0 for <25482@debbugs.gnu.org>; Mon, 23 Jan 2017 00:13:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version:content-transfer-encoding; bh=Qg+XuupZo8RZWqKW1lWK3W2tAizvJCp87CK3vjFsMY0=; b=ln5MRX2Kat9CSKPU7PtwegztHmjPlpyMxuVlHOI7HMTw++V/e9rxyxfxw3otbUpxK0 jQk7m0WoaA0BKVgcnSwzTOiG9+hrUlZRYdcTfiPXsuiDxTf1/otPSgCMPawouhZcq3QN eCh8lmmt/XLTcxBMKLSXbs8USeDPcnaVXSNcTERAPLHObwTFsHHgi37P+Wjvr1oUC0Nx KStX2yD/QkLIJTjI485eYHBq1VGceAont3jWNyHI61WNd+g1KUaKOYv7KrihgWTEMyhg XlD8smzUNVfuW8i9SwNBd+06JUmRAlHBCa2MxCa68RYCXa6G8PxVLhZrzNxUd77ENP7h +LNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version:content-transfer-encoding; bh=Qg+XuupZo8RZWqKW1lWK3W2tAizvJCp87CK3vjFsMY0=; b=oXINr/U+jgxarhyfq8PvgXv7PpTzGOpCEAYTuxHZe5aqe9cheoSdn0UASBxMi4td87 Q7n16riZ7sgLcgwmMF4hkSJJW6LQca/WISmNkGNxjUuQixnnEvL7GUxaksCQUpawjXEX LL9MRBwxOq58K02RzYuFFwKRCli+wMG9Vhn4f1ZgkcnCK0JNXvPIHsrPZYJ8dHitn5Bc x+eG3E46vbFtA4zh/vdTz96CLLW/JT7CrtR17vmhWxTiQXlpg1/LzRYiKhGmW5cA87hs UgQRtKyKBOveEQJEKzjrUGYXlappFVPayyKfKBlOUB103AAsQE9+1GWabQpsNb1zSr7y hmFA== X-Gm-Message-State: AIkVDXID4sDwZQiH5FhpWepdBejtJAUPum6Ovd3gcSsfNipv2jcKQpY9Fwp2xbBj+akR7g== X-Received: by 10.223.152.18 with SMTP id v18mr22389017wrb.78.1485159215734; Mon, 23 Jan 2017 00:13:35 -0800 (PST) Original-Received: from dell-14z ([37.167.98.61]) by smtp.gmail.com with ESMTPSA id x135sm19708960wme.23.2017.01.23.00.13.33 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 23 Jan 2017 00:13:33 -0800 (PST) In-reply-to: <83fuka4yzj.fsf@gnu.org> 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:128323 Archived-At: Eli Zaretskii writes: >> From: Thierry Volpiatto >> Cc: 25482@debbugs.gnu.org >> Date: Sun, 22 Jan 2017 21:14:03 +0100 >> >> What would be much more simple would be to not use at all properties, >> the actual implementation is too complex for something quite simple. > > But why is it a problem in the first place? The problem is that you endup in the history with a crap string, see https://github.com/emacs-helm/helm/issues/1667. > In any case, some change is still needed, I believe, because you said > customization of this is not easy. Can you show a simple recipe that > demonstrates the problems with customizing this option? I think just looking at the defcustom using a sexp which need delay in the defcustom to ensure char-displayable-p is ready to use and the need to reevaluate this defcustom at each call of query-replace-read-from explain all. This patch don't change the actual behavior, I have removed the fallback to emacs-24.5 behavior, so now setting query-replace-from-to-separator to nil just fallback to " -> ". With this patch the whole string is added to history. Also usage of setq is possible, with actual implementation it is not possible. Finally the implementation is much simpler not relaying on props. I will not have the time for further comments or modifications of patch, I leave it here for memory, if you want to merge it let me know. Thanks. 1 file changed, 28 insertions(+), 35 deletions(-) lisp/replace.el | 63 +++++++++++++++++++++++++-------------------------------- modified lisp/replace.el @@ -79,15 +79,12 @@ That becomes the \"string to replace\".") to the minibuffer that reads the string to replace, or invoke replacements from Isearch by using a key sequence like `C-s C-s M-%'." "24.3") -(defcustom query-replace-from-to-separator - (propertize (if (char-displayable-p ?→) " → " " -> ") - 'face 'minibuffer-prompt) - "String that separates FROM and TO in the history of replacement pairs." - ;; Avoids error when attempt to autoload char-displayable-p fails - ;; while preparing to dump, also stops customize-rogue listing this. - :initialize 'custom-initialize-delay +(defcustom query-replace-from-to-separator " → " + "String that separates FROM and TO in the history of replacement pairs. +When nil or the string provided not displayable the default separator \" -> \" +will be used instead." :group 'matching - :type '(choice string (sexp :tag "Display specification")) + :type '(choice string) :version "25.1") (defcustom query-replace-from-history-variable 'query-replace-history @@ -150,14 +147,12 @@ See `replace-regexp' and `query-replace-regexp-eval'.") (mapconcat 'isearch-text-char-description string "")) (defun query-replace--split-string (string) - "Split string STRING at a character 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 'separator t string))) - (cons (substring-no-properties string 0 split-pos) - (substring-no-properties string (1+ split-pos) length))))) + "Split string STRING at `query-replace-from-to-separator'." + (let ((separator (or query-replace-from-to-separator " -> "))) + (cond ((string-match separator string) + (cons (substring-no-properties string 0 (match-beginning 0)) + (substring-no-properties string (match-end 0)))) + (t (substring-no-properties string))))) (defun query-replace-read-from (prompt regexp-flag) "Query and return the `from' argument of a query-replace operation. @@ -165,43 +160,41 @@ The return value can also be a pair (FROM . TO) indicating that the user wants to replace FROM with TO." (if query-replace-interactive (car (if regexp-flag regexp-search-ring search-ring)) - ;; Reevaluating will check char-displayable-p that is - ;; unavailable while preparing to dump. - (custom-reevaluate-setting 'query-replace-from-to-separator) (let* ((history-add-new-input nil) - (separator - (when query-replace-from-to-separator - (propertize "\0" - 'display query-replace-from-to-separator - 'separator t))) + (sep-char (and (stringp query-replace-from-to-separator) + (replace-regexp-in-string + " " "" query-replace-from-to-separator))) + (separator (propertize + (if (and sep-char + (char-displayable-p (string-to-char sep-char))) + query-replace-from-to-separator + " -> ") + 'face 'minibuffer-prompt)) (minibuffer-history (append - (when separator (mapcar (lambda (from-to) (concat (query-replace-descr (car from-to)) separator (query-replace-descr (cdr from-to)))) - query-replace-defaults)) + query-replace-defaults) (symbol-value query-replace-from-history-variable))) - (minibuffer-allow-text-properties t) ; separator uses text-properties (prompt - (if (and query-replace-defaults separator) - (format "%s (default %s): " prompt (car minibuffer-history)) + (if query-replace-defaults + (format "%s (default %s %s %s): " + prompt + (query-replace-descr (caar query-replace-defaults)) + separator + (query-replace-descr (cdar query-replace-defaults))) (format "%s: " prompt))) (from ;; The save-excursion here is in case the user marks and copies ;; a region in order to specify the minibuffer input. ;; That should not clobber the region for the query-replace itself. (save-excursion - (minibuffer-with-setup-hook - (lambda () - (setq-local text-property-default-nonsticky - (cons '(separator . t) text-property-default-nonsticky))) (if regexp-flag (read-regexp prompt nil 'minibuffer-history) (read-from-minibuffer - prompt nil nil nil nil - (car (if regexp-flag regexp-search-ring search-ring)) t))))) + prompt nil nil nil nil (car search-ring) t)))) (to)) (if (and (zerop (length from)) query-replace-defaults) (cons (caar query-replace-defaults) -- Thierry