diff --git a/DESCRIPTION b/DESCRIPTION index 9c8a65e..3e888a3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,7 @@ Suggests: rstudioapi, testthat (>= 3.0.0) Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Config/testthat/edition: 3 URL: https://github.com/lionel-/codegrip BugReports: https://github.com/lionel-/codegrip/issues diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..2aef915 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,6 @@ +# codegrip (development version) + +* The long "flat" form for function definitions now aligns arguments using a + single indent rather than a double indent, which follows the + [tidyverse style guide](https://style.tidyverse.org/functions.html#long-lines-1) + (#20). diff --git a/R/reshape-addin.R b/R/reshape-addin.R index 69ba68f..806481a 100644 --- a/R/reshape-addin.R +++ b/R/reshape-addin.R @@ -15,7 +15,7 @@ #' Note that for function definitions, `addin_reshape()` cycles through two #' different long shapes. The traditional L form uses more horizontal space #' whereas the flat form uses less horizontal space and the arguments are -#' always aligned at double indent: +#' always aligned at single indent: #' ``` #' foo <- function(a, b, c) { #' NULL diff --git a/R/reshape-call.R b/R/reshape-call.R index 5245d02..a1da2e5 100644 --- a/R/reshape-call.R +++ b/R/reshape-call.R @@ -68,10 +68,8 @@ node_call_longer <- function(node, ..., L = FALSE, info) { if (prefix) { body <- node_text(node_call_body(node), info = info) suffix <- paste0(" ", body) - indent_factor <- 2 } else { suffix <- "" - indent_factor <- 1 } fn <- node_text(set[[1]], info = info) @@ -82,11 +80,7 @@ node_call_longer <- function(node, ..., L = FALSE, info) { new_indent_n <- xml_col2(left_paren) } else { fn <- paste0(fn, left_paren_text, "\n") - if (prefix) { - new_indent_n <- current_indent_n + base_indent * indent_factor - } else { - new_indent_n <- current_indent_n + base_indent - } + new_indent_n <- current_indent_n + base_indent } if (L) { @@ -125,7 +119,7 @@ node_call_longer <- function(node, ..., L = FALSE, info) { if (L) { arg_indent_n <- new_indent_n - current_indent_n - arg_parent_indent_n } else { - arg_indent_n <- base_indent * indent_factor - arg_parent_indent_n + arg_indent_n <- base_indent - arg_parent_indent_n } if (length(arg)) { diff --git a/README.md b/README.md index a06ad6a..b5b5b71 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ codegrip provides [RStudio addins](http://rstudio.github.io/rstudioaddins/) and -Note that for function definitions, `addin_reshape` cycles through two different long shapes. The traditional L form uses more horizontal space whereas the flat form uses less horizontal space and the arguments are always aligned at double indent: +Note that for function definitions, `addin_reshape` cycles through two different long shapes. The traditional L form uses more horizontal space whereas the flat form uses less horizontal space and the arguments are always aligned at single indent: @@ -61,7 +61,7 @@ Not yet implemented: ## Using in Visual Studio Code -`addin_reshape` is available for keybinding in VS Code. See [here](https://github.com/REditorSupport/vscode-R/wiki/RStudio-addin-support#enabling-rstudio-addin-support) for instructions on enabling general addin support. +`addin_reshape` is available for keybinding in VS Code. See [here](https://github.com/REditorSupport/vscode-R/wiki/RStudio-addin-support#enabling-rstudio-addin-support) for instructions on enabling general addin support. Once addins are enabled, add the following to `keybindings.json`: diff --git a/man/addin_reshape.Rd b/man/addin_reshape.Rd index e6dccca..234a268 100644 --- a/man/addin_reshape.Rd +++ b/man/addin_reshape.Rd @@ -23,7 +23,7 @@ list( Note that for function definitions, \code{addin_reshape()} cycles through two different long shapes. The traditional L form uses more horizontal space whereas the flat form uses less horizontal space and the arguments are -always aligned at double indent: +always aligned at single indent: \if{html}{\out{
}}\preformatted{foo <- function(a, b, c) \{ NULL diff --git a/tests/testthat/_snaps/reshape-call.md b/tests/testthat/_snaps/reshape-call.md index 483c50a..05d42b8 100644 --- a/tests/testthat/_snaps/reshape-call.md +++ b/tests/testthat/_snaps/reshape-call.md @@ -14,7 +14,7 @@ ) function( - a + a ) NULL Code print_longer("(b, c)") @@ -25,8 +25,8 @@ ) function( - b, - c + b, + c ) NULL Code print_longer("(a, b, c)") @@ -38,9 +38,9 @@ ) function( - a, - b, - c + a, + b, + c ) NULL Code print_longer("(a = 1, b, c = 3)") @@ -52,9 +52,9 @@ ) function( - a = 1, - b, - c = 3 + a = 1, + b, + c = 3 ) NULL Code # Leading indentation is preserved. First line is not indented @@ -73,7 +73,7 @@ ) function( - a + a ) NULL Code print_longer(" (a, b)") @@ -84,8 +84,8 @@ ) function( - a, - b + a, + b ) NULL Code # Multiline args are indented as is @@ -100,11 +100,11 @@ ) function( - a, - b = foo( - bar - ), - c + a, + b = foo( + bar + ), + c ) NULL Code print_longer("(a, b =\n 2, c)") @@ -117,10 +117,10 @@ ) function( - a, - b = - 2, - c + a, + b = + 2, + c ) NULL Code print_longer(" (a, b = foo(\n bar \n ), c)") @@ -134,11 +134,11 @@ ) function( - a, - b = foo( - bar - ), - c + a, + b = foo( + bar + ), + c ) NULL Code # Wrong indentation is preserved @@ -153,11 +153,11 @@ ) function( - a, - b = foo( - bar - ), - c + a, + b = foo( + bar + ), + c ) NULL Code print_longer(" (a, b = foo(\n bar\n), c)") @@ -171,11 +171,11 @@ ) function( - a, - b = foo( - bar - ), - c + a, + b = foo( + bar + ), + c ) NULL # can reshape call longer (L shape) diff --git a/tests/testthat/_snaps/reshape.md b/tests/testthat/_snaps/reshape.md index 70edb7b..6e44b2a 100644 --- a/tests/testthat/_snaps/reshape.md +++ b/tests/testthat/_snaps/reshape.md @@ -64,7 +64,7 @@ Output i: 1 function( - a + a ) NULL i: 2 @@ -72,7 +72,7 @@ i: 3 function( - a + a ) NULL Code @@ -86,9 +86,9 @@ i: 2 function( - a, - b = 1, - c + a, + b = 1, + c ) NULL i: 3 @@ -108,7 +108,7 @@ Output i: 1 if ( - a + a ) NULL i: 2 @@ -120,7 +120,7 @@ Output i: 1 if ( - a + a ) b else c i: 2 @@ -132,7 +132,7 @@ Output i: 1 while ( - a + a ) NULL i: 2