0

When I M-x edit-kbd-macro, it prompts saying:

Keyboard macro to edit (C-x e, M-x, C-h l, or keys):

Here, I would hit M-x. It will then allow me to enter the name of the macro. I have several named macros (fset 'macro-name ...) entries in my ~/.emacs file and I can select the one I want to edit.

But when I have:

(global-set-key (kbd "M-x") 'smex)

in my ~/.emacs, when I do M-x edit-kbd-macro and hit M-x to start selecting a name, it produces an error.

How do I resolve the conflict?

1

Arguably this is a bug in edit-kbd-macro: it prompts for M-x but it checks for something bound to execute-extended-command. An easy workaround is to give some other key sequence bound to execute-extended-command instead of M-x. By default, you could use the Menu Key for that.

As of Emacs 26 (where Bug#29399 is fixed) it will work properly if you use remap to bind smex:

(define-key global-map [remap execute-extended-command] 'smex)
  • Thanks. That is elaborate. Although I did not understand it, not being an expert in emacs. However, to solve my problem, I did something simpler. I changed the 'smex line in ~/.emacs to (global-set-key (kbd "M-]") 'smex). But if this is a bug, do developers watch this forum? – deshmukh Nov 22 '17 at 14:06
  • Don't count on developers watching SE.emacs and determining what needs to be done. Use M-x report-emacs-bug to report a problem or suggest an enhancement. – Drew Nov 22 '17 at 16:00
  • I submitted bug #29399 for this. – Drew Nov 22 '17 at 16:29
  • @deshmukh The code was just to point out the problem, I've removed it since it doesn't really help answer the question. – npostavs Nov 23 '17 at 0:20
  • @npostavs Unfortunately, my keyboard does not have a Menu key. So, I resorted to using M-] – deshmukh Nov 23 '17 at 4:11
0

Giving a "name" to a keyboard macro defines the macro as the symbol-function for the symbol that has that name as its symbol-name. In other words, the name you provide names a command.

What do you mean by "when I try to name a macro using M-x"? Just what did you do?

It doesn't sound like you just provided M-x as the name of your keyboard macro. There's no problem doing that. That defines a symbol M-x, giving it a symbol-function value that is the macro. So you can then do M-x M-x to run the macro. Or you can then bind that command, M-x to a key.

But if you don't bind your command M-x to a key then the key M-x is still bound to command smex.

So it's not clear just what you tried to do.

Here is what C-h k C-x C-k n says, BTW:

C-x C-k n runs the command kmacro-name-last-macro, which is an interactive compiled Lisp function in kmacro.el.

It is bound to C-x C-k n.

(kmacro-name-last-macro SYMBOL)

Assign a name to the last keyboard macro defined.

Argument SYMBOL is the name to define.

The symbol's function definition becomes the keyboard macro string. Such a "function" cannot be called from Lisp, but it is a valid editor command.

Note the last sentence, in case your problem was that you were trying to call it from Lisp.

  • Thanks. That was very detailed. I have edited the question. My problem is reproducible thus. (a) Have (global-set-key (kbd "M-x") 'smex) in ~/.emacs. (b) have some named keyboard macros also in ~/.emacs (c) edit-kbd-macro and at the prompt, (d) M-x to supply name of the macro to edit. It will produce an error saying: Key sequence M-x is not a keyboard macro. Remove the global-key-set from ~/.emacs, restart emacs and now there is no error. – deshmukh Nov 22 '17 at 11:20

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.