emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: improving query-replace and query-replace-regexp


From: Stefan Monnier
Subject: Re: improving query-replace and query-replace-regexp
Date: 28 May 2004 18:20:49 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

> What do you think of making M-% and C-M-% b behave similar to C-s and
> C-u C-s?  This is, typing it a second time continues a previous
> query-and-replace action.  This would save a lot of time.

After a M-%, you should already be able to continue the same query-replace
action with: M-% RET

At least it works here.......[checking whether it's a local hack that
I haven't installed yet].......hmmm...indeed, it's a local hack.
See patch below,


        Stefan


--- orig/lisp/replace.el
+++ mod/lisp/replace.el
@@ -67,17 +67,28 @@
 (defun query-replace-read-args (string regexp-flag &optional noerror)
   (unless noerror
     (barf-if-buffer-read-only))
-  (let (from to)
+  (let ((lastfrom (car (symbol-value query-replace-from-history-variable)))
+       (lastto (car (symbol-value query-replace-to-history-variable)))
+       from to)
     (if query-replace-interactive
        (setq from (car (if regexp-flag regexp-search-ring search-ring)))
+      (if (equal lastfrom lastto)
+         ;; Typically, this is because the two histlists are shared.
+         (setq lastfrom
+               (cadr (symbol-value query-replace-from-history-variable))))
       ;; 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
-       (setq from (read-from-minibuffer (format "%s: " string)
+       (setq from (read-from-minibuffer (if (null lastto)
+                                            (format "%s: " string)
+                                          (format "%s [%s -> %s]: " string
+                                                  lastfrom lastto))
                                         nil nil nil
                                         query-replace-from-history-variable
                                         nil t)))
+      (if (and lastto (zerop (length from)))
+         (setq from lastfrom to lastto)
       ;; Warn if user types \n or \t, but don't reject the input.
       (if (string-match "\\\\[nt]" from)
          (let ((match (match-string 0 from)))
@@ -86,12 +97,13 @@
              (message "Note: `\\n' here doesn't match a newline; to do that, 
type C-q C-j instead"))
             ((string= match "\\t")
              (message "Note: `\\t' here doesn't match a tab; to do that, just 
type TAB")))
-           (sit-for 2))))
+             (sit-for 2)))))
 
+    (unless to
     (save-excursion
       (setq to (read-from-minibuffer (format "%s %s with: " string from)
                                     nil nil nil
-                                    query-replace-to-history-variable from t)))
+                                      query-replace-to-history-variable from 
t))))
     (list from to current-prefix-arg)))
 
 (defun query-replace (from-string to-string &optional delimited start end)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]