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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 13805 in the body.
You can then email your comments to 13805 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#13805; Package emacs. (Sun, 24 Feb 2013 20:42:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Richard Copley <rcopley <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 24 Feb 2013 20:42:03 GMT) Full text and rfc822 format available.

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

From: Richard Copley <rcopley <at> gmail.com>
To: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>
Subject: query-replace-regexp has conflicting interactive defaults
Date: Sun, 24 Feb 2013 20:38:20 +0000
`query-replace-regexp' offers to repeat the last replacement, but
then goes off and does something exciting and new instead.

IMHO replace-regexp and friends should not default their
argument using the thing at point, because the user doesn't have
control of point: it is by definition at one end of the region to be
searched. That means the default is useful only in exceptional
cases, and just a distraction otherwise.

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 "".


In GNU Emacs 24.3.50.1 (i386-mingw-nt6.2.9200)
 of 2013-02-24 on MACHINE
Bzr revision: 111868 rgm <at> gnu.org-20130224194517-l50airg5zdb6y0cr
Windowing system distributor `Microsoft Corp.', version 6.2.9200
Configured using:
 `configure --with-gcc (4.7) --cflags -I c:/gnuwin32/include --ldflags
 -L c:/gnuwin32/lib'

Important settings:
  value of $LANG: ENG
  locale-coding-system: cp1252
  default enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
M-% . <return> ! <return> M-b C-M-% <return> ? <return>
! M-x r e p o r t - e m a c s - b u g <return>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Mark set
Replaced 0 occurrences
Mark set
Replaced 1 occurrence

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils time-date tooltip ediff-hook vc-hooks
lisp-float-type mwheel dos-w32 ls-lisp w32-common-fns disp-table w32-win
w32-vars tool-bar dnd fontset image regexp-opt fringe tabulated-list
newcomment lisp-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
abbrev minibuffer button faces cus-face macroexp files text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process w32notify w32
multi-tty emacs)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#13805; Package emacs. (Mon, 25 Feb 2013 00:14:01 GMT) Full text and rfc822 format available.

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





Reply sent to Juri Linkov <juri <at> jurta.org>:
You have taken responsibility. (Mon, 25 Feb 2013 21:02:01 GMT) Full text and rfc822 format available.

Notification sent to Richard Copley <rcopley <at> gmail.com>:
bug acknowledged by developer. (Mon, 25 Feb 2013 21:02:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> jurta.org>
To: Richard Copley <rcopley <at> gmail.com>
Cc: 13805-done <at> debbugs.gnu.org
Subject: Re: bug#13805: query-replace-regexp has conflicting interactive
	defaults
Date: Mon, 25 Feb 2013 22:58:09 +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:

This is fixed now, thanks for the bug report.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 26 Mar 2013 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 41 days ago.

Previous Next


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