-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Folding #25
Comments
+1 |
It looks as if markdown-mode provides this feature, though it has an easier time with providing it because it just needs to look at headers. |
Something like this in .emacs
Or individual YAML files
|
@vibrog Thanks for the solution, it almost works for me, but the regexp you provide does not accept some of the keys that I would like to use as outlines. I'm editing a YAML file containing an OpenAPI 3 spec, and I have some paths like this:
I tried editing the regex, so that the first |
- via outline minor mode - see yoshiki/yaml-mode#25 (comment)
Hello, in case someone is interested, on my side I have this for now,: (use-package yaml-mode
:ensure t
:mode (".yaml$")
:hook
(yaml-mode . yaml-mode-outline-hook)
:init
(defun yaml-outline-level ()
"Return the outline level based on the indentation, hardcoded at 2 spaces."
(s-count-matches "[ ]\\{2\\}" (match-string 0)))
(defun yaml-mode-outline-hook ()
(outline-minor-mode)
(setq outline-regexp "^\\([ ]\\{2\\}\\)*\\([-] \\)?\\([\"][^\"]*[\"]\\|[a-zA-Z0-9_-]*\\): *\\([>|]\\|&[a-zA-Z0-9_-]*\\)?$")
(setq outline-level 'yaml-outline-level))
) |
@seblemaguer This is not entirely correct. For a counterexample:
Putting point on I cropped the regexp after |
This is what works pretty well for me: (setq outline-regexp
(rx
(seq
bol
(group (zero-or-more " ")
(or (group
(seq (or (seq "\"" (*? (not (in "\"" "\n"))) "\"")
(seq "'" (*? (not (in "'" "\n"))) "'")
(*? (not (in ":" "\n"))))
":"
(?? (seq
(*? " ")
(or (seq "&" (one-or-more nonl))
(seq ">-")
(seq "|"))
eol))))
(group (seq
"- "
(+ (not (in ":" "\n")))
":"
(+ nonl)
eol))))))) With this YAML file for testing: # file test
test:
some: 'key'
yea: 'hi'
sub:
subkey: is nice
# some abc
test: >-
some text and such
I can put things here, without care <3
other: |
asdf
and: hahaha
other:
yes:
- 'string'
- 'string'
ups:
- geht
- trotzdem
other_ups:
- "hey": abc
sup: false
array_of_hashes: &name
- hello: my dear
this: works
"nice thing": yaya
subobjects:
ear: worm
- other: my friend |
@leoc thanks, yours is definitely better than mine :D |
- selective-display: for folding everything at a particular level + from: https://gist.github.com/antonj/874106 @antonj - outline-minor-mode: for folding at various levels, when you only want to concentrate on specific parts of the file. + from: yoshiki/yaml-mode#25 @leoc Despite this hackery, the folding experience remains sub-par and broken (but it's better than having nothing)
@leoc Is your regex working properly for the Everything (except the case mentioned above) works perfectly. Thanks for this helpful regex! ups:
- geht
- trotzdem
other_ups:
- "hey": abc
sup: false |
Hi @phye, yes, it works for me. This is my full yaml-mode config: https://gist.github.com/leoc/f8c0868051003c4ea6eff638bc614575 |
Thansk for your confirmation. |
Just checked further, if I changed your test case a little bit(add value to ups
- geht: world
- trotzdem: new Not sure if you can reproduce it :) |
It would be amazing if the the spacing conformed to the conventional block/indentation such that hs and other default frameworks could know what to fold. |
It would be nice to have an org-mode style folding for nested keys.
The text was updated successfully, but these errors were encountered: