From: Markus Triska <e0225855@stud4.tuwien.ac.at>
To: help-gnu-emacs@gnu.org
Subject: Re: #1: How to do vi's 'g/foo/s/x/y/' #2: + with a Q-R "yes/no?"
Date: Sun, 08 Apr 2007 20:48:20 +0200 [thread overview]
Message-ID: <87fy7awvm3.fsf@gmx.at> (raw)
In-Reply-To: m1hcrrupll.fsf@Sams-Baby.local
Sam Peterson <skpeterson@nospam.please.ucdavis.edu> writes:
> The best method would be to write some lisp code as I thought about
> how to do it with a macro and it started getting too complicated.
A rudimentary definition:
(defun vis-g (arg)
"ARG `foo/x/y' changes x to y on all lines that contain
regexp `foo'."
(interactive "sPattern: ")
(let* ((ls (split-string arg "/"))
(regexp (nth 0 ls))
(from (nth 1 ls))
(to (nth 2 ls))
(nlines 0))
(save-excursion
(goto-char (point-min))
(while (re-search-forward regexp nil t)
(setq nlines (1+ nlines))
(replace-regexp from to nil
(line-beginning-position) (line-end-position))
(forward-line)))
(message "Replaced all occurrences on %s matching line%s"
nlines (if (= nlines 1) "" "s" ))))
next prev parent reply other threads:[~2007-04-08 18:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-07 17:51 #1: How to do vi's 'g/foo/s/x/y/' #2: + with a Q-R "yes/no?" David Combs
2007-04-08 10:28 ` Sam Peterson
2007-04-08 18:48 ` Markus Triska [this message]
2007-04-08 19:07 ` Peter Dyballa
2007-04-09 7:48 ` Drew Adams
[not found] <mailman.1852.1176105200.7795.help-gnu-emacs@gnu.org>
2007-04-23 3:32 ` David Combs
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fy7awvm3.fsf@gmx.at \
--to=e0225855@stud4.tuwien.ac.at \
--cc=help-gnu-emacs@gnu.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).