Keymap problem setting up custom keybindings
-
M-: emacs-version: 26.3 -
M-: (lm-version "binder.el"): 0.4.2
I don't know why but while following the tutorial, I noticed that a lot of keybindings didn't worked. After closing and opening Emacs some more times all keybindings stopped working.
Considering that they stopped working, and also because I had some problems with the keys sequence of some default keybindings, I've tried to set my custom keybindings:
(global-set-key (kbd "<C-kp-subtract>") 'binder-previous)
(global-set-key (kbd "<C-kp-add>") 'binder-next)
(global-set-key (kbd "<C-kp-divide>") 'binder-reveal-in-sidebar)
(global-set-key (kbd "<C-kp-multiply>") 'binder-toggle-sidebar)
The problem is that I'm always receiving the message "set-transient-map PCH: (wrong-type-argument keymapp nil)", this only happens with custom keybindings set up as global-keys, the custom keybindings stills works fine but it prevents the usage of some other things, like to rename a note since it uses the echo area/minibuffer to rename and the message appears every time a key is pressed.
If I try to remap for the binder-mode only, I receive "Wrong argument type: keymap nil" and the keybinding didn't work at all.
(global-set-key (kbd "<C-kp-divide>") #'binder-reveal-in-sidebar)
(eval-after-load 'binder
'(define-key binder-mode (kbd "<C-kp-subtract>") #'binder-previous))
(eval-after-load 'binder
'(define-key binder-mode (kbd "<C-kp-add>") #'binder-next))
(eval-after-load 'binder
'(define-key binder-mode (kbd "<C-kp-multiply>") #'binder-toggle-sidebar))
(eval-after-load 'binder
'(define-key binder-mode (kbd "C-\\") #'binder-notes-expand-window))
First thing's first... do the default key bindings work when you load Emacs with this?
emacs -Q -l PATH/TO/binder.el -l PATH/TO/binder-tutorial.el
Nice, they do work!
I'm pretty new to Emacs but looks like this -Q just ignore the init.el (thus ignoring installed packages) except for those I'm explicitly loading.
So, the problem might be installed packages being in conflict with binder?
Yes, when debugging it's essential to test with -Q to bypass the init.
If you're new to Emacs and you've been pasting random stuff into your init file (probably encouraged by people on reddit) that's not a good way to go about it. This is essentially the manual override option, and implies that you really know what you're doing. Use M-x customize-option to set things up until you're fluent in Elisp. (You can still learn how options are set in lisp by clicking State > Show Saved Lisp Expression.)
That said, currently the only way to override key bindings is in your init, but you can safely add these after the custom-set-* declarations. With the binder-next|previous commands, these are not in the global map, so:
(with-eval-after-load 'binder
(define-key binder-navigation-map (kbd "<C-kp-add>") 'binder-next)
(define-key binder-navigation-map (kbd "<C-kp-subtract>") 'binder-previous))
Let me know if this still raises an error, which will be because the key sequence is read as a single character.
Thanks for the heads up, I don't really paste things randomly on my init.el. :}
I've started a Vanilla Emacs some weeks ago to learn more about it and cherry picked 40 packages.
I read on how to keep init.el clean and safe and I keep my .emacs.d as a git repo so I can keep track of changes and revert back if something goes wrong.
My Emacs loads in about 0.3 seconds with only 40 packages, or 0.9 seconds if I enable the Dashboard package, a --debug-init doesn't warn about any conflict or broken things. I will look if I can uninstall some packages for it to be cleaner and safer, maybe 40 packages is too much.
Is also good to know about M-x customize-option, never heard anyone talking about that. I will try it to see how it goes if I have to change something in the future, I'm already using M-x customize-themes instead of enabling it manually so customize-option might be the way to go.
I wrote the keybindings using binder-nativation-map instead of binder-mode as you said:
(with-eval-after-load 'binder
(define-key binder-navigation-map (kbd "<C-kp-add>") 'binder-next)
(define-key binder-navigation-map (kbd "<C-kp-subtract>") 'binder-previous)
(define-key binder-navigation-map (kbd "<C-kp-divide>") 'binder-reveal-in-sidebar)
(define-key binder-navigation-map (kbd "<C-kp-multiply>") 'binder-toggle-sidebar))
It worked, but Emacs still echo the keymap error, so when I'm trying to rename a note it's difficult as every time I press any key it echoes the error and I can't read what is being written.

Sorry, only the commands binder-next and binder-previous live in binder-navigation-map, whereas the other keys are in binder-mode-map. The latter inherits from the former, so you could bind everything in binder-mode-map but it's binder-navigation-map that allows repeating the last key for just that map e.g. C-c ] ] [ [.
I've added some more safety to the way this gets activated. Please update from MELPA (unstable) in a few hours, or from this repo, and report back if you still get the same issue.