I'm trying to make Workgroups2 more convenient by displaying a list of workgroups in the mini-buffer on pressing the prefix key (C-c z), e.g.:
This makes it convenient to use the index 0-9 to switch workgroups:
(defvar wg-prefixed-map
(wg-fill-keymap
(make-sparse-keymap)
;; workgroup switching
(kbd "C-j") 'wg-switch-to-workgroup-at-index
(kbd "j") 'wg-switch-to-workgroup-at-index
(kbd "0") 'wg-switch-to-workgroup-at-index-0
(kbd "1") 'wg-switch-to-workgroup-at-index-1
(kbd "2") 'wg-switch-to-workgroup-at-index-2
(kbd "3") 'wg-switch-to-workgroup-at-index-3
(kbd "4") 'wg-switch-to-workgroup-at-index-4
(kbd "5") 'wg-switch-to-workgroup-at-index-5
(kbd "6") 'wg-switch-to-workgroup-at-index-6
(kbd "7") 'wg-switch-to-workgroup-at-index-7
(kbd "8") 'wg-switch-to-workgroup-at-index-8
(kbd "9") 'wg-switch-to-workgroup-at-index-9
)
"The keymap that sits on `wg-prefix-key'.")
(defun wg-fill-keymap (keymap &rest binds)
"Return KEYMAP after defining in it all keybindings in BINDS."
(while binds
(define-key keymap (car binds) (cadr binds))
(setq binds (cddr binds)))
keymap)
The list can be generated with:
(wg-fontified-message
(wg-workgroup-list-display))
Question:
Given C-c z as the prefix key for Workgroups2, is it possible to bind it to
(wg-fontified-message
(wg-workgroup-list-display))
so that it displays the list of workgroups in the mini-buffer? C-c z should still be the prefix after the binding.
Note:
This question is similar to Can the prefix of a key-sequence have an effect?. The comments suggest set-transient-map
or keymapp
. If either of these is useful, please kindly show how the above code can be modified to implement the function. Thank you.
(define-prefix-command 'wg-prefixed-map)
and then you do(define-key MAP (kbd "C-c z") 'wg-prefixed-map)
for each minibuffer keymapMAP
that you are interested in, then you get your prefix-key behavior in the minibuffer. How that relates to another use ofC-c z
as the prefix key for "Workgroups2", or how or why you want to bind that same key to(wg-fontified-message (wg-workgroup-list-display))
, which would have to return a command or keymap, is unclear. – Drew Mar 29 '16 at 20:34C-c z
is the default prefix key for Workgroups2. When IC-c z
, I usej
,0
,1
, etc, to execute a command. Now I wantC-c z
to show a list of workgroups in the mini-buffer usingwg-fontified-message
while waiting to accept the next key. – Yang Mar 29 '16 at 20:43j
,0
, etc., to have them first display what you want to display. – Drew Mar 29 '16 at 21:000
,1
, etc, and after I press the prefix keyC-c z
, I would like a list of workgroups (e.g., 0: Default 1: Test 1 2:Test 2 as shown in the image) displayed in the mini-buffer. – Yang Mar 29 '16 at 21:18C-c z
to a single command that reads a key (e.g.0
etc.) and dispatches to a function that does what0
etc. does today. And reread the question you cited: Can the prefix of a key-sequence have an effect?. A key sequence is bound to a command or to a keymap, or it is unbound. A command can read keys. A keymap performs no actions. – Drew Mar 29 '16 at 21:40wg-prefixed-map
is defined by the Workgroups2 library. In addition to0
-9
, there are many other commands (https://github.com/pashinin/workgroups2/blob/master/src/workgroups2.el#L1725). I don't think it's the best way to restructure the library. I have read that a key sequence is bound to a command or to a keymap, or it is unbound, and a keymap performs no actions. That's why I'm asking how I should correctly implement the desired behavior. – Yang Mar 29 '16 at 21:50set-transient-map
. There are not 36 ways to look at this. – Drew Mar 30 '16 at 01:43