R/code-heading.R

Defines functions code_heading

Documented in code_heading

#' Create heading dividers
#'
#' Insert some hyphens padded to a specified console character width.
#'
#' @param width The width of console the hyphens should pad to
#'
#' @return A character string consisting of a ' ' and hyphens that fill to the
#'   specified `width`.
#' @export
code_heading <- function(width = 80) {
  cur_location <- rstudioapi::primary_selection(
    rstudioapi::getSourceEditorContext()
  )

  cur_length <- cur_location$range$start[2]
  if (cur_length < (width - 2)) {
    rstudioapi::insertText(
      glue::glue(" {paste(rep('-', width - cur_length), collapse = '')}")
    )
  }
}
wjakethompson/wjake documentation built on June 29, 2024, 7:47 a.m.