First of all, I made a new keyboard macro called 'mac'.

[F3] abcd [F4]

M-x name-last-kbd-macro mac

Then, I can get 'abcd' by typing [F4] or M-x mac. I tried to get 'abcd' five times. So I made a new keyboard macro of keyboard macro.

[F3] C-u 5 M-x mac [F4]

I expected to see 'abcdabcdabcdabcdabcd' when I typed [F4]. However, keyboard macro of keyboard macro made 'abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd' which is 10 times of 'abcd', rather than 5. What's wrong with it?

  • I suspect you managed to type F4 twice by mistake at the end, causing it to run a second time.
    – phils
    Commented Jan 25, 2017 at 13:23
  • @phils I can reproduce the problem on Emacs, so I don't think it's a accidental keypress
    – Tyler
    Commented Jan 25, 2017 at 14:53
  • Ah, I see. I can't replicate in 24.5 or 25.1.1. M-x report-emacs-bug, methinks.
    – phils
    Commented Jan 25, 2017 at 21:33
  • I found why my keyboard macro works twice. The problem was typing 'RET(enter)' when I define second keyboard macro. I exactly typed '[F3] C-u 5 M-x mac RET [F4]'. Sorry for my mistake. Typing 'RET' add abcd 5 times. So total 10 times of abcd are included in kbd macro.
    – comphys
    Commented Jan 29, 2017 at 13:16

1 Answer 1


This looks like a bug. Using insert-kbd-macro You can look at what's actually stored in the macros:

(fset 'm

(fset 'n
   [?\M-x ?m return ?a])

I created a macro called m that just prints 'a', then created a second macro called n that calls m. It seems the second macro records the call to m, then records the output of m as though it's keyboard input.

The only solution I can find is to create the second macro, then use edit-kbd-macro to remove the doubled text. Not very convenient, really.


I believe this has now been fixed in the master branch, so should work from Emacs 26 on.

  • Thank you very much for you answer. I've been trying to figure out what's wrong for the last hour… Commented Jul 26, 2017 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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