help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: In place (live) editing of matches - is there a package for it?


From: Tom
Subject: Re: In place (live) editing of matches - is there a package for it?
Date: Fri, 14 Oct 2011 12:43:50 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Tom <adatgyujto <at> gmail.com> writes:

> 
> It occurred to me it would be more convenient if I could just select
> the word (or a phrase) and use a command which allows me to live edit
> this region, so that all the changes I make within the selected part are
> reflected instantly at all the other places in the file which have
> the same text as the initial selection.
> 

I created this trivial function which does this without the instant visual 
feedback, but at least it spares me copying the text, going back
to the beginning of buffer, pasting it to the replace prompt and when all
instances are replaced then going back to the place where the whole
thing is started:

(defun my-replace-region ()
  (interactive)
  (unless (use-region-p)
    (error "no region"))
  (let ((what (buffer-substring-no-properties
               (region-beginning) (region-end)))
        (replacement (read-string "replace with: ")))
    (save-excursion
      (goto-char (point-min))
      (while (search-forward what nil t)
        (replace-match replacement)))))

The live feedback would be better, because it's more fancy and the
user can see an instant confirmation of the replacements during typing
if more than one of them is visible on the screen. 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]