From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: Re: replace history Date: Thu, 27 Dec 2007 22:11:31 +0200 Organization: JURTA Message-ID: <871w97x5yc.fsf@jurta.org> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1198786777 24778 80.91.229.12 (27 Dec 2007 20:19:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 27 Dec 2007 20:19:37 +0000 (UTC) Cc: Emacs Bugs To: Reuben Thomas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 27 21:19:50 2007 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1J7zCe-0002s8-H1 for geb-bug-gnu-emacs@m.gmane.org; Thu, 27 Dec 2007 21:19:40 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J7zCJ-0000DX-I7 for geb-bug-gnu-emacs@m.gmane.org; Thu, 27 Dec 2007 15:19:19 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J7zBa-0008NV-Ux for bug-gnu-emacs@gnu.org; Thu, 27 Dec 2007 15:18:35 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J7zBZ-0008Mf-Al for bug-gnu-emacs@gnu.org; Thu, 27 Dec 2007 15:18:34 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J7zBZ-0008MY-0Y for bug-gnu-emacs@gnu.org; Thu, 27 Dec 2007 15:18:33 -0500 Original-Received: from relay01.kiev.sovam.com ([62.64.120.200]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1J7zBY-0006sD-HP for bug-gnu-emacs@gnu.org; Thu, 27 Dec 2007 15:18:32 -0500 Original-Received: from [83.170.232.243] (helo=smtp.svitonline.com) by relay01.kiev.sovam.com with esmtp (Exim 4.67) (envelope-from ) id 1J7zBQ-000F3J-4D; Thu, 27 Dec 2007 22:18:28 +0200 In-Reply-To: (Reuben Thomas's message of "Wed, 26 Dec 2007 23:20:30 +0000 (GMT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux) X-Scanner-Signature: 1e897a521fdb5eac39b1f944f187ca57 X-DrWeb-checked: yes X-SpamTest-Envelope-From: juri@jurta.org X-SpamTest-Group-ID: 00000000 X-SpamTest-Header: Not Detected X-SpamTest-Info: Profiles 1968 [Dec 27 2007] X-SpamTest-Info: helo_type=3 X-SpamTest-Info: {HEADERS: header Content-Type found without required header Content-Transfer-Encoding} X-SpamTest-Info: {TO: local part of email appears in body} X-SpamTest-Method: none X-SpamTest-Rate: 28 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0255], KAS30/Release X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.8-5.1 (or MacOS X 10.2-10.3) X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:17260 Archived-At: > In Emacs 22 it's great the way that you are given the last search/replace > pair as a default for query-replace, but is there a way to get a history > of pairs rather than alternating search item/replace item? One way to implement this feature is to use one input string with the ed-like syntax "s/regex/substitution/g". Below is the simplest function that implements this. It reads such a string from the minibuffer (with the query-replace history list and a convenient default input string), parses it and calls perform-replace with proper arguments querying for each replacement when the input string contains the "g" flag. (defun substitute-regexp (substitution) (interactive (list (read-from-minibuffer "Substitute regexp: " '("s///g" . 3) nil nil 'query-replace-history nil t))) (if (string-match "^s/\\(.*\\)/\\(.*\\)/\\([gi]*\\)" substitution) (let* ((regex (match-string 1 substitution)) (subst (match-string 2 substitution)) (flags (match-string 3 substitution)) (case-fold-search (string-match "i" flags))) (perform-replace regex subst (string-match "g" flags) t nil nil nil (if (and transient-mark-mode mark-active) (region-beginning)) (if (and transient-mark-mode mark-active) (region-end)))) (error "Invalid syntax"))) -- Juri Linkov http://www.jurta.org/emacs/