[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to define a prefixed map for a minor mode?

From: Joost Kremers
Subject: Re: How to define a prefixed map for a minor mode?
Date: Sun, 07 Jun 2020 12:18:04 +0200
User-agent: mu4e 1.4.6; emacs 27.0.91

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
    (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?


In one package of mine, I do this:

 (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)
   ;; [...]
 "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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]