Visual indents and indent navigation
This is useful for Yaml ... maybe I should make it only available in YAML files?
This commit is contained in:
parent
acc8cd98ba
commit
9047dd7137
1 changed files with 63 additions and 0 deletions
|
@ -29,6 +29,69 @@ My day job now involves a lot of Ansible, and I’ve been struggling to get the
|
|||
|
||||
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
|
||||
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.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(use-package spatial-navigate
|
||||
:straight (:repo "https://codeberg.org/ideasman42/emacs-spatial-navigate")
|
||||
:config
|
||||
;; Normal State movement has a number of conflict in other mode maps, for instance:
|
||||
;; Overrides: `kill-sentence'
|
||||
(define-key evil-normal-state-map (kbd "M-k") 'spatial-navigate-backward-vertical-box)
|
||||
;; Overrides: `default-indent-new-line'
|
||||
(define-key evil-normal-state-map (kbd "M-j") 'spatial-navigate-forward-vertical-box)
|
||||
;; Overrides: `beginning-of-defun'
|
||||
(define-key evil-normal-state-map (kbd "M-h") 'spatial-navigate-backward-horizontal-box)
|
||||
;; Overrides my: `beginning-of-next-defun'
|
||||
(define-key evil-normal-state-map (kbd "M-l") 'spatial-navigate-forward-horizontal-box)
|
||||
|
||||
;; Overrides: `indent-for-tab-command' (not good for normal state)
|
||||
(define-key evil-normal-state-map (kbd "<backtab>") 'spatial-navigate-backward-horizontal-bar)
|
||||
(define-key evil-normal-state-map (kbd "<tab>") 'spatial-navigate-forward-horizontal-bar))
|
||||
#+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:
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(use-package highlight-indentation
|
||||
:straight (:host github :repo "antonj/Highlight-Indentation-for-Emacs")
|
||||
:hook ((yaml-mode . highlight-indentation-mode)
|
||||
(yaml-ts-mode . highlight-indentation-mode)
|
||||
(python-mode . highlight-indentation-mode)))
|
||||
#+end_src
|
||||
|
||||
This project has another display feature, which just lines up the current level. So I’ve created a toggle for this:
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(use-package highlight-indentation
|
||||
:config
|
||||
(setq highlight-indentation-blank-lines t)
|
||||
(set-face-background 'highlight-indentation-face "#332c26")
|
||||
(set-face-background 'highlight-indentation-current-column-face "#66615c")
|
||||
|
||||
(defun ha-toggle-highlight-indentation ()
|
||||
"Toggles through the indentation modes."
|
||||
(interactive)
|
||||
(cond
|
||||
(highlight-indentation-mode
|
||||
(progn
|
||||
(highlight-indentation-mode -1)
|
||||
(highlight-indentation-current-column-mode 1)))
|
||||
(highlight-indentation-current-column-mode
|
||||
(progn
|
||||
(highlight-indentation-mode -1)
|
||||
(highlight-indentation-current-column-mode -1)))
|
||||
(t
|
||||
(progn
|
||||
(highlight-indentation-mode 1)
|
||||
(highlight-indentation-current-column-mode -1)))))
|
||||
|
||||
(ha-leader "t i" '("show indents" . ha-toggle-highlight-indentation)))
|
||||
#+end_src
|
||||
|
||||
* YAML
|
||||
Doing a lot of [[https://github.com/yoshiki/yaml-mode][YAML work]], but the =yaml-mode= project needs a new maintainer, so I might as well switch over to the T version.
|
||||
, so I’ve switch to [[https://github.com/zkry/yaml-pro][yaml-pro]] that is now based on Tree Sitter. Let’s make sure the Tree-Sitter version works:
|
||||
|
|
Loading…
Reference in a new issue