Michael Chirico
2023-Mar-01 16:48 UTC
[Rd] tab-complete for non-syntactic names could attempt backtick-wrapping
Great suggestion! I've started a patch: https://bugs.r-project.org/show_bug.cgi?id=18479 On Wed, Mar 1, 2023 at 1:56 AM Ivan Krylov <krylov.r00t at gmail.com> wrote:> > ? 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
Ivan Krylov
2023-Mar-02 08:39 UTC
[Rd] tab-complete for non-syntactic names could attempt backtick-wrapping
There turn out to be a few more things to fix. One problem is easy to solve: vapply() needs a third argument specifying the type of the return value. (Can we have unit tests for tab completion?) The other problem is harder: `comps` defaults to an empty string, and you can't have a symbol consisting of an empty string, because this value is internally reserved for missing function arguments. I think you can return(paste0(prefix, op)) if length(comps) == 0L, but this is still somewhat worrying. R tries to prevent empty names, so I wouldn't expect specialOpCompletionsHelper() to return an empty string, but I can't prove it right now. On the other hand, x$'a string' is the same as x$`a string`. Could we just drop as.name() and keep the return value being a string literal? I'm not sure about this, either. -- Best regards, Ivan
Apparently Analagous Threads
- tab-complete for non-syntactic names could attempt backtick-wrapping
- tab-complete for non-syntactic names could attempt backtick-wrapping
- tools::parseLatex() crashes on "\\verb{}"
- tools::parseLatex() crashes on "\\verb{}"
- Open a file which name contains a tilde