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 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 October 22, 2019 20:05
@@ -0,0 +1,119 @@
#' Add positional information of token to next terminal
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Say in documentation that this function modifies env_current.

@lorenzwalthert lorenzwalthert force-pushed the stylerignore branch 4 times, most recently from f4a0ca6 to 36083e0 Compare November 30, 2019 16:43
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.

Conditional styling
1 participant