From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: query-replace-interactive not documented Date: Tue, 08 Jun 2004 09:55:07 +0300 Organization: JURTA Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <878yeyczec.fsf@mail.jurta.org> References: <20040528.181649.25475113.wl@gnu.org> <200405291737.i4THbPJ06689@raven.dms.auburn.edu> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1086678383 14760 80.91.224.253 (8 Jun 2004 07:06:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 8 Jun 2004 07:06:23 +0000 (UTC) Cc: wl@gnu.org, teirllm@dms.auburn.edu, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Tue Jun 08 09:06:09 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 1BXagS-0006mR-00 for ; Tue, 08 Jun 2004 09:06:08 +0200 Original-Received: from lists.gnu.org ([199.232.76.165]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BXagS-0000ms-00 for ; Tue, 08 Jun 2004 09:06:08 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BXah1-0001M3-Oy for emacs-devel@quimby.gnus.org; Tue, 08 Jun 2004 03:06:43 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BXagu-0001Lm-6O for emacs-devel@gnu.org; Tue, 08 Jun 2004 03:06:36 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BXagr-0001LT-IA for emacs-devel@gnu.org; Tue, 08 Jun 2004 03:06:35 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BXagr-0001LQ-Ea for emacs-devel@gnu.org; Tue, 08 Jun 2004 03:06:33 -0400 Original-Received: from [66.33.219.4] (helo=spork.dreamhost.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BXafo-0002Os-5A; Tue, 08 Jun 2004 03:05:28 -0400 Original-Received: from mail.jurta.org (80-235-38-194-dsl.mus.estpak.ee [80.235.38.194]) by spork.dreamhost.com (Postfix) with ESMTP id 52DA911DC1E; Tue, 8 Jun 2004 00:05:19 -0700 (PDT) Original-To: rms@gnu.org In-Reply-To: (Richard Stallman's message of "Sun, 30 May 2004 15:41:14 -0400") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux) 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:24697 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:24697 Richard Stallman writes: > `query-replace-interactive' is not a user option. It is defined using > defvar in replace.el. Its docstring does not start with a `*' either. > Of course, we can not document every single defvar either. > > Is it something one would want to set permanently to t? > > Some people might. I doubt that people may want to set it permanently to t. And toggling this variable on/off is very inconvenient. However, this variable might be useful in the following situation: it can be set temporarily to t by typing M-% in isearch mode, which can exit isearch mode and start query-replace with isearch string. It's natural to assume that if the user types M-% or C-M-% in isearch mode he wants to use the current search string as FROM-STRING for query-replace and query-replace-regexp. I also added a new value `initial' to `query-replace-interactive' to insert the last search string into FROM-STRING prompt as an initial value to allow the user to modify it before performing replacements. Index: lisp/isearch.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/isearch.el,v retrieving revision 1.228 diff -u -w -b -r1.228 isearch.el --- lisp/isearch.el 6 Jun 2004 13:57:39 -0000 1.228 +++ lisp/isearch.el 8 Jun 2004 03:18:36 -0000 @@ -336,6 +338,9 @@ (define-key map "\M-r" 'isearch-toggle-regexp) (define-key map "\M-e" 'isearch-edit-string) + (define-key map [?\M-%] 'isearch-query-replace) + (define-key map [?\C-\M-%] 'isearch-query-replace-regexp) + map) "Keymap for `isearch-mode'.") @@ -1047,6 +1054,23 @@ (sit-for 1) (isearch-update)) +(defun isearch-query-replace () + "Start query-replace with string to replace from last search string." + (interactive) + (let ((query-replace-interactive 'initial)) + (isearch-exit) + (if isearch-forward (goto-char isearch-other-end)) + (call-interactively 'query-replace))) + +(defun isearch-query-replace-regexp () + "Start query-replace-regexp with string to replace from last search string." + (interactive) + (let ((query-replace-interactive 'initial)) + (isearch-exit) + (if isearch-forward (goto-char isearch-other-end)) + (call-interactively 'query-replace-regexp))) + (defun isearch-delete-char () "Discard last input item and move point back. If no previous match was done, just beep." Index: lisp/replace.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/replace.el,v retrieving revision 1.171 diff -u -r1.171 replace.el --- lisp/replace.el 30 May 2004 21:50:35 -0000 1.171 +++ lisp/replace.el 8 Jun 2004 02:58:37 -0000 @@ -38,8 +38,12 @@ (defcustom query-replace-interactive nil "Non-nil means `query-replace' uses the last search string. -That becomes the \"string to replace\"." - :type 'boolean +That becomes the \"string to replace\". +If value is `initial', the last search string is inserted into +the minibuffer as an initial value for \"string to replace\"." + :type '(choice (const :tag "Off" nil) + (const :tag "Initial content" initial) + (other :tag "Default value" t)) :group 'matching) (defcustom query-replace-from-history-variable 'query-replace-history @@ -70,16 +74,20 @@ (unless noerror (barf-if-buffer-read-only)) (let (from to) - (if query-replace-interactive + (if (and query-replace-interactive + (not (eq query-replace-interactive 'initial))) (setq from (car (if regexp-flag regexp-search-ring search-ring))) ;; 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) - nil nil nil - query-replace-from-history-variable - nil t))) + (setq from (read-from-minibuffer + (format "%s: " string) + (if (eq query-replace-interactive 'initial) + (car (if regexp-flag regexp-search-ring search-ring))) + nil nil + query-replace-from-history-variable + nil t))) ;; Warn if user types \n or \t, but don't reject the input. (if (string-match "\\\\[nt]" from) (let ((match (match-string 0 from))) -- Juri Linkov http://www.jurta.org/emacs/