* Multiple keymaps for a minor mode
@ 2020-01-23 1:58 Tim Johnson
2020-01-23 20:49 ` Stefan Monnier
2020-02-26 12:05 ` Michael Heerdegen
0 siblings, 2 replies; 15+ messages in thread
From: Tim Johnson @ 2020-01-23 1:58 UTC (permalink / raw)
To: MLEmacs
Using GNU Emacs 26.1 on ubuntu
;; I use the following code to establish a minor mode
(defvar tj-mode-map (make-sparse-keymap)
"Keymap for `tj-mode'.")
;;;###autoload
(define-minor-mode tj-minor-mode
"This minor mode enables my key settings to override conflicting modes."
:init-value t
:lighter " -tj-"
:keymap tj-mode-map)
;;;###autoload
(define-globalized-minor-mode global-tj-minor-mode tj-minor-mode
tj-minor-mode)
(add-to-list 'emulation-mode-map-alists `((tj-minor-mode . ,tj-mode-map)))
;; End code
I wish to separate `tj-mode-map into a number of individual mode maps
that are configured by category. This would give me the advantage of
using a function called
which-key--create-buffer-and-show from the which-key package to
implement a menu showing commands bound to keys by functionality or
category.
the :keymap member of define-mode-map is what binds the keymap to the mode.
Can I use multiple :keymap entries, one for each keymap or must I define
a minor mode for each of my custom keymaps?
Certainly the latter is doable, but I like to save keystrokes :)
thanks
--
Tim
tj49.com
^ permalink raw reply [flat|nested] 15+ messages in thread
* Multiple keymaps for a minor mode
@ 2020-01-23 18:57 Tim Johnson
2020-01-24 18:47 ` Tim Johnson
0 siblings, 1 reply; 15+ messages in thread
From: Tim Johnson @ 2020-01-23 18:57 UTC (permalink / raw)
To: MLEmacs
Using GNU Emacs 26.1 on ubuntu
;; I use the following code to establish a minor mode
(defvar tj-mode-map (make-sparse-keymap)
"Keymap for `tj-mode'.")
;;;###autoload
(define-minor-mode tj-minor-mode
"This minor mode enables my key settings to override conflicting modes."
:init-value t
:lighter " -tj-"
:keymap tj-mode-map)
;;;###autoload
(define-globalized-minor-mode global-tj-minor-mode tj-minor-mode
tj-minor-mode)
(add-to-list 'emulation-mode-map-alists `((tj-minor-mode . ,tj-mode-map)))
;; End code
I wish to separate `tj-mode-map into a number of individual mode maps
that are configured by category. This would give me the advantage of
using a function called
which-key--create-buffer-and-show from the which-key package to
implement a menu showing commands bound to keys by functionality or
category.
the :keymap member of define-mode-map is what binds the keymap to the mode.
Can I use multiple :keymap entries, one for each keymap or must I define
a minor mode for each of my custom keymaps?
Certainly the latter is doable, but I like to save keystrokes :)
thanks
--
Tim
tj49.com
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Multiple keymaps for a minor mode
2020-01-23 1:58 Multiple keymaps for a minor mode Tim Johnson
@ 2020-01-23 20:49 ` Stefan Monnier
2020-02-19 23:26 ` Tim Johnson
2020-02-26 12:05 ` Michael Heerdegen
1 sibling, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2020-01-23 20:49 UTC (permalink / raw)
To: help-gnu-emacs
> (defvar tj-mode-map (make-sparse-keymap)
> "Keymap for `tj-mode'.")
>
> ;;;###autoload
> (define-minor-mode tj-minor-mode
> "This minor mode enables my key settings to override conflicting modes."
> :init-value t
> :lighter " -tj-"
> :keymap tj-mode-map)
This last line can be removed if you rename `tj-mode-map` to `tj-minor-mode-map`.
> (add-to-list 'emulation-mode-map-alists `((tj-minor-mode . ,tj-mode-map)))
This is redundant with the keymap setup of `define-minor-mode`, so you'd
be better off just not using the :keymap of `define-minor-mode`.
> Can I use multiple :keymap entries, one for each keymap
No, `define-minor-mode` does not support that.
> or must I define a minor mode for each of my custom keymaps?
Not a good idea either.
But you can simply your various keymaps to `emulation-mode-map-alists`
manually like you already do.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Multiple keymaps for a minor mode
2020-01-23 18:57 Tim Johnson
@ 2020-01-24 18:47 ` Tim Johnson
0 siblings, 0 replies; 15+ messages in thread
From: Tim Johnson @ 2020-01-24 18:47 UTC (permalink / raw)
To: help-gnu-emacs
On 1/23/20 9:57 AM, Tim Johnson wrote:
> Using GNU Emacs 26.1 on ubuntu
>
> ;; I use the following code to establish a minor mode
>
> (defvar tj-mode-map (make-sparse-keymap)
> "Keymap for `tj-mode'.")
>
> ;;;###autoload
> (define-minor-mode tj-minor-mode
> "This minor mode enables my key settings to override conflicting
> modes."
> :init-value t
> :lighter " -tj-"
> :keymap tj-mode-map)
>
> ;;;###autoload
> (define-globalized-minor-mode global-tj-minor-mode tj-minor-mode
> tj-minor-mode)
>
> (add-to-list 'emulation-mode-map-alists `((tj-minor-mode .
> ,tj-mode-map)))
> ;; End code
>
> I wish to separate `tj-mode-map into a number of individual mode maps
> that are configured by category. This would give me the advantage of
> using a function called
>
> which-key--create-buffer-and-show from the which-key package to
> implement a menu showing commands bound to keys by functionality or
> category.
>
> the :keymap member of define-mode-map is what binds the keymap to the
> mode.
>
> Can I use multiple :keymap entries, one for each keymap or must I
> define a minor mode for each of my custom keymaps?
>
> Certainly the latter is doable, but I like to save keystrokes :)
>
No worries ... it is an easy enough pattern to follow.
cheers
--
Tim
tj49.com
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Multiple keymaps for a minor mode
2020-01-23 20:49 ` Stefan Monnier
@ 2020-02-19 23:26 ` Tim Johnson
2020-02-21 16:16 ` Stefan Monnier
0 siblings, 1 reply; 15+ messages in thread
From: Tim Johnson @ 2020-02-19 23:26 UTC (permalink / raw)
To: help-gnu-emacs
On 1/23/20 11:49 AM, Stefan Monnier wrote:
>> (defvar tj-mode-map (make-sparse-keymap)
>> "Keymap for `tj-mode'.")
>>
>> ;;;###autoload
>> (define-minor-mode tj-minor-mode
>> "This minor mode enables my key settings to override conflicting modes."
>> :init-value t
>> :lighter " -tj-"
>> :keymap tj-mode-map)
> This last line can be removed if you rename `tj-mode-map` to `tj-minor-mode-map`.
>
>> (add-to-list 'emulation-mode-map-alists `((tj-minor-mode . ,tj-mode-map)))
> This is redundant with the keymap setup of `define-minor-mode`, so you'd
> be better off just not using the :keymap of `define-minor-mode`.
>
>> Can I use multiple :keymap entries, one for each keymap
> No, `define-minor-mode` does not support that.
>
>> or must I define a minor mode for each of my custom keymaps?
> Not a good idea either.
Thanks for the reply Stefa, however I do not completely understand your
last comment which follows:
> But you can simply your various keymaps to `emulation-mode-map-alists`
> manually like you already do.
>
Could you elaborate?
Thank you
--
Tim
tj49.com
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Multiple keymaps for a minor mode
2020-02-19 23:26 ` Tim Johnson
@ 2020-02-21 16:16 ` Stefan Monnier
2020-02-21 18:22 ` Tim Johnson
0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2020-02-21 16:16 UTC (permalink / raw)
To: help-gnu-emacs
> Thanks for the reply Stefa, however I do not completely understand your last
> comment which follows:
>> But you can simply your various keymaps to `emulation-mode-map-alists`
>> manually like you already do.
>>
> Could you elaborate?
Your code does:
(add-to-list 'emulation-mode-map-alists `((tj-minor-mode . ,tj-mode-map)))
and you can add any number of var/keymap pairs in there.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Multiple keymaps for a minor mode
2020-02-21 16:16 ` Stefan Monnier
@ 2020-02-21 18:22 ` Tim Johnson
0 siblings, 0 replies; 15+ messages in thread
From: Tim Johnson @ 2020-02-21 18:22 UTC (permalink / raw)
To: help-gnu-emacs
On 2/21/20 7:16 AM, Stefan Monnier wrote:
>> Thanks for the reply Stefa, however I do not completely understand your last
>> comment which follows:
>>> But you can simply your various keymaps to `emulation-mode-map-alists`
>>> manually like you already do.
>>>
>> Could you elaborate?
> Your code does:
>
> (add-to-list 'emulation-mode-map-alists `((tj-minor-mode . ,tj-mode-map)))
>
> and you can add any number of var/keymap pairs in there.
>
Thank you
--
Tim
tj49.com
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Multiple keymaps for a minor mode
2020-01-23 1:58 Multiple keymaps for a minor mode Tim Johnson
2020-01-23 20:49 ` Stefan Monnier
@ 2020-02-26 12:05 ` Michael Heerdegen
2020-02-26 19:05 ` Tim Johnson
1 sibling, 1 reply; 15+ messages in thread
From: Michael Heerdegen @ 2020-02-26 12:05 UTC (permalink / raw)
To: Tim Johnson; +Cc: MLEmacs
Tim Johnson <tim@akwebsoft.com> writes:
> (add-to-list 'emulation-mode-map-alists `((tj-minor-mode . ,tj-mode-map)))
> I wish to separate `tj-mode-map into a number of individual mode maps
> that are configured by category. [...]
An alternative to what already has been discussed could be to use
`make-composed-keymap' to combine the split maps to the minor mode map.
The result inherits changes of its parts.
Michael.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Multiple keymaps for a minor mode
2020-02-26 12:05 ` Michael Heerdegen
@ 2020-02-26 19:05 ` Tim Johnson
2020-02-26 20:24 ` Drew Adams
2020-03-04 15:47 ` Michael Heerdegen
0 siblings, 2 replies; 15+ messages in thread
From: Tim Johnson @ 2020-02-26 19:05 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: MLEmacs
On 2/26/20 3:05 AM, Michael Heerdegen wrote:
> Tim Johnson <tim@akwebsoft.com> writes:
>
>
>> (add-to-list 'emulation-mode-map-alists `((tj-minor-mode . ,tj-mode-map)))
>> I wish to separate `tj-mode-map into a number of individual mode maps
>> that are configured by category. [...]
> An alternative to what already has been discussed could be to use
> `make-composed-keymap' to combine the split maps to the minor mode map.
> The result inherits changes of its parts
Thanks Michael. I'm glad to hear about make-composed-keymap.
I will research its usage, time permitting.
I actually scrapped the idea of multiple minor modes by category. It
seemed as if I were unnecessarily populating my environment with modes.
My original interest was prompted by wishing to have "help" on
keybindings by category. My solution has been to set up a menuing scheme
using x-popup-menu. I would note, as others would, that tmm-prompt could
be an alternative if I ever had to use emacs in terminal mode - which I
do not implement at this time.
The advantage is that a binding and command can now appear in more than
one category. The disadvantage is that if I were to change a keybinding,
I would also have to change at least one and maybe more menu entries.
thanks again
--
Tim
tj49.com
^ permalink raw reply [flat|nested] 15+ messages in thread
* RE: Multiple keymaps for a minor mode
2020-02-26 19:05 ` Tim Johnson
@ 2020-02-26 20:24 ` Drew Adams
2020-02-27 0:02 ` Tim Johnson
2020-03-04 15:47 ` Michael Heerdegen
1 sibling, 1 reply; 15+ messages in thread
From: Drew Adams @ 2020-02-26 20:24 UTC (permalink / raw)
To: Tim Johnson, Michael Heerdegen; +Cc: MLEmacs
> tmm-prompt could be an alternative
An alternative to tmm is library lacarte.el.
Paths to menu items are completion candidates.
And if you use a completion style that does
substring matching, or you use a library such
as Icicles, then it's easy to fine menu items
wherever they might be in the menu hierarchy/tree.
https://www.emacswiki.org/emacs/LaCarte
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Multiple keymaps for a minor mode
2020-02-26 20:24 ` Drew Adams
@ 2020-02-27 0:02 ` Tim Johnson
0 siblings, 0 replies; 15+ messages in thread
From: Tim Johnson @ 2020-02-27 0:02 UTC (permalink / raw)
To: help-gnu-emacs
Thanks Drew, I'll check it out.
On 2/26/20 11:24 AM, Drew Adams wrote:
>> tmm-prompt could be an alternative
> An alternative to tmm is library lacarte.el.
>
> Paths to menu items are completion candidates.
> And if you use a completion style that does
> substring matching, or you use a library such
> as Icicles, then it's easy to fine menu items
> wherever they might be in the menu hierarchy/tree.
>
> https://www.emacswiki.org/emacs/LaCarte
>
>
--
Tim
tj49.com
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Multiple keymaps for a minor mode
2020-02-26 19:05 ` Tim Johnson
2020-02-26 20:24 ` Drew Adams
@ 2020-03-04 15:47 ` Michael Heerdegen
2020-03-05 18:51 ` Tim Johnson
1 sibling, 1 reply; 15+ messages in thread
From: Michael Heerdegen @ 2020-03-04 15:47 UTC (permalink / raw)
To: Tim Johnson; +Cc: MLEmacs
Tim Johnson <tim@akwebsoft.com> writes:
> My original interest was prompted by wishing to have "help" on
> keybindings by category.
Do these categories exist only for the purpose of giving better help, or
are they existing in your code already in any way? If not, do you
necessarily have to implement these categories on the level of keymaps,
or could this classification also take place at another level?
Michael.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Multiple keymaps for a minor mode
2020-03-04 15:47 ` Michael Heerdegen
@ 2020-03-05 18:51 ` Tim Johnson
2020-03-05 23:54 ` Michael Heerdegen
0 siblings, 1 reply; 15+ messages in thread
From: Tim Johnson @ 2020-03-05 18:51 UTC (permalink / raw)
To: help-gnu-emacs
On 3/4/20 6:47 AM, Michael Heerdegen wrote:
> Tim Johnson <tim@akwebsoft.com> writes:
>
>> My original interest was prompted by wishing to have "help" on
>> keybindings by category.
> Do these categories exist only for the purpose of giving better help, or
> are they existing in your code already in any way? If not, do you
> necessarily have to implement these categories on the level of keymaps,
> or could this classification also take place at another level?
They exist for the purpose of giving better help. Essentially they *are*
arbitrary.
In fact, should my muse so move me, I want a keybind/command to display
in more than one category.
thanks
--
Tim
tj49.com
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Multiple keymaps for a minor mode
2020-03-05 18:51 ` Tim Johnson
@ 2020-03-05 23:54 ` Michael Heerdegen
2020-03-06 0:45 ` Tim Johnson
0 siblings, 1 reply; 15+ messages in thread
From: Michael Heerdegen @ 2020-03-05 23:54 UTC (permalink / raw)
To: Tim Johnson; +Cc: help-gnu-emacs
Tim Johnson <tim@akwebsoft.com> writes:
> They exist for the purpose of giving better help. Essentially they
> *are* arbitrary.
So you also could establish the association to categories in some other
way and look up the categories when building the popup menus.
> In fact, should my muse so move me, I want a keybind/command to
> display in more than one category.
That should not be a problem. Anyway, don't hesitate to post some code
snippets or more code when you want.
Michael.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Multiple keymaps for a minor mode
2020-03-05 23:54 ` Michael Heerdegen
@ 2020-03-06 0:45 ` Tim Johnson
0 siblings, 0 replies; 15+ messages in thread
From: Tim Johnson @ 2020-03-06 0:45 UTC (permalink / raw)
To: help-gnu-emacs
> Tim Johnson <tim@akwebsoft.com> writes:
>
>> They exist for the purpose of giving better help. Essentially they
>> *are* arbitrary.
> So you also could establish the association to categories in some other
> way and look up the categories when building the popup menus.
>
>> In fact, should my muse so move me, I want a keybind/command to
>> display in more than one category.
> That should not be a problem. Anyway, don't hesitate to post some code
> snippets or more code when you want.
I'm quite happy with the results that I have produced, and am happy to
share.
The core elisp is as follows:
(defun info-popup (title &rest messages)
"simple informational popup"
(interactive)
(let (menu items)
(setq menu (list title))
(setq items '("--"))
(dolist (message messages)
(setq items (append items (list(cons message nil)))))
(setq menu (append menu (list items)))
(condition-case nil
(x-popup-menu (list '(700 300) (selected-window)) menu)
((quit) nil))))
;; I have two complaints about the result of my code:
;; The title shows as quite pale, not a big deal, but the solution would
edify me.
;; x-popup-dialog by default shows in the very center of the frame. I
would love it if I could accomplish the same with x-popup-menu, but
couldn't figure that part out.
;; Below is a simple implementation
(defun tj-transpose-info ()
"Popup transpostition key bindings"
(interactive)
(info-popup
"Transposition"
" C-M-t Sexps" "C-t Prev chars" "M-t Words" "C-x C-t Lines"))
Thanks for the interest
--
Tim
tj49.com
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2020-03-06 0:45 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-23 1:58 Multiple keymaps for a minor mode Tim Johnson
2020-01-23 20:49 ` Stefan Monnier
2020-02-19 23:26 ` Tim Johnson
2020-02-21 16:16 ` Stefan Monnier
2020-02-21 18:22 ` Tim Johnson
2020-02-26 12:05 ` Michael Heerdegen
2020-02-26 19:05 ` Tim Johnson
2020-02-26 20:24 ` Drew Adams
2020-02-27 0:02 ` Tim Johnson
2020-03-04 15:47 ` Michael Heerdegen
2020-03-05 18:51 ` Tim Johnson
2020-03-05 23:54 ` Michael Heerdegen
2020-03-06 0:45 ` Tim Johnson
-- strict thread matches above, loose matches on Subject: below --
2020-01-23 18:57 Tim Johnson
2020-01-24 18:47 ` Tim Johnson
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).