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: Xah
Subject: Re: Applying macro to lines which match regexp
Date: Wed, 15 Oct 2008 12:54:58 -0700 (PDT)
User-agent: G2/1.0

On Oct 15, 12:21 pm, Corey Foote <coreyfo...@hotmail.com> wrote:
> 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!

I'm not sure there's a way.

>From my experience, once you knew a little elisp you almost never use
keyboard macros...

what you could do in your case is assign a keyboard shortcut to the
macro, then just use arrow keys to move to the lines you want then
press the key.

... but if you'd describe what you want to do, i'm sure me or someone
can easily create a elisp function so that you can apply it to a
region and it process just the comment lines.

Since you are familiar with perl, with a little elisp knowledge you
can write any text processing code in perl, then wrap it in elisp, so
that the elisp function works on the region by calling your perl
script for the processing. Let us know and i'll write up on how you do
this so that you could use all your existing knowledge in perl/php/
ruby/python/bash/awk and use them in emacs.

  Xah
∑ http://xahlee.org/

reply via email to

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