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: query-replace in isearch (was Re: should search ring contain duplicates?) Date: Thu, 11 May 2006 14:57:32 +0300 Organization: JURTA Message-ID: <87wtcslqoj.fsf@jurta.org> References: <200605030727.k437R2Wx009975@amrm2.ics.uci.edu> <87bqufwbls.fsf@jurta.org> <200605031504.k43F49hr001544@scanner2.ics.uci.edu> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1147352414 15690 80.91.229.2 (11 May 2006 13:00:14 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 11 May 2006 13:00:14 +0000 (UTC) Cc: dann@ics.uci.edu, storm@cua.dk, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu May 11 15:00:11 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FeAlh-0002Sp-0W for ged-emacs-devel@m.gmane.org; Thu, 11 May 2006 14:59:49 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FeAlg-0002xs-EH for ged-emacs-devel@m.gmane.org; Thu, 11 May 2006 08:59:48 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FeAlQ-0002vI-Px for emacs-devel@gnu.org; Thu, 11 May 2006 08:59:32 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FeAlO-0002t5-Ko for emacs-devel@gnu.org; Thu, 11 May 2006 08:59:31 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FeAlO-0002sh-6p for emacs-devel@gnu.org; Thu, 11 May 2006 08:59:30 -0400 Original-Received: from [217.25.160.1] (helo=relay1.binet.com.ua) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FeAmr-000751-BD; Thu, 11 May 2006 09:01:01 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by relay1.binet.com.ua (Postfix) with ESMTP id BE84B77DE0; Thu, 11 May 2006 15:59:25 +0300 (EEST) Original-Received: from mail.binet.com.ua (i45.dialup.binet.com.ua [217.25.161.109]) by relay1.binet.com.ua (Postfix) with ESMTP id 5DA1A77DB1; Thu, 11 May 2006 15:59:22 +0300 (EEST) Original-To: rms@gnu.org In-Reply-To: (Richard Stallman's message of "Wed, 10 May 2006 23:45:08 -0400") User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) X-Virus-Scanned: by ClamAv at binet.com.ua X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:54259 Archived-At: > This reminds me of the fact that doing `query-replace' from isearch > does not put `query-replace' in the complex command history. IMHO it > should. i.e.: C-s FOO M-% BAR RET C-x ESC ESC should show the same > thing as M-% FOO RET BAR RET C-x ESC ESC > > Would someone please fix this and ack? The following patch should do that. It also uses `add-to-history' to add the current search string to `query-replace-from-history-variable' to improve code in the same function. This requires adding a new argument KEEP-ALL to `add-to-history'. Its meaning is the same as the argument KEEP-ALL of `read-from-minibuffer'. Index: lisp/isearch.el =================================================================== RCS file: /sources/emacs/emacs/lisp/isearch.el,v retrieving revision 1.288 diff -c -r1.288 isearch.el *** lisp/isearch.el 5 May 2006 23:37:31 -0000 1.288 --- lisp/isearch.el 11 May 2006 11:55:45 -0000 *************** *** 1214,1220 **** (interactive) (barf-if-buffer-read-only) (if regexp-flag (setq isearch-regexp t)) ! (let ((case-fold-search isearch-case-fold-search)) (isearch-done) (isearch-clean-overlays) (if (and isearch-other-end --- 1229,1235 ---- (interactive) (barf-if-buffer-read-only) (if regexp-flag (setq isearch-regexp t)) ! (let ((case-fold-search isearch-case-fold-search) to) (isearch-done) (isearch-clean-overlays) (if (and isearch-other-end *************** *** 1222,1239 **** (not (and transient-mark-mode mark-active (< (mark) (point))))) (goto-char isearch-other-end)) ! (set query-replace-from-history-variable ! (cons isearch-string ! (symbol-value query-replace-from-history-variable))) (perform-replace isearch-string ! (query-replace-read-to ! isearch-string ! (if isearch-regexp "Query replace regexp" "Query replace") ! isearch-regexp) t isearch-regexp isearch-word nil nil (if (and transient-mark-mode mark-active) (region-beginning)) ! (if (and transient-mark-mode mark-active) (region-end))))) (defun isearch-query-replace-regexp () "Start query-replace-regexp with string to replace from last search string." --- 1237,1258 ---- (not (and transient-mark-mode mark-active (< (mark) (point))))) (goto-char isearch-other-end)) ! (add-to-history query-replace-from-history-variable isearch-string nil t) (perform-replace isearch-string ! (setq to (query-replace-read-to ! isearch-string ! (if isearch-regexp "Query replace regexp" "Query replace") ! isearch-regexp)) t isearch-regexp isearch-word nil nil (if (and transient-mark-mode mark-active) (region-beginning)) ! (if (and transient-mark-mode mark-active) (region-end))) ! (add-to-history ! 'command-history ! (list (if isearch-regexp 'query-replace-regexp 'query-replace) ! isearch-string to isearch-word ! '(if (and transient-mark-mode mark-active) (region-beginning)) ! '(if (and transient-mark-mode mark-active) (region-end)))))) (defun isearch-query-replace-regexp () "Start query-replace-regexp with string to replace from last search string." Index: lisp/subr.el =================================================================== RCS file: /sources/emacs/emacs/lisp/subr.el,v retrieving revision 1.507 diff -c -r1.507 subr.el *** lisp/subr.el 7 May 2006 20:49:01 -0000 1.507 --- lisp/subr.el 11 May 2006 11:55:55 -0000 *************** *** 1123,1151 **** (< oa ob) oa))))))) ! (defun add-to-history (history-var newelt &optional maxelt) "Add NEWELT to the history list stored in the variable HISTORY-VAR. Return the new history list. If MAXELT is non-nil, it specifies the maximum length of the history. Otherwise, the maximum history length is the value of the `history-length' property on symbol HISTORY-VAR, if set, or the value of the `history-length' variable. ! Remove duplicates of NEWELT unless `history-delete-duplicates' is nil." (unless maxelt (setq maxelt (or (get history-var 'history-length) history-length))) (let ((history (symbol-value history-var)) tail) ! (if history-delete-duplicates (setq history (delete newelt history))) ! (setq history (cons newelt history)) ! (when (integerp maxelt) ! (if (= 0 maxelt) ! (setq history nil) ! (setq tail (nthcdr (1- maxelt) history)) ! (when (consp tail) ! (setcdr tail nil)))) ! (set history-var history))) ;;;; Mode hooks. --- 1123,1154 ---- (< oa ob) oa))))))) ! (defun add-to-history (history-var newelt &optional maxelt keep-all) "Add NEWELT to the history list stored in the variable HISTORY-VAR. Return the new history list. If MAXELT is non-nil, it specifies the maximum length of the history. Otherwise, the maximum history length is the value of the `history-length' property on symbol HISTORY-VAR, if set, or the value of the `history-length' variable. ! Remove duplicates of NEWELT unless `history-delete-duplicates' is nil. ! KEEP-ALL, if non-nil, says to put all inputs in the history list, ! even empty or duplicate inputs." (unless maxelt (setq maxelt (or (get history-var 'history-length) history-length))) (let ((history (symbol-value history-var)) tail) ! (if (and history-delete-duplicates (null keep-all)) (setq history (delete newelt history))) ! (unless (and (null keep-all) history (equal (car history) newelt)) ! (setq history (cons newelt history)) ! (when (integerp maxelt) ! (if (= 0 maxelt) ! (setq history nil) ! (setq tail (nthcdr (1- maxelt) history)) ! (when (consp tail) ! (setcdr tail nil)))) ! (set history-var history)))) ;;;; Mode hooks. -- Juri Linkov http://www.jurta.org/emacs/