[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
What should I do to define C-c bindings in a minor mode?
From: |
Marcin Borkowski |
Subject: |
What should I do to define C-c bindings in a minor mode? |
Date: |
Fri, 07 May 2021 07:43:18 +0200 |
User-agent: |
mu4e 1.1.0; emacs 28.0.50 |
I noticed that
--8<---------------cut here---------------start------------->8---
(define-minor-mode cool-mode
"An extremely cool minor mode."
:lighter " cool!"
:keymap `((,(kbd "C-c C-c") . do-cool-stuff)))
--8<---------------cut here---------------end--------------->8---
Just Works™, and it is so (apparently) because of the existence of
`mode-specific-map'. Do I get it correctly that it works like this:
- C-c is bound in `global-map' to the keymap `mode-specific-map', which
is empty by default.
- I define a key of the form "C-c <whatever>" in `cool-mode-map', either
using the above definition, or `define-key', or whatever means.
- When the user presses `C-c' in cool-mode, Emacs knows that it is
a prefix key because of `global-map' (and `C-c' not being defined in
any other keymaps), so it waits for the next key.
- When the user presses `C-c' for the second time, Emacs looks up the
binding for `C-c C-c' using normal means, IOW, starting with minor
mode keymaps - and since it's there, runs `do-cool-stuff'.
Is that correct?
While at that, are there any downsides to defining minor mode keymaps
like I did above? A very similar example (but without `kbd' and the
backquote) appears in the manual - see (info "(elisp) Defining Minor
Modes"), the definition of `hungry-mode'. Technically, it uses a normal
quote instead of #', so it is against the recommendation of using #' and
not ' for functions, but it still works fine. Is it me hair-splitting
or is the recommended way of defining minor mode keymaps something else?
TIA,
--
Marcin Borkowski
http://mbork.pl
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- What should I do to define C-c bindings in a minor mode?,
Marcin Borkowski <=