unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* get the binding in macro notation for this-command
@ 2008-09-08 20:56 Xah
  2008-09-09  7:26 ` Kevin Rodgers
  0 siblings, 1 reply; 2+ messages in thread
From: Xah @ 2008-09-08 20:56 UTC (permalink / raw)
  To: help-gnu-emacs

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/^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: get the binding in macro notation for this-command
  2008-09-08 20:56 get the binding in macro notation for this-command Xah
@ 2008-09-09  7:26 ` Kevin Rodgers
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Rodgers @ 2008-09-09  7:26 UTC (permalink / raw)
  To: help-gnu-emacs

Xah wrote:
> 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?

,----[ C-h f key-description RET ]
| key-description is a built-in function in `C source code'.
| (key-description keys &optional prefix)
|
| Return a pretty description of key-sequence keys.
| Optional arg prefix is the sequence of keys leading up to keys.
| Control characters turn into "C-foo" sequences, meta into "M-foo",
| spaces are put between sequence elements, etc.
|
| [back]
`----

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

,----[ C-h f where-is RET ]
| where-is is an interactive compiled Lisp function in `help.el'.
| It is bound to C-h w, <f1> w, <help> w.
| (where-is definition &optional insert)
|
| Print message listing key sequences that invoke the command definition.
| Argument is a command definition, usually a symbol with a function 
definition.
| If insert (the prefix arg) is non-nil, insert the message in the buffer.
`----

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-09-09  7:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-08 20:56 get the binding in macro notation for this-command Xah
2008-09-09  7:26 ` Kevin Rodgers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).