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

Remove {prettycode} dependency in favour of cli::code_highlight() #512

Open
moodymudskipper opened this issue Dec 31, 2024 · 1 comment
Open
Milestone

Comments

@moodymudskipper
Copy link
Collaborator

Will be closed by #488 after Gabor merges r-lib/cli#727 cc @wurli

@moodymudskipper moodymudskipper added this to the 1.2.0 milestone Dec 31, 2024
@moodymudskipper
Copy link
Collaborator Author

A new version of cli was released and the PR was not considered, this looks like it could take forever or even be rejected.

Better to just patch it in constructive itself. I think something like this is safe:

# In code
code_highlight <- NULL

# In .onLoad
code_highlight <- cli::code_highlight
environment(code_highlight) <- rlang::new_environment(
  data = list(getParseData = get_parse_data)
  parent = environment(cli::code_highlight)
)
code_highlight <<- code_highlight

Or a bit less efficient but without polluting .onLoad :

code_highlight_fixed <- function(...) {
  code_highlight <- cli::code_highlight
  environment(code_highlight) <- rlang::new_environment(
    data = list(getParseData = get_parse_data)
    parent = environment(cli::code_highlight)
  )
  code_highlight(...)
}

where get_parse_data() is the function defined in the PR but slightly modified to have the same args as getParseData() so no code using it will break.

We could also do something with rlang::local_bindings() but that's more invasive, we'll need to unlock bindings and I think CRAN doesn't like that.

We need the tests as well, we can copy them but use construct() rather than code_highlight()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant