From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: History for query replace pairs Date: Wed, 08 Oct 2014 01:11:52 +0300 Organization: JURTA Message-ID: <87k34ba5sn.fsf@mail.jurta.org> References: <87a97ejxuo.fsf@mail.jurta.org> <87lhovik5c.fsf@lifelogs.com> <87wq8egh3r.fsf@lifelogs.com> <87ppe4zv0t.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1412720108 32470 80.91.229.3 (7 Oct 2014 22:15:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 7 Oct 2014 22:15:08 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 08 00:15:01 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Xbd25-0003KW-Km for ged-emacs-devel@m.gmane.org; Wed, 08 Oct 2014 00:15:01 +0200 Original-Received: from localhost ([::1]:32828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xbd25-0000lY-3m for ged-emacs-devel@m.gmane.org; Tue, 07 Oct 2014 18:15:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xbd1n-0000lJ-Ct for emacs-devel@gnu.org; Tue, 07 Oct 2014 18:14:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xbd1g-0003gI-JX for emacs-devel@gnu.org; Tue, 07 Oct 2014 18:14:43 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.222.226]:44693 helo=ps18281.dreamhostps.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xbd1g-0003gE-Db for emacs-devel@gnu.org; Tue, 07 Oct 2014 18:14:36 -0400 Original-Received: from localhost.jurta.org (ps18281.dreamhostps.com [69.163.222.226]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 0897430C97691E for ; Tue, 7 Oct 2014 15:14:34 -0700 (PDT) In-Reply-To: <87ppe4zv0t.fsf@mail.jurta.org> (Juri Linkov's message of "Tue, 07 Oct 2014 01:35:30 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 69.163.222.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:175100 Archived-At: > So the first RET will actually do almost the same as TAB would do > in the two-field minibuffer to switch to editing the TO part. This is the minimal patch to implement this. Opinions? === modified file 'lisp/replace.el' --- lisp/replace.el 2014-08-25 02:36:45 +0000 +++ lisp/replace.el 2014-10-07 22:07:18 +0000 @@ -56,8 +56,8 @@ (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.") +This is a list of cons cells (FROM-STRING . TO-STRING), +or nil if there is no default values.") (defvar query-replace-interactive nil "Non-nil means `query-replace' uses the last search string. @@ -135,8 +135,8 @@ (defun query-replace-read-from (prompt r (prompt (if query-replace-defaults (format "%s (default %s -> %s): " prompt - (query-replace-descr (car query-replace-defaults)) - (query-replace-descr (cdr query-replace-defaults))) + (query-replace-descr (car (car query-replace-defaults))) + (query-replace-descr (cdr (car query-replace-defaults)))) (format "%s: " prompt))) (from ;; The save-excursion here is in case the user marks and copies @@ -149,9 +149,9 @@ (defun query-replace-read-from (prompt r prompt nil nil nil query-replace-from-history-variable (car (if regexp-flag regexp-search-ring search-ring)) t))))) (if (and (zerop (length from)) query-replace-defaults) - (cons (car query-replace-defaults) + (cons (car (car query-replace-defaults)) (query-replace-compile-replacement - (cdr query-replace-defaults) regexp-flag)) + (cdr (car query-replace-defaults)) regexp-flag)) (add-to-history query-replace-from-history-variable from nil t) ;; Warn if user types \n or \t, but don't reject the input. (and regexp-flag @@ -213,10 +213,10 @@ (defun query-replace-read-to (from promp (let* ((history-add-new-input nil) (to (read-from-minibuffer (format "%s %s with: " prompt (query-replace-descr from)) - nil nil nil + (cdr (assoc from query-replace-defaults)) nil nil query-replace-to-history-variable from t))) (add-to-history query-replace-to-history-variable to nil t) - (setq query-replace-defaults (cons from to)) + (push (cons from to) query-replace-defaults) to)) regexp-flag))