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

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

Re: Applying macro to lines which match regexp


From: Tim X
Subject: Re: Applying macro to lines which match regexp
Date: Thu, 16 Oct 2008 11:38:39 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Corey Foote <coreyfoote@hotmail.com> writes:

> I was reading through the Emacs manual today, and came across C-x C-k r
> (apply-macro-to-region-lines) which applies the last keyboard macro to each
> line that begins in the region. How would I apply the last keyboard macro to
> each line that begins in the region which match a certain regular expression.
> For example, say I was editing a Perl script and wanted to apply the last
> macro to all line which consist solely of a comment. For example:
>
> 1    # Print some text
> 2    print "foo";
> 3    print "foobar";
> 4
> 5    # And then a while later
> 6    print "foobarbaz";
>
> I would want to apply the macro to lines 1 and 6 which match the regular
> expression ^\s-*#. Thanks a bunch!
>
> Corey Foote
> Toby Software
> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> Stay up to date on your PC, the Web, and your mobile phone with Windows Live. 
> See Now
>

I'm not sure there is a command to do that 'out of the box'. Normally,
I'd probably write a function to do it. A couple of ideas though -

1. You could include in your macro definition an isearch command to find
the line you are interested in. 

2. See if you can find the package map-lines.el by Andreas Fuchs (part
of the emacs-goodies package in Debian). This allows you to apply a
command to a set of lines matching a regexp. 

3. Write something in elisp using the various map* funcitons.

HTH

Tim



-- 
tcross (at) rapttech dot com dot au


reply via email to

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