Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow selecting the style used by RStudio addins. #463

Merged
merged 11 commits into from Feb 16, 2019

eliminate match_fun (called once, oneliner) and set_addins_style (cal…

…led once, oneliner).
  • Loading branch information...
lorenzwalthert committed Feb 5, 2019
commit 7bc04b7cda543a35560e2c78be74043ad264c50f
@@ -97,10 +97,6 @@ get_rstudio_context <- function() {
rstudioapi::getActiveDocumentContext()
}

match_fun <- function(x) {
eval(parse(text = x))
}

# Binding for style-setting addin.
prompt_style <- function() {
current_style <- get_addins_style()
@@ -111,31 +107,20 @@ prompt_style <- function() {
current_style
)
if (!is.null(new_style)) {
set_addins_style(new_style)
options(styler.addins.style = style_name)
}
invisible(current_style)
}

# Set/get style used by the addins.
set_addins_style <- function(style_name) {
# match_fun ensures the provided name is a valid function
options(
styler.addins.style = style_name
)
}

get_addins_style <- function() {
# `default` could be an environment variable
getOption(
"styler.addins.style",
default = "styler::tidyverse_style"
)
}

get_addins_style_fun <- function() {
match_fun(
get_addins_style()
)
eval(parse(text = get_addins_style()))
}

# How the addins communicate the style being used.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.