I am trying to define a minor mode that makes 2 keybindings. This is code i am defining it with:

(define-minor-mode parinfer-mode
  "Uses Parinfer to Format lispy code"
  :lighter " parinfer"
  :keymap '(let ((map (make-sparse-keymap)))
             (define-key map (kbd "C-c t") 'parinfer-mode--toggle)
             (define-key map (kbd "C-c r") 'parinfer-mode--refresh)
  (if parinfer-mode

However, when i later eval parinfer-mode, those bindings remain undefined, and value of parinfer-mode-map is:

 (67 keymap
     (45 keymap
         (99 keymap
             (32 keymap
                 (114 . parinfer)
                 (116 . parinfer-mode--toggle))))))

What should i change to set keymap the way i want?

P.S. I am not interested in defining mode separately, but in understanding what goes wrong in using an approach described in documentation.

  • The :keymap argument is a pain to use correctly. Better stay away from it and just use (defvar parinfer-mode-map (let ... map)) instead (placed before the define-minor-mode). – Stefan Jul 11 '16 at 17:36

Your Answer

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

Browse other questions tagged or ask your own question.