Skip to content
Prev 11677 / 15075 Next

UI suggestion: allow a tab with no more suggestions to fill in "$"

That seems like a very strong assumption and my point questioning that assumption. For a lot of objects $ makes no sense which is why I'm reluctant to add $ unconditionally. Really, it only makes sense for lists (and some subclasses) - anything else gets a bit dodgy (it works for some but not others).

That said, I suppose one possible approach would be to catch any completion that yields just the items itself and if that happens attempt a completion with $ appended and see what it yields. If it yields anything additional, return that result instead. You can test whether you like that by using something like the following:


add.fn("rcompgen.completion", function (x)
{
    comp <- function(x) {
         utils:::.assignLinebuffer(x)
         utils:::.assignEnd(nchar(x))
         utils:::.guessTokenFromLine()
         utils:::.completeToken()
         utils:::.CompletionEnv[["comps"]]
    }
    res <- unique(comp(x))
    if (nzchar(x) && identical(res, x) && !identical(substr(x, nchar(x), nchar(x) + 1L), "$")) {
       rc <- comp(paste0(x, "$"))
       if (!identical(substr(rc, nchar(rc), nchar(rc) + 1L), "$")) res <- rc
    }
    res
})

Obviously, you can eve spin that further and carry on with @ if $ doesn't work.

Cheers,
Simon