Skip to content
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

Unindent for snippets #1945

Closed
Vampire opened this issue Feb 16, 2023 · 9 comments · Fixed by #1963
Closed

Unindent for snippets #1945

Vampire opened this issue Feb 16, 2023 · 9 comments · Fixed by #1963
Labels
P: maybe Pending approval of low priority request. T: feature Feature.

Comments

@Vampire
Copy link

Vampire commented Feb 16, 2023

Description

It would be nice if snippets would be unindented, so that the leading whitespace that is common to all lines in the snippet is removed, so it starts left-most with the first character.
This should imho even be the default behavior if it will be configurable.

Benefits

No need to cram the snippet code to beginning of line in the source file to have it nice in the docs.

Solution Idea

Just get the leading whitespace of all lines, take the shortest one and remove that from all lines.
If someone has mixed space and tab indents, it is his own fault. :-D

@Vampire Vampire added the T: feature Feature. label Feb 16, 2023
@gir-bot gir-bot added the S: triage Issue needs triage. label Feb 16, 2023
@facelessuser facelessuser added P: maybe Pending approval of low priority request. and removed S: triage Issue needs triage. labels Feb 16, 2023
@facelessuser
Copy link
Owner

Related to this discussion: #1913

If we do this, it would likely only be done when injection "sections" or I guess also when specific line numbers are specified. A full file should already be dedented, and if not, that's on the user. This does run into an issue if you are injecting an indented code block, it would get dedented...but I guess if you indent the snippet syntax, then maybe it'll all work out. I'd have to verify.

This is of course if we just go the simple route and dedent all snippet partials automatically. If we have some syntax (and I don't know what that would even look like) that is meant to signify a dedent should occur, then the user would have complete control of when this does or does not happen.

The actual dedenting should be pretty easy as there are already built-in tools in Python to do so.

Anyways, stuff to think about.

@Vampire
Copy link
Author

Vampire commented Feb 16, 2023

A full file should already be dedented, and if not, that's on the user.

👍

This does run into an issue if you are injecting an indented code block, it would get dedented...but I guess if you indent the snippet syntax, then maybe it'll all work out. I'd have to verify.

Yeah, actually having a way to intentionally indent would probably be nice if you combine different snippets or a snippet with accompanying lines.
Maybe either by indenting the scissors, or by being able to specify how far to indent as number.

@facelessuser
Copy link
Owner

Yeah, snippets can be nested too, so it is something to think about. The idea behind snippets was to just very dumbly insert a file. Feature creep is making it a bit more complicated these days, not that it's a bad thing per se. I'd need to find a way to extend the syntax in a reasonable way if we want an explicit approach.

@Vampire
Copy link
Author

Vampire commented Feb 16, 2023

Actually I just tried, adding indent is possible by indenting the scissors

@facelessuser
Copy link
Owner

Yeah, that is what I figured. We try to respect the indentation of insertion.

facelessuser added a commit that referenced this issue Feb 22, 2023
- Allow `-` and `_` in section names
- If `check_paths` is enabled and a section cannot be found, raise an
  error.
- Add `dedent_subsections` to remove indentation of sections or lines
  that are inserted.

Resolves #1947
Resolves #1946
Resolves #1945
@facelessuser
Copy link
Owner

For now, we are going to add an option that always dedents sectional inserts. Assuming that resolves the problem generally well, we might make it the default in the future. We'll see if that is sufficient or if there is a need for manual dedenting.

@Vampire
Copy link
Author

Vampire commented Feb 24, 2023

I tested the dedent, works perfectly fine here, thanks.
Do you have any idea when 9.10 will be final? :-)

@facelessuser
Copy link
Owner

I have it in beta mainly for the new general-purpose blocks. I'm thinking everything is pretty much cemented there, but I'm getting some active feedback, so just making sure there are no more minor tweaks before I pull the trigger.

I'd say soon-ish? I have no plans for any additional features in 9.10. I'm hoping maybe a week or two, but we'll see.

@Vampire
Copy link
Author

Vampire commented Feb 24, 2023

Great, thanks :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P: maybe Pending approval of low priority request. T: feature Feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants