Skip to content

Ignore certain lines when styling#560

Merged
lorenzwalthert merged 9 commits into
r-lib:masterfrom
lorenzwalthert:stylerignore
Nov 30, 2019
Merged

Ignore certain lines when styling#560
lorenzwalthert merged 9 commits into
r-lib:masterfrom
lorenzwalthert:stylerignore

Conversation

@lorenzwalthert

@lorenzwalthert lorenzwalthert commented Oct 22, 2019

Copy link
Copy Markdown
Collaborator

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
Comment thread R/stylerignore.R
@@ -0,0 +1,119 @@
#' Add positional information of token to next terminal

Copy link
Copy Markdown
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
@lorenzwalthert lorenzwalthert merged commit 54f4e11 into r-lib:master Nov 30, 2019
@lorenzwalthert lorenzwalthert deleted the stylerignore branch November 30, 2019 17:19
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