Emacs: macro within a macro

It has been around 4 years now that I am using Emacs and it feels awesome. You are an RTL engineer, probably you are no good to me without Emacs. Recently a friend of mine Anil Godasi (I call him the walking encyclopedia of HDL, you name the language he knows it and knows it __right__), asked me about an emacs query on how do we have nested macros on it. The answer was quite short, rename your last keyboard macro and you could call the macro as is. I am assuming he could not find it when he Google’d it and here is how we do it.

  1. Define the first macro
    C-x (
  2. Start your macro operations and finish defining the macro
    C-x )
  3. The macro is now defined, but then it is stored as the last-kbd-macro in emacs.
  4. So we rename the last-kbd-macro
    M-x name-last-kbd-macro
  5. Gives you a prompt to define the name for the macro as my-macro1
    Name last kbd macro : my-macro1
  6. Now get to defining the second macro and start your second macro.
  7. Call the first macro by
    M-x my-macro1
  8. Finish defining the second macro with a
    C-x )
  9. Execute the second macro with a
    C-x e
  10. This still calls the last macro and the last macro being defined was your second macro. You could still rename the second macro and call the nested macro in another third macro.

Awesomeness
Shyam

Advertisements

2 Comments

  1. Raghav
    Posted February 5, 2011 at 6:54 am | Permalink | Reply

    yepp. Anil indeed is a walking encyclopedia.. i call him google of HDL.
    and thanks for the solution… guess u can compile more of emacs tips n tricks in the blog..

    • ghanashyam
      Posted March 26, 2011 at 7:01 am | Permalink | Reply

      sorry for the late reply.. I haven’t been doing much on my blog since long.. I did some snippet lisp coding for verilog and probbaly will put this up sooner.. :) so its in the coming soon section..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: