Skip to content

Add tools for re-indenting tokens - #217

Merged
lorenzwalthert merged 2 commits into
r-lib:masterfrom
lorenzwalthert:unindent_regex_comments
Oct 8, 2017
Merged

lorenzwalthert merged 2 commits into
r-lib:masterfrom
lorenzwalthert:unindent_regex_comments

Conversation

@lorenzwalthert

Copy link
Copy Markdown
Collaborator

Add tools for re-indenting tokens that match certain regular expression patterns, in particular, to allow strcode code separators. Closes #64, but is actually much more general. The indention level for an arbitrary token text that matches any regular expression in the regex vector passed to the styling function can be controlled. One absolute indention level for all matches in one run can be set. Since we have scope = "spaces" (which does not modify indention), we can just run styler repeatedly and set the indention level of different tokens sequentially. But probably no one would like to do that actually.

See tests/testthat/unindention_regex/random_non_comment_indention-out.R to see the how the indention level for the token bbx was set to 5. This function call that lead to this result can be found in tests/testthat/unindention_regex/random_non_comment_indention-out.R

@lorenzwalthert
lorenzwalthert force-pushed the unindent_regex_comments branch 4 times, most recently from a28d5cb to 02e5aa4 Compare September 22, 2017 15:33
Comment thread R/style_guides.R Outdated
indent_by = 2,
start_comments_with_one_space = FALSE) {
start_comments_with_one_space = FALSE,
reindention = specify_reindention()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

default_reindention()? What is the rationale behind the specify_ prefix?

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.

We can use a forwarder here too to be consistent with #221.

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.

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.

@krlmlr ok?

Comment thread R/style_guides.R Outdated
#' @param comments_only Whether the `regex_reindention_pattern` should only be
#' matched against comments or against all tokens. Mainly added for
#' performance.
specify_reindention <- function(regex_pattern = regex_strcode(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this default to regex_none(), at least for the tidyverse style?

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.

Ok.

Comment thread R/reindent.R Outdated
#' Character vector with the patterns of code separator and title for the three
#' levels of granularity.
#' @export
regex_strcode <- function() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This adds a hard-to-track dependency to strcode. Maybe add to strcode instead (also requires to change the default for the tidyverse)?

Perhaps strcode could also implement a style guide, to showcase extensibility?

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.

Ok, agree, I can export regex_strcode() from the strcode package.

Add tools for re-indenting tokens that match certain regular expression patterns, in particular to allow strcode code separators
@lorenzwalthert
lorenzwalthert force-pushed the unindent_regex_comments branch from aaf86f9 to 8721211 Compare October 8, 2017 12:26
@lorenzwalthert
lorenzwalthert force-pushed the unindent_regex_comments branch from 8721211 to 6141e09 Compare October 8, 2017 12:29
@lorenzwalthert
lorenzwalthert merged commit 91cd42c into r-lib:master Oct 8, 2017
@lorenzwalthert
lorenzwalthert deleted the unindent_regex_comments branch October 8, 2017 13:08
krlmlr added a commit that referenced this pull request Oct 23, 2017
- Hotfix: utf8 should not be verbose (#245).
- Allow styling of Rmd files(#233).
- Remove duplicate @family (#244).
- Fixing token insertion (#242).
- Capitalize Addin titles (#241).
- Explicit `NULL` creation to make styler compatible with R3.2.0 (#237).
- Improve vignettes (#232).
- Allow exclusion of files with `style_pkg()` and `style_dir()`.
- Correct styling with long strings (#230).
- Add tools for re-indenting tokens (#217).
- Math token spacing (#221).
- Remove outdated line and col information (#218).
- Empty input for styling does not cause an error (#227, #228).
- Tools to insert tokens + application on `if`-`else` clauses (#212).
- Improve example in documentation (#222).
- Fix spacing around in (#214).
- Maintenance: renaming functions / files, extend helper, documentation, if_else etc. (#204).
- Disallow line break after ( for function calls (#210).
- Preserve space between `!` and bang (#209).
- Simplify RStudio Addin (#208, #211).
- Indention based on square brackets (#207).
- Add vignette on introducing styler (#203).
- Indent function declaration without curly braces correctly (#202).
- Fix indention in if-else statement (#200).
- Sorting key (#196).
- Use safe sequences (#197).
- Fix space between two commas (#195).
- Keep single-line pipes on one line (#74).
- Remove tidyr and dplyr dependency (#182, #183, @jimhester).
- Fix parsing inconsistency (#188).
- Substitute create filler (#190).
- Introducing class vertical (#189).
- Adapt line break rules (#172).
- Fix `R CMD check` (#185).
- Force argument evaluation for proper error handling (#179).
- Add nonstrict version of set_space_before_comment (#174).
- Add installation instructions to README (#175).
- Addin to style highlighted region (#143).
- Improve spelling (#168).
- Add coverage badge
- Change badge from WIP to active
- Add the number of files to message (#166).
- Improve documentation (#164).
- Add informative messages while styling files (#165).
- More examples in help file (#161).
- No line breaks after pipe if comment is next token (#160).
- Fixing spacing around `!` (non-bang-bang) (#157).
- Finalize function documentation (#154).
- Review vignette (#158).
- Update bang-bang rule (#156).
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.

2 participants