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

Support comments to skip formatting #86

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Support comments to skip formatting #86

wants to merge 2 commits into from

Conversation

sthiele
Copy link
Member

@sthiele sthiele commented Oct 3, 2022

The comment % fmt: off will turn formatting off
and % fmt: on turns it on again.

% fmt: off
This section will not be formatted
% fmt: on

@sthiele sthiele linked an issue Oct 3, 2022 that may be closed by this pull request
@sthiele sthiele mentioned this pull request Oct 3, 2022
@sthiele sthiele changed the base branch from main to next October 3, 2022 06:01
@florianfischer91
Copy link

If I only have a single % fmt: off without a % fmt: on afterwards, everything after % fmt: off is not printed. This also happens if i use something like % fmt: off fmt: on on the same line.

In the first case i would expect to turn of formatting as long as there is no % fmt: on which would mean if i insert % fmt: off at the beginning of a file the whole file would not be formatted.
In the second case the comment should have no effect at all.

Any chance to also support something like

:- bounds(L,U),0 < L,not counter(1,L). % fmt: skip
% which would be a shorthand for
% fmt: off
:- bounds(L,U),0 < L,not counter(1,L).
% fmt: on

The comment `% fmt: off` will turn formatting off
and `% fmt: on` turns it on again.

```
% fmt: off
This section will not be formatted
% fmt: on
```
@sthiele
Copy link
Member Author

sthiele commented Oct 3, 2022

If I only have a single % fmt: off without a % fmt: on afterwards, everything after % fmt: off is not printed.
.. i would expect to turn of formatting as long as there is no % fmt: on which would mean if i insert % fmt: off at the beginning of a file the whole file would not be formatted.

This should be working now as you expect. The unformated code at the end of the file is now written.

@sthiele
Copy link
Member Author

sthiele commented Oct 3, 2022

This also happens if i use something like % fmt: off fmt: on on the same line.
... the comment should have no effect at all.

I do currently no parsing of the comment, I have a global variable skip: bool that is set to true if a comment contains fmt: off
and if skip is true and a comment contains fmt: on skip is set to false.

What behavior would you expect for % fmt: on fmt: off ?

@sthiele
Copy link
Member Author

sthiele commented Oct 3, 2022

Any chance to also support something like

:- bounds(L,U),0 < L,not counter(1,L). % fmt: skip
% which would be a shorthand for
% fmt: off
:- bounds(L,U),0 < L,not counter(1,L).
% fmt: on

I guess so. I'm not sure what the semantic would be for a multi line statement should it consider the statement (rule) or the line?

like in

            a(X, Y, Z) :-
       b(X), c(Y) % fmt: skip
    d(Z).

Would the rule stay the same or just the line ?

a(X, Y, Z) :-
       b(X), c(Y) % fmt: skip
    d(Z).

@florianfischer91
Copy link

Sry for the delayed answer. I was quite busy.
% fmt: off fmt: on should actually have no effect at all, you could see it as

% fmt: off
% fmt: on

I'm not sure if this case has to be adressed or if it should just print out a warning or something like that.

Regarding 'skip', i would expect that just the line stays the same.

Base automatically changed from next to main April 30, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

format on/off/skip
2 participants