Monthly Archives: December 2010

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.