all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* invoke a keyboard menu map from lisp?
@ 2015-08-26 21:40 Stephen Leake
  2015-08-27  2:21 ` Alexis
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Stephen Leake @ 2015-08-26 21:40 UTC (permalink / raw)
  To: emacs-devel

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.

Can anyone help?

-- 
-- Stephe



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

* Re: invoke a keyboard menu map from lisp?
  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
  2015-08-27  2:30 ` Stephen Leake
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Alexis @ 2015-08-27  2:21 UTC (permalink / raw)
  To: emacs-devel


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?


Alexis.



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

* Re: invoke a keyboard menu map from lisp?
  2015-08-26 21:40 invoke a keyboard menu map from lisp? Stephen Leake
  2015-08-27  2:21 ` Alexis
@ 2015-08-27  2:30 ` Stephen Leake
  2015-08-27  2:46   ` Eli Zaretskii
  2015-08-27  6:22 ` Stefan Reichör
  2015-08-27 17:00 ` Stefan Monnier
  3 siblings, 1 reply; 8+ messages in thread
From: Stephen Leake @ 2015-08-27  2:30 UTC (permalink / raw)
  To: emacs-devel

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.
>
> Can anyone help?

I can do (popup-menu map), but that pops up a GUI window; I'd rather
have the plain keyboard menu.

-- 
-- Stephe



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

* Re: invoke a keyboard menu map from lisp?
  2015-08-27  2:30 ` Stephen Leake
@ 2015-08-27  2:46   ` Eli Zaretskii
  2015-08-27  3:16     ` Stephen Leake
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2015-08-27  2:46 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

> From: Stephen Leake <stephen_leake@stephe-leake.org>
> Date: Wed, 26 Aug 2015 21:30:48 -0500
> 
> I can do (popup-menu map), but that pops up a GUI window; I'd rather
> have the plain keyboard menu.

What is "plain keyboard menu"?



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

* Re: invoke a keyboard menu map from lisp?
  2015-08-27  2:46   ` Eli Zaretskii
@ 2015-08-27  3:16     ` Stephen Leake
  0 siblings, 0 replies; 8+ messages in thread
From: Stephen Leake @ 2015-08-27  3:16 UTC (permalink / raw)
  To: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Stephen Leake <stephen_leake@stephe-leake.org>
>> Date: Wed, 26 Aug 2015 21:30:48 -0500
>> 
>> I can do (popup-menu map), but that pops up a GUI window; I'd rather
>> have the plain keyboard menu.
>
> What is "plain keyboard menu"?

As described in (info "(elisp) Menu Keymaps"); what you get by invoking
a key sequence that is bound to a menu keymap.

-- 
-- Stephe



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

* Re: invoke a keyboard menu map from lisp?
  2015-08-27  2:21 ` Alexis
@ 2015-08-27  3:18   ` Stephen Leake
  0 siblings, 0 replies; 8+ messages in thread
From: Stephen Leake @ 2015-08-27  3:18 UTC (permalink / raw)
  To: emacs-devel

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



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

* Re: invoke a keyboard menu map from lisp?
  2015-08-26 21:40 invoke a keyboard menu map from lisp? Stephen Leake
  2015-08-27  2:21 ` Alexis
  2015-08-27  2:30 ` Stephen Leake
@ 2015-08-27  6:22 ` Stefan Reichör
  2015-08-27 17:00 ` Stefan Monnier
  3 siblings, 0 replies; 8+ messages in thread
From: Stefan Reichör @ 2015-08-27  6:22 UTC (permalink / raw)
  To: emacs-devel

Hello Stephen,

> 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.
>
> Can anyone help?

It sounds similar to my quick-task.el library:

http://xsteve.at/prg/emacs/quick-task.el

Using it you can define actions that are shown in a menu like this:

;; (quick-task-define-menu my-quick-task-menu
;;   '(("Build"
;;      ["software" my-quick-task-build1]
;;      ["1: scons proj1" my-quick-task-scons-proj1]
;;      )
;;     ("other"
;;      ["fun" my-quick-task-fun]
;;      )
;;     ["ediff proj1" my-quick-task-ediff-proj1]
;;     ["9: another fun" my-quick-task-fun]
;;     [view "*s:*/dev/ttyS0"] ;; switch to an already open serial terminal buffer
;;     ("find-file"
;;      [open "*e:*~/.emacs"]
;;      [open "*q:*.quick-task.el*/home/stefan/site-lisp/xsteve/.quick-task.el"]
;;      )
;;     ))

Internally I use tmm-prompt to display the candidates.

Maybe this is useful for you.

Stefan.




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

* Re: invoke a keyboard menu map from lisp?
  2015-08-26 21:40 invoke a keyboard menu map from lisp? Stephen Leake
                   ` (2 preceding siblings ...)
  2015-08-27  6:22 ` Stefan Reichör
@ 2015-08-27 17:00 ` Stefan Monnier
  3 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2015-08-27 17:00 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

>     ;; FIXME: invoke the map
> But I can't find the function that executes the keymap.

I guess you'd need to (temporarily) set your map as one of (or the
only/main) active keymaps (e.g. using overriding-local-map), and then
call ‘read-key-sequence’, tho I'm not sure if the "menu keymap" feature
works for the "root" keymap.  This feature is used *extremely* rarely,
it's mostly unknown, ...


        Stefan



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

end of thread, other threads:[~2015-08-27 17:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.