4

EDIT: ANSWER

The cause for the problem in this question was pointed out in the Emacs mailing list. It is due to the (kbd ...) forms not getting evaluated because the keymap in the define-minor-mode is passed as a quoted list. The (kbd ...) forms can be used by using a backquoted list and then placing a , before each (kbd ...) form so that they get evaluated.

END EDIT

I know there are similar questions like mine, but I could not find an answer to my question.

This question was edited (below) because it appears to be a bug (please confirm).

I want my minor-mode bindings to get precedence over the pdf-view major mode bindings.

I define my minor mode with the following code:

(define-minor-mode pdf-continuous-scroll-mode
  "Emulate continuous scroll with two synchronized buffers"
  nil
  " Continuous"
  '(((kbd "j") . (lambda () (interactive) (print "pushed j")))
    ((kbd "k") . (lambda () (interactive) (print "pushed k")))
    ((kbd "C-n") . (lambda () (interactive) (print "pushed C-n")))
    ((kbd "C-p") . (lambda () (interactive)(print "pushed C-p"))))
  (print "loaded minor mode"))

Now when I evaluate this while I am viewing a document with PDF-tools and enable the minor mode, then the j/k bindings work but the C-n/C-p bindings do not because Emacs still uses the pdf-view major mode keybindings (i.e. it scrolls the document). I find here that minor-mode keymaps should have highest precedence behind overlay keymaps. I checked if maybe there is some overlay keymap used in PDF-tools but I could not find one.

Can anybody explain why my minor mode bindings do not get precedence over de pdf-view major mode bindings?

EDITS

  1. I find the C-n and C-p do not even get precedence over the global-keymap. I can just start emacs using emacs -Q, evaluate the code and activate the minor mode. Then still C-n and C-p do not work. Please someone confirm this is a bug, then I will report the bug.

END EDIT

3
  • Please post the Spacemacs question separately. One question per question. Thx. – Drew Sep 25 '20 at 17:27
  • I created a bug report and removed the Spacemacs question. Thanks again! – dalanicolai Sep 25 '20 at 18:02
  • Thanks for creating the bug report. I expect this will be fixed soon - shouldn't be complicated, I think – Drew Sep 25 '20 at 18:42
3

I think it's a bug.

If you don't use that alist as the KEYMAP arg, but instead you create a keymap, assign it to a variable, use define-key with (kbd "C-n") etc., and use that variable as the KEYMAP arg, then it works.

Please consider using M-x report-emacs-bug, to report this.

(setq toto-map (make-sparse-keymap))
(defun foo () "..." (interactive) (message "my C-n"))
(define-key toto-map (kbd "C-n") 'foo)
(define-minor-mode pdf-continuous-scroll-mode
  "Emulate continuous scroll with two synchronized buffers"
  nil
  " Continuous"
  toto-map
  (print "loaded minor mode"))
2
  • Thanks for your answer. The workaround is working fine indeed. I have reported a bug using the report-emacs-bug. – dalanicolai Sep 25 '20 at 18:00
  • A discussion about this being a bug or not can be found here – dalanicolai Oct 3 '20 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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