0

If I have both a major and minor mode in effect, I expect that the MINOR keymap will override. But that's not what happens!

The major map has (among other things) a weird binding for SPC, and it does not have any inserts. By contrast, the minor map inherits from text-mode.

But when the minor mode is in effect, I still don't get any self-inserts, and SPC is still weird. I do see my additional custom minor mode commands. But I wanted the inherited text-mode keys to override the ones that the major mode redefined.

Do I misunderstand the precedence of how keys are looked up, or have I somehow defined my keymaps incorrectly, or is the problem in my mode definitions?

Here is the simplified code:

;; MAJOR MODE

(defvar-keymap sd-mode-map
  :parent nil  ;still gets most commands?
  :suppress t  ;get rid of self-insert
  "SPC"     'sd-next-line)

(defun sd-mode ()
  [...]  
  (interactive)
  (delay-mode-hooks
    (setq major-mode 'sd-mode)  
    (kill-all-local-variables)
    (use-local-map sd-mode-map)
    ;; business
    (setq buffer-read-only t))
  (run-mode-hooks 'sd-mode-hook))

;; MINOR MODE

(defvar sd-edit-mode-map
  (let ((map (make-sparse-keymap "Sd/Edit")))
    (set-keymap-parent map text-mode-map)
    (define-key map "<right>" 'sd-some-thing)
    map)
  "My minor mode keymap")

(define-minor-mode sd-edit-mode
  "Whatever."
  :keymap sd-edit-mode-map
  (message "Your minor mode is in effect!")
  (setq buffer-read-only nil))
6
  • emacs.stackexchange.com/tags/elisp/info
    – NickD
    Commented Jun 4 at 14:01
  • Don't have time to check closer now, but I'm guessing you're missing something. Minor-mode maps always override major-mode mappings. Do you see the same thing with emacs -Q (no init file) and just the code you posted?
    – Drew
    Commented Jun 4 at 14:40
  • I know I'm "missing something", that's why I wrote this question! Commented Jun 4 at 18:50
  • Do you see the same thing with emacs -Q (no init file) and just the code you posted? If not, bisect your init file to find the culprit.
    – Drew
    Commented Jun 5 at 21:27
  • "I can't be bothered to read what you posted, and I have no theory of anything else you could be doing to cause the problem. I am clueless. Did you try rebooting?". Thanks, Drew! Commented Jun 8 at 0:40

1 Answer 1

0

The self-insert-command bindings do not come from text-mode map; they come from the global map. The other problem is that the :suppress feature on the major mode keymap will still prevent the minor keymap from seeing the normal self-insert-commands (even when the minor mode's keymap inherits from global-map).

Just make sure that the major mode puts the buffer in read-only mode, don't suppress the self-insert commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.