Open hadley opened 8 years ago
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.
Assuming that the cursor is •, it would be handy to take:
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.