all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Reuben Thomas <rrt@sc3d.org>
Cc: Emacs Bugs <bug-gnu-emacs@gnu.org>
Subject: Re: replace history
Date: Thu, 27 Dec 2007 22:11:31 +0200	[thread overview]
Message-ID: <871w97x5yc.fsf@jurta.org> (raw)
In-Reply-To: <alpine.DEB.0.999999.0712262319480.3801@localhost.localdomain> (Reuben Thomas's message of "Wed, 26 Dec 2007 23:20:30 +0000 (GMT)")

> 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/




  parent reply	other threads:[~2007-12-27 20:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-26 23:20 replace history Reuben Thomas
2007-12-26 23:48 ` Dan Nicolaescu
2007-12-27 11:42   ` Bastien
2007-12-27 20:14     ` Juri Linkov
2007-12-27 20:12   ` Juri Linkov
2007-12-27 20:40     ` Dan Nicolaescu
2007-12-28 13:55     ` Richard Stallman
     [not found]     ` <mailman.5457.1198850122.18990.bug-gnu-emacs@gnu.org>
2008-01-02 13:21       ` Mathias Dahl
2008-01-03 21:45         ` Juri Linkov
2008-01-03 22:15           ` Mathias Dahl
2008-01-03 22:47             ` Juri Linkov
2008-01-03 23:24               ` Mathias Dahl
2007-12-27 20:11 ` Juri Linkov [this message]
2007-12-28 13:55   ` Richard Stallman
2008-01-03 21:46     ` Juri Linkov
2008-01-05  5:54       ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871w97x5yc.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=bug-gnu-emacs@gnu.org \
    --cc=rrt@sc3d.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.