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

Find complete expression #3

Open
hadley opened this issue Feb 5, 2016 · 1 comment
Open

Find complete expression #3

hadley opened this issue Feb 5, 2016 · 1 comment

Comments

@hadley
Copy link

hadley commented Feb 5, 2016

Assuming that the cursor is •, it would be handy to take:

ggplot() + 
  geom_point() + 
  geom_line(•)

# OR
mtcars %>%
  filter(•) %>%
  subset() %>%

And have a keyboard shortcut that ran the complete expression. I'm not entirely sure how you'd implement this (or if it's even possible in general), but it would be super helpful if you could find the full expression given the current cursor.

@kevinushey
Copy link
Owner

Thinking out loud, the API for this could look something like:

tokens <- tokenize_string("<code>")
cursor <- token_cursor(tokens, row, column) ## place cursor on token at [row, col]
result <- whole_expression(cursor)

The token_cursor would be a simple stateful 'pointer' to tokens, which you could move forwards, backwards, or to matching parentheses, and so on.

result would probably be something like the document_selection used in the rstudioapi package.

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

No branches or pull requests

2 participants