[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: query-replace-regexp whitespace handling
From: |
Michael Mauger |
Subject: |
Re: query-replace-regexp whitespace handling |
Date: |
Wed, 9 Feb 2005 08:54:59 -0800 (PST) |
I am in W32 but it doesn't appear to be system dependent. I did some
more research and determined that the problem is not specific to
`query-replace-regexp', it also occurs in `query-replace'; and it is not
related to whitespace handling.
The problem appears in the handling of history when the default is
processed.
Try the following:
$ emacs -Q
;; in an empty *scratch*
M-% AAAAA RET BBBBB RET
;; You should see "Replaced 0 occurrences"
M-%
;; prompt should be: "Query replace (default AAAAA -> BBBBB): "
RET
;; You should see "Replaced 0 occurrences"
M-%
;; the prompt I see is: "Query replace (default BBBBB -> ): "
RET
;; You should see "Replaced 0 occurrences"
M-%
;; the prompt I see is: "Query replace (default -> ): "
RET
The problem seems to be that the empty string entered to accept the
default is left in the history and is then misinterpreted as a
replacement string and then as a search string. The critical point
being that it does not break until the invocation after accepting the
default search and replacement strings.
The following patch seems to correct the problem:
Index: emacs/lisp/replace.el
===================================================================
RCS file: /c/cvsroot/emacs/emacs/lisp/replace.el,v
retrieving revision 1.202
diff -u -r1.202 replace.el
--- emacs/lisp/replace.el 15 Jan 2005 18:10:59 -0000 1.202
+++ emacs/lisp/replace.el 9 Feb 2005 16:38:22 -0000
@@ -115,8 +115,11 @@
query-replace-from-history-variable
nil t t))))
(if (and (zerop (length from)) lastto lastfrom)
- (cons lastfrom
- (query-replace-compile-replacement lastto regexp-flag))
+ (progn
+ (cons lastfrom
+ (query-replace-compile-replacement lastto regexp-flag))
+ (set query-replace-from-history-variable
+ (cdr (symbol-value
query-replace-from-history-variable))))
;; Warn if user types \n or \t, but don't reject the input.
(and regexp-flag
(string-match
"\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" from)
--- Richard Stallman <address@hidden> wrote:
> It does not fail when I try it (on GNU/Linux).
>