all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: nick <nobody@nowhere.non>
Subject: Re: how to %g/notice/d
Date: Fri, 16 Jul 2004 17:16:24 GMT	[thread overview]
Message-ID: <sgjwu1398ke.fsf@zenix.zk3.dec.com> (raw)
In-Reply-To: cd8499$g2j$1@news1.kornet.net

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

<f9> 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-<SPC> 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)

  parent reply	other threads:[~2004-07-16 17:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-16  8:39 how to %g/notice/d Chang PilHun
2004-07-16  9:10 ` Damien Wyart
2004-07-16 13:09 ` kgold
2004-07-16 16:45 ` Kevin Rodgers
2004-07-16 17:16 ` nick [this message]
2004-07-16 18:33   ` Kevin Rodgers
2004-07-16 18:36   ` Peter Lee

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=sgjwu1398ke.fsf@zenix.zk3.dec.com \
    --to=nobody@nowhere.non \
    /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.