[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: invoke a keyboard menu map from lisp?
From: |
Stephen Leake |
Subject: |
Re: invoke a keyboard menu map from lisp? |
Date: |
Wed, 26 Aug 2015 22:18:40 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (windows-nt) |
Alexis <address@hidden> writes:
> Stephen Leake <address@hidden> 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