I want to edit a big, hairy YAML file in Emacs. File structure is implied by indentation: If line A is indented ten spaces, then A starts a section that includes every following line that is indented by more than ten spaces. This is a fairly common convention that is used well beyond YAML.
What I really want is an emacs mode that has definitions that respect this structure. For example:
forward-sexp
to skip past a sexp, where a sexp is implied by the indentation rather than by matching pairs of brackets. Similarly, I'd like there to be other navigation commands to move to the line after the end of the current section, to the next sibling section to the current one, and so forth.I have looked at yaml-mode
, but it doesn't do anything useful. Several people have suggested I try Python mode, but it doesn't work very well for this purpose.
A generic indented-lines mode seems like the sort of thing someone would have written a long time ago, but if it exists, I can't find it. Or maybe there's some way to hack outline-mode
to work the way I want?
Thanks for any suggestions.
Using outline-mode
and setting outline-regexp
to " *"
doesn't get me exactly what I want, but it does get a fair amount of it. For example, hide-subtree
, bound to C-c C-d
by default, seems to collapse the current section in just the way I described above. outline-forward-same-level
, bound to C-c C-f
, also does what I wanted.
Some things still don't work quite right. I'll modify this answer if I find any other useful ways to tweak outline-mode
.
This is a slight modification of a suggestion of José Antonio Ortega Ruiz.
To go to the next/current sibling I wrote a function. Load the file and use M-x my-yaml-next-sibling
. This package is still rudimentary but quite useful IMO !
update: this function has grown into a real package, indent-tools. Its first goal is navigation in blocks of indentation: go to the next node of same indentation, to the parent, etc. Then it's handy to indent blocks, comment, fold, etc.
Not in melpa yet but in the process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With