Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jdavidb (1361)

  (email not shown publicly)

J. David Blackstone has a Bachelor of Science in Computer Science and Engineering and nine years of experience at a wireless telecommunications company, where he learned Perl and never looked back. J. David has an advantage in that he works really hard, he has a passion for writing good software, and he knows many of the world's best Perl programmers.

Journal of jdavidb (1361)

Friday October 25, 2002
03:18 PM

Emacs macros

[ #8611 ]

I'm sure I'm not the only person out there still learning emacs.While cutting and pasting jjohn's 10-line code snippets to make the SOAP journal client (Don't waste an opportunity to learn! Examine and understand each piece before going on!) I wanted an easy way to delete the source code line numbers and associated spacing. In vi, I'm quite familiar with how I'd do that: 7x to delete 7 characters, followed by n, followed by dot to repeat. Unfortunately the same approach in emacs fails because the "repeat" command repeats the act of going to the next line.

With the help of a coworker and the documentation, I figured out how to get what I wanted: c-x ( starts recording a keyboard macro, then I hit c-a to go to the beginning of the current line (I'm writing this macro defensively :) ), then c-u 7d to delete seven characters, including the spaces and line number, then c-n to go to the next line. Finally I close out the macro with c-x ) . Now, I can execute my macro once with c-x e , or I can tell it to repeat ten times (say, each time I paste one of those snippets), using c-u, as in c-u 10 c-x e.

Have you ever noticed that emacs is cool?

Oh, and, if you hadn't guessed, this is my first post from emacs with the new client. Thanks, Joe!

Addendum-- or, if I'd waited until the end of the article, I would have learned that I could just download the program. But then I wouldn't have learned this really cool emacs trick, would I? I might look foolish at this point, but I'm satisfied. :)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • C-space to mark at the beginning of the first line;
    cursor down to the 7th row of the last line;
    C-X r k to delete the characters (mnemonic: region-kill)

    -DA []

    • Whoops, sorry; it's short for rectangle-kill.

      -DA []

    • Or, in VIM ctrl-shift-v (for visual block mode), then use your arrow keys, then x to delete. Newer versions of VIM use ctrl-v instead of ctrl-shift-v.
    • :) Sounds like emacs subscribes to Perl's TMTOWTDI philosophy.

      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers