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

simplify complicated matching + remove package styler

  • Loading branch information...
lorenzwalthert committed Feb 5, 2019
commit 3d57c3eb03bba0d5a25901215fb863d83193ef55
@@ -97,35 +97,8 @@ get_rstudio_context <- function() {
rstudioapi::getActiveDocumentContext()
}


# Dedicated binding for package styling addin. Simple wrapper calling style_pkg
# with the selected addins style.
style_package <- function() {
communicate_addins_style()
style_pkg(style = get_addins_style_fun())
}


# `match.fun`-like utility covering "ns::name".
exported_value_rx <- "^([^:]+)::([^:]+)$"
is_exported_value <- function(x) {
rlang::is_scalar_character(x) && grepl(exported_value_rx, x)
}
extract_exported_ns <- function(x) {
sub(exported_value_rx, "\\1", x)
}
extract_exported_name <- function(x) {
sub(exported_value_rx, "\\2", x)
}
match_fun <- function(x) {
if (is_exported_value(x)) {
x <-
getExportedValue(
extract_exported_ns(x),
extract_exported_name(x)
)
}
match.fun(x)
eval(parse(text = x))
}

# Binding for style-setting addin.
@@ -3,11 +3,6 @@ Description: Prompt for and set the style used by all STYLER addins
Binding: prompt_style
Interactive: true

Name: Style package
Description: Pretty-print package source code
Binding: style_package
Interactive: true

Name: Style active file
Description: Pretty-print active file
Binding: style_active_file
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.