help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

get the binding in macro notation for this-command


From: Xah
Subject: get the binding in macro notation for this-command
Date: Mon, 8 Sep 2008 13:56:16 -0700 (PDT)
User-agent: G2/1.0

There's this-command-keys and this-command-keys-vector. Is there
a command that returns using the syntax of keyboard macro like
“M-‹key›” or “C-‹key›”? Or, how to convert the above to the macro
syntax string?

also when i do M-x narrow-to-region, emacs will tell me that it is
bound to C-x n n. Similar for other command that has a binding but
called with M-x. How to find out programatically the keys of a given
command? I looked at the source but didn't see any mechanism that
reminds user of a existence of a binding.

here's some detail of what i want to do:

Basically, i want to write a function like this:

(global-set-key (kbd "C-a") 'binding-changed-notify)

(defun binding-changed-notify ()
"Notify user that a keybinding has changed.
Display a message of the last key press, the the command associated
with that key press by default keybinding, and the new binding for the
command."
(interactive)
(let (thisKeyPress desiredCmd desiredCmdKey))
(setq thisKeyPress (this-command-keys))
(setq desiredCmd 'someCmd)
(setq desiredCmdKey (where-is-internal desiredCmd))
(message "You pressed %s. You probably wanted to call command %s,
bound to key %s" thisKeyPress desiredCmd desiredCmdKey)
)

Thanks.

  Xah
∑ http://xahlee.org/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]