From: Stephen Leake <stephen_leake@stephe-leake.org>
To: emacs-devel@gnu.org
Subject: Re: invoke a keyboard menu map from lisp?
Date: Wed, 26 Aug 2015 22:18:40 -0500 [thread overview]
Message-ID: <86wpwhiflb.fsf@stephe-leake.org> (raw)
In-Reply-To: <878u8xbhev.fsf@gmail.com> (Alexis's message of "Thu, 27 Aug 2015 12:21:12 +1000")
Alexis <flexibeast@gmail.com> writes:
> Stephen Leake <stephen_leake@stephe-leake.org> writes:
>
>> I'm trying to build a keyboard menu keymap on the fly, and then
>> invoke it. I've gotten this far:
>>
>> (defun dvc-offer-choices (comment choices) "Present user with a
>> choice of actions, labeled by COMMENT. CHOICES is a list of pairs
>> containing (function description)." ;; Build a keyboard menu
>> keymap (let ((i 0) (map (make-sparse-keymap "actions")) choice)
>> (unless (< (length choices) 10) (error "‘dvc-offer-choices’
>> only supports up to 10 choices"))
>>
>> (while choices (setq choice (pop choices)) (define-key map
>> (int-to-string i) (list menu-item (format "%d) %s" i
>> (cadr choice)) (car choice)))) ;; FIXME: invoke the map ))
>>
>> But I can't find the function that executes the keymap.
>
> Is setting the value of `overriding-local-map` perhaps what you want?
(now set-transient-map)
Close. This emulates a menu keymap:
(defun dvc-offer-choices (comment choices)
"Execute a keyboard menu built from COMMENT, CHOICES. CHOICES is a list
of pairs (function description)."
;; I can't find the code that executes a real keyboard menu; this is
;; close. (popup-menu map) works, but is not a keyboard menu
(let ((i 0)
(msg (if comment comment ""))
(map (make-sparse-keymap))
choice)
(unless (< (length choices) 10)
(error "‘dvc-offer-choices’ only supports up to 10 choices"))
(while choices
(setq choice (pop choices))
(setq msg (concat msg (format "%d) %s " i (cadr choice))))
(define-key map (int-to-string i) (car choice))
(setq i (1+ i)))
(message msg)
(set-transient-map map)
))
Good enough for my use cases, which all have only a few choices.
--
-- Stephe
next prev parent reply other threads:[~2015-08-27 3:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-26 21:40 invoke a keyboard menu map from lisp? Stephen Leake
2015-08-27 2:21 ` Alexis
2015-08-27 3:18 ` Stephen Leake [this message]
2015-08-27 2:30 ` Stephen Leake
2015-08-27 2:46 ` Eli Zaretskii
2015-08-27 3:16 ` Stephen Leake
2015-08-27 6:22 ` Stefan Reichör
2015-08-27 17:00 ` Stefan Monnier
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86wpwhiflb.fsf@stephe-leake.org \
--to=stephen_leake@stephe-leake.org \
--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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.