Subject: Re: bug#30309: Surprising behaviour of insert-kbd-macro

From: Robert Pluim <[email-masked]>
Date: Fri, 30 Nov 2018 09:36:43 +0100

Noam Postavsky <[email-masked]> writes:

> tags 30309 + confirmed easy
> retitle 30309 C-u M-x insert-kbd-macro RET RET inserts many unrelated "bindings" (menu separators?)
> quit
>
> Robert Pluim <[email-masked]> writes:
>
>> #emacs-26
>> emacs -Q
>> C-u M-x insert-kbd-macro RET RET
>> =>
>> (setq last-kbd-macro
>>    nil)
>> (global-set-key [C-down-mouse-2 s2] 'last-kbd-macro)
>> (global-set-key [C-down-mouse-2 s1] 'last-kbd-macro)
>> (global-set-key [menu-bar help-menu sep1] 'last-kbd-macro)
> [...]
>
> Yeah, I guess no keybindings should be inserted in that case.

So I guess just checking for last-kbd-macro should be enough, since
that should never have a legitimate key binding.

diff --git i/lisp/macros.el w/lisp/macros.el
index 4078b983ec..53a688a367 100644
--- i/lisp/macros.el
+++ w/lisp/macros.el
@@ -125,7 +125,7 @@ insert-kbd-macro
         ;; (kmacro-create [<keys>] 0 "%d").
 	(prin1 definition (current-buffer))))
     (insert ")\n")
-    (if keys
+    (and keys (not (eq macroname 'last-kbd-macro))
         (let ((keys (or (where-is-internal (symbol-function macroname)
                                            '(keymap))
                         (where-is-internal macroname '(keymap)))))