Repository navigation
Add tools for re-indenting tokens - #217
Conversation
94ffb9d to
cca0b13
Compare
a28d5cb to
02e5aa4
Compare
| indent_by = 2, | ||
| start_comments_with_one_space = FALSE) { | ||
| start_comments_with_one_space = FALSE, | ||
| reindention = specify_reindention()) { |
There was a problem hiding this comment.
default_reindention()? What is the rationale behind the specify_ prefix?
There was a problem hiding this comment.
We can use a forwarder here too to be consistent with #221.
There was a problem hiding this comment.
Same line of argument as in https://github.com/krlmlr/styler/pull/221#discussion_r142003169. I suggest to revert to specify_reindention().
| #' @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(), |
There was a problem hiding this comment.
Should this default to regex_none(), at least for the tidyverse style?
| #' Character vector with the patterns of code separator and title for the three | ||
| #' levels of granularity. | ||
| #' @export | ||
| regex_strcode <- function() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
aaf86f9 to
8721211
Compare
8721211 to
6141e09
Compare
- 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).
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.Rto see the how the indention level for the tokenbbxwas set to 5. This function call that lead to this result can be found intests/testthat/unindention_regex/random_non_comment_indention-out.R