From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Markus Triska Newsgroups: gmane.emacs.help 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 Message-ID: <87fy7awvm3.fsf@gmx.at> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1176061024 12432 80.91.229.12 (8 Apr 2007 19:37:04 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 8 Apr 2007 19:37:04 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Apr 08 21:36:40 2007 Return-path: Envelope-to: geh-help-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 1HadBo-0005VJ-8h for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Apr 2007 21:36:40 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HadFX-0001cL-St for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Apr 2007 15:40:31 -0400 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!newsfeed.freenet.de!newsfeed01.chello.at!newscore.univie.ac.at!aconews-feed.univie.ac.at!aconews.univie.ac.at!not-for-mail Original-Newsgroups: gnu.emacs.help Cancel-Lock: sha1:pWIZUJdFBasYYEcaRl2WJ3DPXvc= Original-Lines: 26 Original-NNTP-Posting-Host: news-access-from.tuwien.ac.at Original-X-Trace: 1176058104 tunews.univie.ac.at 12642 192.35.241.118 Original-X-Complaints-To: abuse@tuwien.ac.at Original-Xref: shelby.stanford.edu gnu.emacs.help:146879 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:42484 Archived-At: Sam Peterson 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" ))))