* How to define a prefixed map for a minor mode?
@ 2020-06-07 6:50 Marcin Borkowski
2020-06-07 7:54 ` Jamie Beardslee
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Marcin Borkowski @ 2020-06-07 6:50 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
Hi all,
continuing my work on a (simplistic) Emacs CAT, I want to define a minor
mode. However, I'm stuck on defining its keymap. I want all the
commands prefixed by e.g. `C-c .', and here's what I have:
--8<---------------cut here---------------start------------->8---
(setq ecat-basic-map (make-sparse-keymap))
(define-key ecat-basic-map (kbd "p") #'ecat-highlight-previous-sentence)
(define-key ecat-basic-map (kbd "n") #'ecat-highlight-next-sentence)
(define-key ecat-basic-map (kbd ".") #'ecat-highlight-this-sentence)
(easy-mmode-defmap ecat-mode-map
`(((kbd "C-c .") . ecat-basic-map))
"Keymap for `ecat-mode'.")
(define-minor-mode ecat-mode
"Toggle Emacs CAT mode."
:lighter " CAT"
:keymap ecat-mode-map
(if ecat-mode
(ecat-highlight-this-sentence)
(delete-overlay ecat-sentence-overlay)))
--8<---------------cut here---------------end--------------->8---
Alas, this does not seem to work - after pressing `C-c .' (when the mode
is one!) I get "C-c . is undefined".
What am I doing wrong? Is there a "canonical" method of defining
a minor mode whose bindings start with some prefix?
TIA,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to define a prefixed map for a minor mode?
2020-06-07 6:50 How to define a prefixed map for a minor mode? Marcin Borkowski
@ 2020-06-07 7:54 ` Jamie Beardslee
2020-06-07 20:45 ` Marcin Borkowski
2020-06-07 7:59 ` Michael Heerdegen
2020-06-07 10:18 ` Joost Kremers
2 siblings, 1 reply; 9+ messages in thread
From: Jamie Beardslee @ 2020-06-07 7:54 UTC (permalink / raw)
To: Marcin Borkowski; +Cc: Help Gnu Emacs mailing list
> (easy-mmode-defmap ecat-mode-map
> `(((kbd "C-c .") . ecat-basic-map))
> "Keymap for `ecat-mode'.")
You're missing a couple of unquotes there -- that should be:
`((,(kbd "C-c .") . ,ecat-basic-map))
Smerge-mode uses a prefix key (C-c ^) for all commands and this is done
in pretty much the same way:
(easy-mmode-defmap smerge-basic-map
`(("n" . smerge-next)
("p" . smerge-prev)
[...])
"The base keymap for `smerge-mode'.")
(defcustom smerge-command-prefix "\C-c^"
"Prefix for `smerge-mode' commands."
[...])
(easy-mmode-defmap smerge-mode-map
`((,smerge-command-prefix . ,smerge-basic-map))
"Keymap for `smerge-mode'.")
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to define a prefixed map for a minor mode?
2020-06-07 7:54 ` Jamie Beardslee
@ 2020-06-07 20:45 ` Marcin Borkowski
0 siblings, 0 replies; 9+ messages in thread
From: Marcin Borkowski @ 2020-06-07 20:45 UTC (permalink / raw)
To: Jamie Beardslee; +Cc: Help Gnu Emacs mailing list
On 2020-06-07, at 09:54, Jamie Beardslee <beardsleejamie@gmail.com> wrote:
>> (easy-mmode-defmap ecat-mode-map
>> `(((kbd "C-c .") . ecat-basic-map))
>> "Keymap for `ecat-mode'.")
>
> You're missing a couple of unquotes there -- that should be:
>
> `((,(kbd "C-c .") . ,ecat-basic-map))
As I said a minute ago - you're obviously right, that helped.
> Smerge-mode uses a prefix key (C-c ^) for all commands and this is done
> in pretty much the same way:
Yep, indeed I tried to mimick it, but forgot about unquoting.
Thanks,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to define a prefixed map for a minor mode?
2020-06-07 6:50 How to define a prefixed map for a minor mode? Marcin Borkowski
2020-06-07 7:54 ` Jamie Beardslee
@ 2020-06-07 7:59 ` Michael Heerdegen
2020-06-07 8:16 ` Michael Heerdegen
2020-06-07 20:44 ` Marcin Borkowski
2020-06-07 10:18 ` Joost Kremers
2 siblings, 2 replies; 9+ messages in thread
From: Michael Heerdegen @ 2020-06-07 7:59 UTC (permalink / raw)
To: help-gnu-emacs
Marcin Borkowski <mbork@mbork.pl> writes:
> (easy-mmode-defmap ecat-mode-map
> `(((kbd "C-c .") . ecat-basic-map))
> "Keymap for `ecat-mode'.")
I don't know much about this but passing an unevaluated `kbd' expression
doesn't look right to me.
Michael.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to define a prefixed map for a minor mode?
2020-06-07 7:59 ` Michael Heerdegen
@ 2020-06-07 8:16 ` Michael Heerdegen
2020-06-07 20:45 ` Marcin Borkowski
2020-06-07 20:44 ` Marcin Borkowski
1 sibling, 1 reply; 9+ messages in thread
From: Michael Heerdegen @ 2020-06-07 8:16 UTC (permalink / raw)
To: help-gnu-emacs
Michael Heerdegen <michael_heerdegen@web.de> writes:
> > (easy-mmode-defmap ecat-mode-map
> > `(((kbd "C-c .") . ecat-basic-map))
> > "Keymap for `ecat-mode'.")
>
> I don't know much about this but passing an unevaluated `kbd' expression
> doesn't look right to me.
AFAIR I use to do this kind of thing like this:
(define-minor-mode ecat-mode
"Toggle Emacs CAT mode."
:lighter " CAT"
:keymap (let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c .") ecat-basic-map)
map))
Michael.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to define a prefixed map for a minor mode?
2020-06-07 8:16 ` Michael Heerdegen
@ 2020-06-07 20:45 ` Marcin Borkowski
2020-06-08 11:23 ` Michael Heerdegen
0 siblings, 1 reply; 9+ messages in thread
From: Marcin Borkowski @ 2020-06-07 20:45 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
On 2020-06-07, at 10:16, Michael Heerdegen <michael_heerdegen@web.de> wrote:
> Michael Heerdegen <michael_heerdegen@web.de> writes:
>
>> > (easy-mmode-defmap ecat-mode-map
>> > `(((kbd "C-c .") . ecat-basic-map))
>> > "Keymap for `ecat-mode'.")
>>
>> I don't know much about this but passing an unevaluated `kbd' expression
>> doesn't look right to me.
>
> AFAIR I use to do this kind of thing like this:
>
> (define-minor-mode ecat-mode
> "Toggle Emacs CAT mode."
> :lighter " CAT"
> :keymap (let ((map (make-sparse-keymap)))
> (define-key map (kbd "C-c .") ecat-basic-map)
> map))
Thanks, that seems to make sense to me.
Still, I'd love to see the "canonical" way...
Best,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to define a prefixed map for a minor mode?
2020-06-07 7:59 ` Michael Heerdegen
2020-06-07 8:16 ` Michael Heerdegen
@ 2020-06-07 20:44 ` Marcin Borkowski
1 sibling, 0 replies; 9+ messages in thread
From: Marcin Borkowski @ 2020-06-07 20:44 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
On 2020-06-07, at 09:59, Michael Heerdegen <michael_heerdegen@web.de> wrote:
> Marcin Borkowski <mbork@mbork.pl> writes:
>
>> (easy-mmode-defmap ecat-mode-map
>> `(((kbd "C-c .") . ecat-basic-map))
>> "Keymap for `ecat-mode'.")
>
> I don't know much about this but passing an unevaluated `kbd' expression
> doesn't look right to me.
Stupid me, you're right, of course.
Best,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to define a prefixed map for a minor mode?
2020-06-07 6:50 How to define a prefixed map for a minor mode? Marcin Borkowski
2020-06-07 7:54 ` Jamie Beardslee
2020-06-07 7:59 ` Michael Heerdegen
@ 2020-06-07 10:18 ` Joost Kremers
2 siblings, 0 replies; 9+ messages in thread
From: Joost Kremers @ 2020-06-07 10:18 UTC (permalink / raw)
To: Marcin Borkowski; +Cc: help-gnu-emacs
On Sun, Jun 07 2020, Marcin Borkowski wrote:
> Hi all,
>
> continuing my work on a (simplistic) Emacs CAT, I want to define
> a minor
> mode. However, I'm stuck on defining its keymap. I want all
> the
> commands prefixed by e.g. `C-c .', and here's what I have:
>
> --8<---------------cut
> here---------------start------------->8---
> (setq ecat-basic-map (make-sparse-keymap))
>
> (define-key ecat-basic-map (kbd "p")
> #'ecat-highlight-previous-sentence)
> (define-key ecat-basic-map (kbd "n")
> #'ecat-highlight-next-sentence)
> (define-key ecat-basic-map (kbd ".")
> #'ecat-highlight-this-sentence)
>
> (easy-mmode-defmap ecat-mode-map
> `(((kbd "C-c .") . ecat-basic-map))
> "Keymap for `ecat-mode'.")
>
> (define-minor-mode ecat-mode
> "Toggle Emacs CAT mode."
> :lighter " CAT"
> :keymap ecat-mode-map
> (if ecat-mode
> (ecat-highlight-this-sentence)
> (delete-overlay ecat-sentence-overlay)))
> --8<---------------cut
> here---------------end--------------->8---
>
> Alas, this does not seem to work - after pressing `C-c .' (when
> the mode
> is one!) I get "C-c . is undefined".
>
> What am I doing wrong? Is there a "canonical" method of
> defining
> a minor mode whose bindings start with some prefix?
>
> TIA,
In one package of mine, I do this:
```
(eval-and-compile
(define-prefix-command 'ebib-slave-map)
(suppress-keymap 'ebib-slave-map 'no-digits)
(define-key ebib-slave-map "c" #'ebib-slave-create-slave)
(define-key ebib-slave-map "a" #'ebib-slave-add-entry)
(define-key ebib-slave-map "d" #'ebib-slave-delete-entry)
(define-key ebib-slave-map "m" #'ebib-slave-switch-to-master))
```
and in the major mode's map:
```
(defvar ebib-index-mode-map
(let ((map (make-keymap)))
(suppress-keymap map 'no-digits)
;; [...]
(define-key map "M" 'ebib-slave-map)
;; [...]
map)
"Keymap for the ebib index buffer.")
```
I'm not sure if that's what you're looking for, though, because
`ebib-slave-map` isn't tied to a minor mode. But perhaps you can
adapt it to your needs.
--
Joost Kremers
Life has its moments
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-06-08 11:23 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-07 6:50 How to define a prefixed map for a minor mode? Marcin Borkowski
2020-06-07 7:54 ` Jamie Beardslee
2020-06-07 20:45 ` Marcin Borkowski
2020-06-07 7:59 ` Michael Heerdegen
2020-06-07 8:16 ` Michael Heerdegen
2020-06-07 20:45 ` Marcin Borkowski
2020-06-08 11:23 ` Michael Heerdegen
2020-06-07 20:44 ` Marcin Borkowski
2020-06-07 10:18 ` Joost Kremers
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).