From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: improving query-replace and query-replace-regexp Date: 28 May 2004 18:20:49 -0400 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: <20040528.182035.197345599.wl@gnu.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1085798755 16223 80.91.224.253 (29 May 2004 02:45:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 29 May 2004 02:45:55 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sat May 29 04:45:48 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BTtr1-0001oI-00 for ; Sat, 29 May 2004 04:45:47 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BTtr1-0000NJ-00 for ; Sat, 29 May 2004 04:45:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BTpjb-00034N-5k for emacs-devel@quimby.gnus.org; Fri, 28 May 2004 18:21:51 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.34) id 1BTpjN-000337-05 for emacs-devel@gnu.org; Fri, 28 May 2004 18:21:37 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.34) id 1BTpiq-0002xt-6U for emacs-devel@gnu.org; Fri, 28 May 2004 18:21:35 -0400 Original-Received: from [132.204.24.67] (helo=mercure.iro.umontreal.ca) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BTpip-0002xk-Mm; Fri, 28 May 2004 18:21:03 -0400 Original-Received: from asado.iro.umontreal.ca (asado.iro.umontreal.ca [132.204.24.84]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id B97E1B302C8; Fri, 28 May 2004 18:20:49 -0400 (EDT) Original-Received: by asado.iro.umontreal.ca (Postfix, from userid 20848) id AC6678CA23; Fri, 28 May 2004 18:20:49 -0400 (EDT) Original-To: Werner LEMBERG In-Reply-To: <20040528.182035.197345599.wl@gnu.org> Original-Lines: 64 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=0, requis 5) X-MailScanner-From: monnier@iro.umontreal.ca X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:24113 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:24113 > 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)