From: Drew Adams <drew.adams@oracle.com>
To: emacs-devel@gnu.org
Subject: `this-command-keys-vector', prefix keys, and Customize
Date: Fri, 7 Feb 2014 14:31:40 -0800 (PST) [thread overview]
Message-ID: <1e92962b-bb8c-42f7-92ab-ec18b183edcd@default> (raw)
Consider this:
(global-set-key [menu-bar edit foo] '("Foo" . foo-cmd))
Then, choosing `Edit > Foo' from the menu bar results in this
value for `(this-command-keys-vector)':
[(menu-bar) edit foo]
I don't find the parenthesized form `(menu-bar)' documented
anywhere. Is it really correct? In a sense it obviously is,
since Emacs apparently works that way.
And someone will no doubt reply that it is internal, so it can
be anything Emacs Dev wants it to be. Maybe.
But we document the form of keys and keymaps, and users should
be able to know what the form is (or all possible forms are) in
such a case, and count on that. Either that or provide
functions (an API) that abstract from the actual form and let
you construct and manipulate its components etc.
Now consider this, as a way of letting users define a key
sequence to be used as a prefix key and tested against existing
prefix keys:
(defcustom pref-key [] "doc..."
:type '(key-sequence :tag "Prefix Key" :value []))
Now how can a user customize that, to match the actual prefix
key returned as the first part of [(menu-bar) edit foo]?
S?he can enter <menu-bar> <edit> in the Customize edit field.
But that gives [menu-bar edit], not [(menu-bar) edit].
How can code test a value such as [menu-bar edit] against the
prefix part of what `this-command-keys-vector' returns, which
is [(menu-bar) edit]?
Is there a bug in `this-command-keys-vector', so that it
should in fact return [menu-bar edit foo] here, not
[(menu-bar) edit foo]?
Or is there a problem with Customize, so that it should
return [(menu-bar) edit] for the input <menu-bar> <edit>?
Or is there some function `same-key' that handles all such
forms of keys, testing for equivalence, so that instead of
(equal ACTUAL-PREFIX OPTION-PREFIX), i.e., in this case
(equal [(menu-bar) edit] [menu-bar edit])
^^^^^actual^^^^^^ ^^^^option^^^^^
I could test (same-key ACTUAL-PREFIX OPTION-PREFIX)?
If not, and I need to roll my own such test function, what
are the possible forms of a prefix key as a vector?
Is it enough to wrap any non-list elements of ACTUAL-PREFIX
and OPTION-PREFIX with #'list, so, in effect, the comparison
here becomes:
(equal [(menu-bar) (edit)] [(menu-bar) (edit)])?
Or to unwrap any list elements, so it becomes:
(equal [menu-bar edit] [menu-bar edit])?
What's the right way, or a good way, to go about this?
I want to test an actual prefix key, obtained as part of
`this-command-keys-vector', against a prefix key chosen
by the user as an option value.
Thanks for any help. Perhaps this is all clearly documented
somewhere, the coding is trivial, and I just haven't come
across it yet. That's my hope anyway.
next reply other threads:[~2014-02-07 22:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-07 22:31 Drew Adams [this message]
2014-02-07 23:05 ` `this-command-keys-vector', prefix keys, and Customize Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1e92962b-bb8c-42f7-92ab-ec18b183edcd@default \
--to=drew.adams@oracle.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).