GNU bug report logs - #13805
query-replace-regexp has conflicting interactive defaults

Previous Next

Package: emacs;

Reported by: Richard Copley <rcopley <at> gmail.com>

Date: Sun, 24 Feb 2013 20:42:01 UTC

Severity: normal

Done: Juri Linkov <juri <at> jurta.org>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 13805 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Richard Copley <rcopley <at> gmail.com>
Cc: 13805 <at> debbugs.gnu.org
Subject: Re: bug#13805: query-replace-regexp has conflicting interactive
	defaults
Date: Mon, 25 Feb 2013 02:03:37 +0200
> From `emacs -Q':
> M-% . RET ! RET ;; To put a replacement into the history.
> M-b    ;; To place point before the word "buffer" in *scratch*.
> C-M-%  ;; Prompts "Query replace regexp (default . -> !): ".
> RET    ;; Prompts "Query replace regexp \_<buffer\.\_> with: ".
> RET !  ;; Replaces "buffer" with "".

The default logic was broken a week ago in revno:111803.
This patch should restore the previous correct behavior:

=== modified file 'lisp/replace.el'
--- lisp/replace.el	2013-02-22 17:13:05 +0000
+++ lisp/replace.el	2013-02-25 00:01:21 +0000
@@ -592,7 +592,8 @@ (defun read-regexp (prompt &optional def
 
 Non-nil HISTORY is a symbol to use for the history list.
 If HISTORY is nil, `regexp-history' is used."
-  (let* ((defaults
+  (let* ((default (if (consp defaults) (car defaults) defaults))
+	 (defaults
 	   (append
 	    (if (listp defaults) defaults (list defaults))
 	    (list
@@ -610,7 +611,6 @@ (defun read-regexp (prompt &optional def
 		  (car (symbol-value
 			query-replace-from-history-variable)))))
 	 (defaults (delete-dups (delq nil (delete "" defaults))))
-	 (default (car defaults))
 	 ;; Do not automatically add default to the history for empty input.
 	 (history-add-new-input nil)
 	 (input (read-from-minibuffer


To avoid similar confusion in the future, I propose to improve the
terminology and give the variables proper names, i.e. to rename the
variable `defaults' to `suggestions' (a list of values available via `M-n')
as opposed to the variable `default' (a single value used when the user
accepts empty input).  This patch could be applied over the above patch:

=== modified file 'lisp/replace.el'
--- lisp/replace.el	2013-02-25 00:01:21 +0000
+++ lisp/replace.el	2013-02-25 00:02:12 +0000
@@ -593,7 +593,7 @@
 Non-nil HISTORY is a symbol to use for the history list.
 If HISTORY is nil, `regexp-history' is used."
   (let* ((default (if (consp defaults) (car defaults) defaults))
-	 (defaults
+	 (suggestions
 	   (append
 	    (if (listp defaults) defaults (list defaults))
 	    (list
@@ -610,7 +610,7 @@
 		  (regexp-quote (or (car search-ring) ""))
 		  (car (symbol-value
 			query-replace-from-history-variable)))))
-	 (defaults (delete-dups (delq nil (delete "" defaults))))
+	 (suggestions (delete-dups (delq nil (delete "" suggestions))))
 	 ;; Do not automatically add default to the history for empty input.
 	 (history-add-new-input nil)
 	 (input (read-from-minibuffer
@@ -621,7 +621,7 @@
 				 (query-replace-descr default)))
 		       (t
 			(format "%s: " prompt)))
-		 nil nil nil (or history 'regexp-history) defaults t)))
+		 nil nil nil (or history 'regexp-history) suggestions t)))
     (if (equal input "")
 	(or default input)
       (prog1 input





This bug report was last modified 12 years and 91 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.