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

autocomplete #57

Closed
cscheid opened this issue Aug 11, 2013 · 6 comments
Closed

autocomplete #57

cscheid opened this issue Aug 11, 2013 · 6 comments
Milestone

Comments

@cscheid
Copy link

cscheid commented Aug 11, 2013

ACE has autocomplete support, and so does R. We should look into doing this. Making it low-latency will be.. interesting.

@smschauhan
Copy link
Contributor

I was looking for autocomplete support for ace earlier but ended up with this issue, which was closed 4 months ago. Then I see this long running thread. I also did find this commit, which just confuses me.

Something tells me that they don't have a great support for autocomplete?

@cscheid
Copy link
Author

cscheid commented Sep 4, 2013

There's this, which has been merged: ajaxorg/ace#1189

@gordonwoodhull
Copy link
Contributor

Yayayay! How do we get the words to complete with?

@cscheid
Copy link
Author

cscheid commented Sep 6, 2013

There's several steps to this.

First, we need a function that takes the current cursor position and isolates the "relevant R statement". There might be R code that does this (@s-u, help here?). Here are some relevant use cases, where I'm using <> to denote the position of the cursor.

First, trivial cases:

x <- rno<>

This should return rnorm, etc. Then, almost-as-trivial:

x <- 5; y <- rno<>

Then, a little more annoying, since it mixes markdown:

# Some title

A paragraph

```{r}
x <- rno<>

This takes some annoying parsing code duplication with knitr, but I see no way around it.

@cscheid
Copy link
Author

cscheid commented Sep 6, 2013

Assuming we can isolate the latest incomplete R statement, the next step is to crib the rcompgen.completion function from the R graphical client:

> rcompgen.completion
function (x) 
{
    utils:::.assignLinebuffer(x)
    utils:::.assignEnd(nchar(x))
    utils:::.guessTokenFromLine()
    utils:::.completeToken()
    utils:::.CompletionEnv[["comps"]]
}

With that,

> rcompgen.completion("rno")
[1] "rnorm"

> rcompgen.completion("x <- rnorm(")
[1] "n="    "mean=" "sd="  

> rcompgen.completion("y <- 5; x <- rnorm(")
[1] "n="    "mean=" "sd="  

It's smart enough to pluck the last statement by itself, so it might just be a matter of isolating the last R block.

@ghost ghost assigned gordonwoodhull Sep 15, 2013
@gordonwoodhull
Copy link
Contributor

Pushing basic support for this. Required a few changes to mode-r.js and ext-language_tools.js which I'm not completely sure about and which will need to be reapplied or rethought the next time we upgrade ace.

(See the commit messages.)

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

No branches or pull requests

3 participants