Fix keymap precedence for evil users in the org-roam-buffer
`org-roam-mode` based buffers use `magit-section` to render sections. The problem is that `magit-section` will layer keymaps for each section under a text property. In Emacs, text property based keymaps have a higher precedence for a lookup[0] than `emulation-mode-map-alists`, in which Evil and leader keymaps are stored in. [0]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Searching-Keymaps.html
This commit is contained in:
parent
ff331781c5
commit
13f0c4785e
1 changed files with 40 additions and 21 deletions
|
@ -136,27 +136,46 @@ In case of failure, fail gracefully."
|
||||||
"t" #'org-roam-tag-add
|
"t" #'org-roam-tag-add
|
||||||
"T" #'org-roam-tag-remove
|
"T" #'org-roam-tag-remove
|
||||||
"r" #'org-roam-ref-add
|
"r" #'org-roam-ref-add
|
||||||
"R" #'org-roam-ref-remove))
|
"R" #'org-roam-ref-remove)))
|
||||||
(:map org-roam-mode-map
|
|
||||||
:when (featurep! :editor evil +everywhere)
|
(when (featurep! :editor evil +everywhere)
|
||||||
:nv "]" #'magit-section-forward-sibling
|
(add-hook! 'org-roam-mode-hook
|
||||||
:nv "[" #'magit-section-backward-sibling
|
(defun +org-roam-detach-magit-section-mode-map-h ()
|
||||||
:nv "gj" #'magit-section-forward-sibling
|
"Detach `magit-section-mode-map' from `org-roam-mode-map'.
|
||||||
:nv "gk" #'magit-section-backward-sibling
|
Inheriting its keymaps introduces a lot of conflicts in
|
||||||
:nv "gr" #'revert-buffer
|
`org-roam-mode' based buffers, where Evil and leader keybindings
|
||||||
:nv "gR" #'revert-buffer
|
will become completely overridden. This is because `magit-section'
|
||||||
:nv "z1" #'magit-section-show-level-1
|
uses 'keymap text-property to attach section-unique keymaps, which
|
||||||
:nv "z2" #'magit-section-show-level-2
|
has a higher level of precedence than `emulation-mode-map-alists'.
|
||||||
:nv "z3" #'magit-section-show-level-3
|
|
||||||
:nv "z4" #'magit-section-show-level-4
|
Note: We do this each time through the hook, because otherwise
|
||||||
:nv "za" #'magit-section-toggle
|
sections seems to ignore the detachment."
|
||||||
:nv "zc" #'magit-section-hide
|
(set-keymap-parent org-roam-mode-map nil)))
|
||||||
:nv "zC" #'magit-section-hide-children
|
|
||||||
:nv "zo" #'magit-section-show
|
(map! :map org-roam-mode-map
|
||||||
:nv "zO" #'magit-section-show-children
|
:nv "]" #'magit-section-forward-sibling
|
||||||
:nv "zr" #'magit-section-show-level-4-all
|
:nv "[" #'magit-section-backward-sibling
|
||||||
:nv "C-j" #'magit-section-forward
|
:nv "gj" #'magit-section-forward-sibling
|
||||||
:nv "C-k" #'magit-section-backward)))
|
:nv "gk" #'magit-section-backward-sibling
|
||||||
|
:nv "gr" #'revert-buffer
|
||||||
|
:nv "gR" #'revert-buffer
|
||||||
|
:nv "z1" #'magit-section-show-level-1
|
||||||
|
:nv "z2" #'magit-section-show-level-2
|
||||||
|
:nv "z3" #'magit-section-show-level-3
|
||||||
|
:nv "z4" #'magit-section-show-level-4
|
||||||
|
:nv "za" #'magit-section-toggle
|
||||||
|
:nv "zc" #'magit-section-hide
|
||||||
|
:nv "zC" #'magit-section-hide-children
|
||||||
|
:nv "zo" #'magit-section-show
|
||||||
|
:nv "zO" #'magit-section-show-children
|
||||||
|
:nv "zr" #'magit-section-show-level-4-all
|
||||||
|
:nv "C-j" #'magit-section-forward
|
||||||
|
:nv "C-k" #'magit-section-backward
|
||||||
|
:g "M-p" #'magit-section-backward-sibling
|
||||||
|
:g "M-n" #'magit-section-forward-sibling
|
||||||
|
:g [tab] #'magit-section-toggle
|
||||||
|
:g [C-tab] #'magit-section-cycle
|
||||||
|
:g [backtab] #'magit-section-cycle-global)))
|
||||||
|
|
||||||
|
|
||||||
;; Since the org module lazy loads org-protocol (waits until an org URL is
|
;; Since the org module lazy loads org-protocol (waits until an org URL is
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue