emacs-pretest-bug
[Top][All Lists]
Advanced

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

Re: suggestion in query-replace is messed up after cancelation


From: Chong Yidong
Subject: Re: suggestion in query-replace is messed up after cancelation
Date: Sat, 27 May 2006 23:12:15 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Richard Stallman <address@hidden> writes:

>     That would mean that after doing a C-g, the next time you do M-% the
>     suggested replacement the will be "LAST_FROM -> ", i.e., replacing the
>     last from-string entered with the empty string, instead of the last
>     "good" pair of values as the bug reporter wanted.  Maybe this is
>     acceptable behavior, I don't know.
>
> Neither one is very good.  However, to do any better
> we would need to maintain a separate history of pairs to suggest.
> This would be disconnected from the history list of strings.

This patch should implement this behavior.

*** emacs/lisp/replace.el.~1.240.~      2006-05-25 22:45:19.000000000 -0400
--- emacs/lisp/replace.el       2006-05-27 23:06:41.000000000 -0400
***************
*** 36,41 ****
--- 36,46 ----
  
  (defvar query-replace-history nil)
  
+ (defvar query-replace-defaults nil
+   "Default values of FROM-STRING and TO-STRING for `query-replace'.
+ This is a cons cell (FROM-STRING . TO-STRING), or nil if there is
+ no default value.")
+ 
  (defvar query-replace-interactive nil
    "Non-nil means `query-replace' uses the last search string.
  That becomes the \"string to replace\".")
***************
*** 94,125 ****
  wants to replace FROM with TO."
    (if query-replace-interactive
        (car (if regexp-flag regexp-search-ring search-ring))
!     (let* ((lastfrom (car (symbol-value query-replace-from-history-variable)))
!          (lastto (car (symbol-value query-replace-to-history-variable)))
!          (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
-             (when (equal lastfrom lastto)
-               ;; Typically, this is because the two histlists are shared.
-               (setq lastfrom (cadr (symbol-value
-                                     query-replace-from-history-variable))))
              (read-from-minibuffer
!              (if (and lastto lastfrom)
                   (format "%s (default %s -> %s): " prompt
!                          (query-replace-descr lastfrom)
!                          (query-replace-descr lastto))
                 (format "%s: " prompt))
               nil nil nil
               query-replace-from-history-variable
               nil t))))
!       (if (and (zerop (length from)) lastto lastfrom)
          (progn
            (set query-replace-from-history-variable
                 (cdr (symbol-value query-replace-from-history-variable)))
!           (cons lastfrom
!                 (query-replace-compile-replacement lastto regexp-flag)))
        ;; Warn if user types \n or \t, but don't reject the input.
        (and regexp-flag
             (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" 
from)
--- 99,125 ----
  wants to replace FROM with TO."
    (if query-replace-interactive
        (car (if regexp-flag regexp-search-ring search-ring))
!     (let* ((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
              (read-from-minibuffer
!              (if query-replace-defaults
                   (format "%s (default %s -> %s): " prompt
!                          (query-replace-descr (car query-replace-defaults))
!                          (query-replace-descr (cdr query-replace-defaults)))
                 (format "%s: " prompt))
               nil nil nil
               query-replace-from-history-variable
               nil t))))
!       (if (and (zerop (length from)) query-replace-defaults)
          (progn
            (set query-replace-from-history-variable
                 (cdr (symbol-value query-replace-from-history-variable)))
!           (cons (car query-replace-defaults)
!                 (query-replace-compile-replacement
!                  (cdr query-replace-defaults) regexp-flag)))
        ;; Warn if user types \n or \t, but don't reject the input.
        (and regexp-flag
             (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\(\\\\[nt]\\)" 
from)
***************
*** 177,186 ****
    "Query and return the `to' argument of a query-replace operation."
    (query-replace-compile-replacement
     (save-excursion
!      (read-from-minibuffer
!       (format "%s %s with: " prompt (query-replace-descr from))
!       nil nil nil
!       query-replace-to-history-variable from t))
     regexp-flag))
  
  (defun query-replace-read-args (prompt regexp-flag &optional noerror)
--- 177,188 ----
    "Query and return the `to' argument of a query-replace operation."
    (query-replace-compile-replacement
     (save-excursion
!      (let ((to (read-from-minibuffer
!               (format "%s %s with: " prompt (query-replace-descr from))
!               nil nil nil
!               query-replace-to-history-variable from t)))
!        (setq query-replace-defaults (cons from to))
!        to))
     regexp-flag))
  
  (defun query-replace-read-args (prompt regexp-flag &optional noerror)




reply via email to

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