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

Ignore certain lines when styling #560

Merged
merged 9 commits into from Nov 30, 2019

Conversation

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Oct 22, 2019

Closes #365 as well as it's duplicates #533 and #542, following the #365 (comment). Here is a short example of how to use it, it works both for segments as well as inline:

call(1 ) # styler: off
# styler: off
# also if there are more comments
test_xkj("hier", na.rm = 3, py = 43
         )

x="new" # styler: off
y=1 # none

more_calls(with(arguments))
# styler: on
1 + 1
a(!b)

Taken from the outline in #365, this PR implements the functionality as follows:

Here is how to make sure this code does not get styled:

  • Before parse data is nested, we find the stylerignore tags and add a column
    stylerignore to the parse data which is false for all token except the
    tokens that fall between two stylerignore tags.

  • After code is turned into nested parse data and spaces and newlines are
    computed (must be between terminals, not between any token as currently done with
    default_style_guilde_attributes() edit: Because we need the position of tokens relative to other terminals, not tokens in general when serializing, we must do default_style_guilde_attributes() twice in total now). We store the lag_spaces and
    lag_newline attributes for all terminal tokens that are marked as
    stylerignore in the environment env_current.

  • We proceed as usual with appyling transformers and flattening out the parse
    table.

  • Right before we serialize the parse table, we replace lag_newlines, lag_spaces
    and tokens, text with the initial values for all tokens that were marked as
    stylerignore. Then we serialize.

@lorenzwalthert lorenzwalthert marked this pull request as ready for review Oct 22, 2019
@@ -0,0 +1,119 @@
#' Add positional information of token to next terminal

This comment has been minimized.

Copy link
@lorenzwalthert

lorenzwalthert Oct 30, 2019

Author Collaborator

Say in documentation that this function modifies env_current.

@lorenzwalthert lorenzwalthert force-pushed the lorenzwalthert:stylerignore branch 4 times, most recently from f4a0ca6 to 36083e0 Nov 30, 2019
@lorenzwalthert lorenzwalthert force-pushed the lorenzwalthert:stylerignore branch from 36083e0 to 210c293 Nov 30, 2019
wq
@lorenzwalthert lorenzwalthert force-pushed the lorenzwalthert:stylerignore branch from 210c293 to 38f8c25 Nov 30, 2019
@lorenzwalthert lorenzwalthert merged commit 54f4e11 into r-lib:master Nov 30, 2019
0 of 2 checks passed
0 of 2 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@lorenzwalthert lorenzwalthert deleted the lorenzwalthert:stylerignore branch Nov 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.