From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: nick Newsgroups: gmane.emacs.help Subject: Re: how to %g/notice/d Date: Fri, 16 Jul 2004 17:16:24 GMT Organization: nowhere, inc. Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1089998266 8714 80.91.224.253 (16 Jul 2004 17:17:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 16 Jul 2004 17:17:46 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jul 16 19:17:35 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BlWL1-0001yM-00 for ; Fri, 16 Jul 2004 19:17:35 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BlWNY-0000st-Vj for geh-help-gnu-emacs@m.gmane.org; Fri, 16 Jul 2004 13:20:13 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!info1.fnal.gov!nntp-server.caltech.edu!hammer.uoregon.edu!arclight.uoregon.edu!wns13feed!worldnet.att.net!128.230.129.106!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!news.cpqcorp.net!53ab2750!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:2l1fGH1Kg4N2DUi5E9Fb87CFQhE= Original-Lines: 65 Original-NNTP-Posting-Host: 16.141.40.203 Original-X-Complaints-To: abuse@HP.com Original-X-Trace: news.cpqcorp.net 1089998184 16.141.40.203 (Fri, 16 Jul 2004 10:16:24 PDT) Original-NNTP-Posting-Date: Fri, 16 Jul 2004 10:16:24 PDT Original-Xref: shelby.stanford.edu gnu.emacs.help:124339 Original-To: help-gnu-emacs@gnu.org 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: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:19675 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:19675 There are many ways: o you can write a lisp function to do it - that is a good exercise if you want to learn emacs lisp, but of course, it will take a while to write and debug the function, so it is not really an option if you want something quickly. o you can write a macro (as kgold suggested) that remembers the keystrokes you type while you are doing *one* deletion, go to the top of the buffer and then invoke the macro N times (with a prefix argument of course), where N is some number greater or equal to the number of occurrences of the word ``notice'' in your file. o if you are on Unix, you can use standard Unix tools - let me expand on this last one: There is a function in emacs called ``shell-command-on-region''. It is bound by default to the key M-| (meta verticalbar). The idea is to mark the whole buffer as the region and then use this function to invoke an arbitrary shell command on it. It is as if (and the notation is designed to encourage that notion) you pipe the buffer through the command. The only remaining problem is to make sure that the output of the command replaces the contents of the region (by default, a temp buffer is created to hold the output of the command). Having the output replace the contents of the region can be done by giving a prefix argument to this command. You can give a prefix argument to a command by hitting C-u before the command. That is the long explanation. Here is the sequence of operations: M-x mark-whole-buffer RET C-u M-| sed '/notice/d' RET In my case, I have bound the mark-whole-buffer function to a function key, since I use it very often, so the resulting operation is shorter. In my .emacs, I have (define-key global-map [f9] 'mark-whole-buffer) which makes the function key invoke this function (there are better ways to write this for compatibility reasons, but this works for me, so I have not bothered to improve it). So I do C-u M-| sed '/notice/d' RET If you want to localize the transformation to a *part* of the buffer, all you have to do is mark the region that you want to transform, instead of marking the whole buffer: Go to the beginning of the region, and mark it with C-SPC (or C-@ if C- does not work on your machine). Go the end of the region. Say C-u M-| sed 'notice/d' RET As you can see, it is much harder to describe than to do, but if you understand the basic idea, then the power of the mechanism becomes obvious. Note that you can put an arbitrary shell command in place of the sed, which allows you to do all sorts of transformations on the input. Hope this helps. -- nick (nicholas dot dokos at hp dot com)