You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For breaking code into sections (either manually or with a tool such as strcode), it is desirable that these are not indented. This is not currently supported since all tokens (including comments) will be indented as the current level requires. One way to deal with that would be to set indention of these token to -Inf and using max(0, indention) in serialize_parse_data_nested() although this to be not particularly elegant.
Mainly for code separators, I want the comments to start on the very first
column of a line because if I indent them, it creates visual distortion.
I think it's more natural to not indent code separators.
Have a look here:
#' Insert a code break of arbitrary level#'#'A helper function to insert a code break for a given level#' @param level The level, a numeric value bounded between 1 and 3#' @param insert_with_shiny A boolean value indicating whether to use#' a shiny gadget to add separator and possibly title. If set to \code{FALSE},#' simply a separator will be inserted and the user has to set the title#' himself. To permanently set#' this argument, you can alter the global option strcode$insert_with_shiny,#' which is the location where \code{insert_break} looks up the value when#' used as an RStudio Add-in.#' @keywords internalinsert_break<-function(level,
insert_with_shiny= options()$strcode$insert_with_shiny){
### .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .### elicit title of section (and possible reset level)if (insert_with_shiny) {
ret_value<- find_title(level)
if (ret_value$cancel) return("")
title<-ret_value$text1anchor_in_sep<-ret_value$anchor_in_sep# set options so anchor_in_sep is rememberedop<- options()$strcodeop$anchor_in_sep<-anchor_in_sep
options(strcode=op)
level<- as.numeric(unlist(strsplit(ret_value$level, ""))[nchar(ret_value$level)])
} else {
title<-""anchor_in_sep<-FALSE
}
### .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .### set parameter depending on levelstart<- paste0(rep("#", level), collapse="")
break_char= give_breakchar(level)
sep= paste(rep("", 4-level), collapse="")
# ____________________________________________________________________________### .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .### create break sequence to insertseq_break<- help_create_break(start=start,
break_char=break_char,
sep=sep, anchor_in_sep=anchor_in_sep)
help_insert(seq_break,
start_row=1,
start_indention=Inf,
start_indention_margin=0,
end_row=2,
end_indention=Inf)
### .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .### create title sequence to insertif (insert_with_shiny) {
seq_title<- help_create_title(start=start,
fill=title,
sep=sep,
end="####")
if (!is.null(seq_title)) {
help_insert(seq_title,
start_row=0,
start_indention=Inf,
start_indention_margin=0,
end_row=1,
end_indention=Inf)
}
}
}
Activity
krlmlr commentedon Jul 25, 2017
Can you give an example where it is relevant not to indent? In DBItest I do indent the roxygen2 comments inside functions.
lorenzwalthert commentedon Jul 25, 2017
Mainly for code separators, I want the comments to start on the very first
column of a line because if I indent them, it creates visual distortion.
I think it's more natural to not indent code separators.
Have a look here:
What do you think?
krlmlr commentedon Jul 25, 2017
I think we could specify different indention rules based on regexes that apply to the comment strings.
lorenzwalthert commentedon Sep 10, 2017
WIP @ branch
unindent_regex_commentsandpr106_3_regex.