Closed sriramkswamy closed 8 years ago
Keybindings with evil is a bit tricky because it really wants its keybindings to be at the top of the stack. For that reason evil-smartparens adds keybindings using a function. When evil-smartparens-mode is enabled, this function runs:
(defun evil-sp--add-bindings ()
(when smartparens-strict-mode
(evil-define-key 'normal evil-smartparens-mode-map
(kbd "d") #'evil-sp-delete
(kbd "c") #'evil-sp-change
(kbd "y") #'evil-sp-yank
(kbd "S") #'evil-sp-change-whole-line
(kbd "X") #'evil-sp-backward-delete-char
(kbd "x") #'evil-sp-delete-char)
(evil-define-key 'visual evil-smartparens-mode-map
(kbd "X") #'evil-sp-delete
(kbd "x") #'evil-sp-delete))
(evil-define-key 'normal evil-smartparens-mode-map
(kbd "D") #'evil-sp-delete-line
(kbd "Y") #'evil-sp-yank-line
(kbd "C") #'evil-sp-change-line)
(evil-define-key 'insert evil-smartparens-mode-map
(kbd "DEL") 'sp-backward-delete-char)
(evil-define-key 'visual evil-smartparens-mode-map
(kbd "o") #'evil-sp-override)
(evil-normalize-keymaps))
So instead of worrying about keymap precedence the easiest thing is probably to just redefine that function, with your preferred changes, in a (with-eval-after-load 'evil-smartparens)
block.
I'm sorry this is kind of convoluted, but I hope this is an acceptable solution.
Ah, I see. I thought that I might have to tweak the source itself but this is very helpful. Thank you!
As a follow up I have another question. Manually evaluating (C-x C-e
) the keybinding nil statement and the new keybinding statement makes sure my keybinding prevails over that of evil-smartparens'. Is there a particular reason for this?
I will leave it to you as to whether this question needs to be closed or not.
Is there a particular reason for this?
Yes, when you do this you add your bindings to the top of the stack.
In a new buffer they won't be, and if you do e.g. M-x revert-buffer
they'll get shadowed by evil and evil-smartparens again.
Glad your problem got solved. I'll close this for now and if someone else runs into this I'll see about adding a better way of adding new keybindings.
For what it's worth, I also ran into this problem. I remember being really confused that my keybindings weren't working--IMO, even just a warning in the readme, or something along those lines, would go a long ways.
I am an amateur at elisp and with what I know, I could not change the
S
binding (bound toevil-sp-change-whole-line
function. I useS
for other purposes and wanted to know if there is a way to change this binding.I use a
use-package
definition forevil-smartparens
and itsbind
is not evil friendly, so I use general.el for consistent bindings. After that didn't work, I tried to just use the normalevil-define-key
bindings. Those didn't work either. I tried to set the default binding tonil
and set these bindings again inside(with-eval-after-load 'evil-smartparens)
block but that didn't make any difference either. Finally, I created a function with just binding definitions and created a hook based on(add-hook 'evil-smartparens-mode-hook #'my-function)
but that also didn't work.I just want to know if I'm doing something wrong. If so, it would be very helpful if you can correct it. Thanks!