Better spatial navigation of YAML docs

We'll see how useful this is. Remember `g t`
This commit is contained in:
Howard Abrams 2024-07-04 23:20:35 -07:00
parent 0f6d77f89b
commit f269ef0cb0

View file

@ -28,7 +28,6 @@ Configuring Ansible and YAML
My day job now involves a lot of Ansible, and Ive been struggling to get the right balance here. My day job now involves a lot of Ansible, and Ive 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 doesnt 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 doesnt 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.
@ -38,19 +37,25 @@ The obvious keybindings are ~M-h/j/k/l~ … but that is used … well, somewhat.
(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: