Michael Chirico
2023-Mar-01 09:36 UTC
[Rd] tab-complete for non-syntactic names could attempt backtick-wrapping
Consider: x <- list(`a b` = 1) x$a<tab> (i.e., press the 'tab' key after typing 'x$a') The auto-complete mechanism will fill the buffer like so: x$a b This is not particularly helpful because this is now a syntax error. It seems to me there's a simple fix -- in utils:::specialCompletions(), we can wrap the result of utils:::specialOpCompletionsHelper() with backticks for non-syntactic names ([1]): comps <- specialOpCompletionsHelper(op, suffix, prefix) if (length(comps) == 0L) comps <- "" +non_syntactic <- make.names(comps) != comps +comps[non_syntactic] <- paste0("`", comps[non_syntactic], "`") sprintf("%s%s%s", prefix, op, comps) I'm somewhat surprised this hasn't come up before (I searched for 'completeToken', 'specialCompletions', and 'specialOpCompletionsHelper' here and on Bugzilla), so I'm checking with the list first if I'm missing anything before filing a patch. Mike C [1] https://github.com/r-devel/r-svn/blob/4657f65a377cb5ef318c6548bc264e3b0f9517a0/src/library/utils/R/completion.R#L536-L538
Ivan Krylov
2023-Mar-01 09:56 UTC
[Rd] tab-complete for non-syntactic names could attempt backtick-wrapping
? Wed, 1 Mar 2023 01:36:02 -0800 Michael Chirico via R-devel <r-devel at r-project.org> ?????:> +comps[non_syntactic] <- paste0("`", comps[non_syntactic], "`")There are a few more corner cases. For example, comps could contain backticks (which should be escaped with backslashes) and backslashes (which should also be escaped). Thankfully, \uXXXX-style Unicode escape sequences are not currently supported inside backticks, and "escape the backslash" rule already takes care of them. The deparse() function already knows these rules: name <- 'hello world ` \\uFF' cat(deparse1(as.name(name), backtick=TRUE), '\n') # `hello world \` \\uFF` `hello world \` \\uFF` <- 'hello' `hello world \` \\uFF` # [1] "hello" -- Best regards, Ivan