1

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 Jan 25 '17 at 13:23
  • @phils I can reproduce the problem on Emacs 25.1.9.1, so I don't think it's a accidental keypress – Tyler Jan 25 '17 at 14:53
  • Ah, I see. I can't replicate in 24.5 or 25.1.1. M-x report-emacs-bug, methinks. – phils Jan 25 '17 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 Jan 29 '17 at 13:16
4

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

(fset 'm
   "a")

(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.


Update:

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… – Aleks-Daniel Jakimenko-A. Jul 26 '17 at 16:09

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.