Skip to content

Commit 0cf43fc

Browse files
don't insert space after # / #' if only spaces follow
1 parent c60bf90 commit 0cf43fc

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

R/nested.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,20 @@ add_terminal_token_before <- function(pd_flat) {
101101
#'
102102
#' @param spaces_after_prefix An integer vector with the number of spaces
103103
#' after the prefix.
104+
#' @param text_lenght Integer vector giving the number of characters of
105+
#' the text.
104106
#' @param force_one Whether spaces_after_prefix should be set to one in all
105107
#' cases.
106108
#' @return An integer vector of length spaces_after_prefix, which is either
107109
#' one (if `force_one = TRUE`) or `space_after_prefix` with all values
108110
#' below one set to one.
109-
set_spaces <- function(spaces_after_prefix, force_one) {
111+
set_spaces <- function(spaces_after_prefix, text_length, force_one) {
110112
if (force_one) {
111113
n_of_spaces <- rep(1, length(spaces_after_prefix))
112114
} else {
113115
n_of_spaces <- pmax(spaces_after_prefix, 1L)
114116
}
115-
n_of_spaces
117+
ifelse(text_length > 0, n_of_spaces, 0)
116118
}
117119

118120
#' Nest a flat parse table

R/rules-spacing.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ set_space_between_levels <- function(pd_flat) {
136136
#' Start comments with a space
137137
#'
138138
#' Forces comments to start with a space, that is, after the regular expression
139-
#' "^#+'*", at least one space must follow. Multiple spaces may be legit for
140-
#' indention in some situations.
141-
#'
139+
#' "^#+'*", at least one space must follow if the comment is *non-empty*, i.e
140+
#' there is not just spaces within the comment. Multiple spaces may be legit
141+
#' for indention in some situations.
142142
#' @param pd A parse table.
143143
#' @param force_one Wheter or not to force one space or allow multiple spaces
144144
#' after the regex "^#+'*".
@@ -156,7 +156,8 @@ start_comments_with_space <- function(pd, force_one = FALSE) {
156156
regex = "^(#+'*)( *)(.*)$")
157157
comments$space_after_prefix <- nchar(comments$space_after_prefix)
158158
comments$space_after_prefix <- set_spaces(
159-
comments$space_after_prefix,
159+
spaces_after_prefix = comments$space_after_prefix,
160+
text_length = nchar(trimws(comments$text, "right")),
160161
force_one
161162
)
162163

man/set_spaces.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/start_comments_with_space.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)