Better spatial navigation of YAML docs
We'll see how useful this is. Remember `g t`
This commit is contained in:
parent
0f6d77f89b
commit
f269ef0cb0
1 changed files with 21 additions and 16 deletions
|
@ -28,29 +28,34 @@ Configuring Ansible and YAML
|
||||||
My day job now involves a lot of Ansible, and I’ve been struggling to get the right balance here.
|
My day job now involves a lot of Ansible, and I’ve been struggling to get the right balance here.
|
||||||
|
|
||||||
Much of the conflict stems from whether to use [[file:ha-programming.org::*Tree Sitter][Tree Sitter]] for the YAML mode or not.
|
Much of the conflict stems from whether to use [[file:ha-programming.org::*Tree Sitter][Tree Sitter]] for the YAML mode or not.
|
||||||
|
|
||||||
* Visual Indentation
|
* Visual Indentation
|
||||||
Moving by lines is our default navigation mode, but for Yaml and Python, that doesn’t have s-expressions, we need something to move around by blocks. The [[https://codeberg.org/ideasman42/emacs-spatial-navigate][spatial navigation]] project attempts to address this. The problem is how to bind the functions.
|
Moving by lines is our default navigation mode, but for Yaml and Python, that doesn’t have s-expressions, we need something to move around by blocks. The [[https://codeberg.org/ideasman42/emacs-spatial-navigate][spatial navigation]] project attempts to address this. The problem is how to bind the functions.
|
||||||
|
|
||||||
The obvious keybindings are ~M-h/j/k/l~ … but that is used … well, somewhat. In org files, this is a way to move the outline of subtrees around. Useful, and =spatial-navigate= wouldn’t be helpful in org files anyway.
|
The obvious keybindings are ~M-h/j/k/l~ … but that is used … well, somewhat. In org files, this is a way to move the outline of subtrees around. Useful, and =spatial-navigate= wouldn’t be helpful in org files anyway.
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(use-package spatial-navigate
|
(use-package spatial-navigate
|
||||||
:straight (:repo "https://codeberg.org/ideasman42/emacs-spatial-navigate")
|
:straight (:repo "https://codeberg.org/ideasman42/emacs-spatial-navigate")
|
||||||
:config
|
:config
|
||||||
;; Normal State movement has a number of conflict in other mode maps, for instance:
|
(pretty-hydra-define spatial-navigate (:color amaranth :quit-key "q")
|
||||||
;; Overrides: `kill-sentence'
|
("Box"
|
||||||
(define-key evil-normal-state-map (kbd "M-k") 'spatial-navigate-backward-vertical-box)
|
(("k" spatial-navigate-backward-vertical-box "up")
|
||||||
;; Overrides: `default-indent-new-line'
|
("j" spatial-navigate-forward-vertical-box "Down")
|
||||||
(define-key evil-normal-state-map (kbd "M-j") 'spatial-navigate-forward-vertical-box)
|
("h" spatial-navigate-backward-horizontal-box "Down")
|
||||||
;; Overrides: `beginning-of-defun'
|
("l" spatial-navigate-forward-horizontal-box "Down"))
|
||||||
(define-key evil-normal-state-map (kbd "M-h") 'spatial-navigate-backward-horizontal-box)
|
"Bar"
|
||||||
;; Overrides my: `beginning-of-next-defun'
|
(("K" spatial-navigate-backward-vertical-bar "up")
|
||||||
(define-key evil-normal-state-map (kbd "M-l") 'spatial-navigate-forward-horizontal-box)
|
("J" spatial-navigate-forward-vertical-bar "Down")
|
||||||
|
("H" spatial-navigate-backward-horizontal-bar "Down")
|
||||||
|
("L" spatial-navigate-forward-horizontal-bar "Down")))))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
;; Overrides: `indent-for-tab-command' (not good for normal state)
|
And we can attach this menu to the “g” section:
|
||||||
(define-key evil-normal-state-map (kbd "<backtab>") 'spatial-navigate-backward-horizontal-bar)
|
#+begin_src emacs-lisp
|
||||||
(define-key evil-normal-state-map (kbd "<tab>") 'spatial-navigate-forward-horizontal-bar))
|
(use-package spatial-navigate
|
||||||
|
:general
|
||||||
|
(:states '(normal visual motion operator)
|
||||||
|
"g t" '("spatial nav" . spatial-navigate/body)))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
The [[https://github.com/antonj/Highlight-Indentation-for-Emacs][Highlight-Indentation]] project highlights each of the indent levels, which could be helpful for these modes:
|
The [[https://github.com/antonj/Highlight-Indentation-for-Emacs][Highlight-Indentation]] project highlights each of the indent levels, which could be helpful for these modes:
|
||||||
|
|
Loading…
Reference in a new issue