3

I defined a macro in an emacs client, which was attached to my emacs server. I closed the client, and opened the client on a new file, and attempted to run the macro on the new file.

In both the new emacs client, and the server, I was told No keyboard macro defined.

a) Why might someone want this behaviour?
b) How can I work around it?

  • The keyboard macros don't get saved automatically. You need to copy them to your init. The following emacs SE question has the details. This question can be marked as a duplicate. – Kaushal Modi Feb 26 '15 at 11:59
  • @kaushalmodi No, I think you've misunderstood. There's a persistent emacs server backing the client. – Squidly Feb 26 '15 at 12:12
  • Ah, got it. Please ignore my previous comment then. – Kaushal Modi Feb 26 '15 at 12:15
6

This is because last-kbd-macro is a terminal-local variable.

See C-hig (elisp) Multiple Terminals

There aren't a large number of such variables in Emacs, so it's easy to get caught out by the fact that they exist at all, but also very helpful to be aware of the concept, as it helps you to jump to the correct conclusion in such situations.

Note that C-hv last-kbd-macro helpfully points out that it is terminal-local. (Obviously you would need to know where to look for that in the first place, but it gives you confirmation if you do.)

What you would want to do in this situation is either name the keyboard macro and call it by name, or assign it to a key and then use that key binding. You can read about those abilities in the manual:

C-hig (emacs) Save Keyboard Macro

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.