[TxMt] R request: tab moves through list when cursor in collection

Hans-Jörg Bibiko bibiko at eva.mpg.de
Mon Apr 23 18:37:27 UTC 2007


On 23.04.2007, at 16:33, Timothy Bates wrote:

> I often want to edit collections (R lists), and it would be nice if  
> tabbing
> inside a collection had the action of moving the selection to the  
> next item
> in the list.
> Would it be possible to write a command (to hard for a snippet, I  
> think)
> which takes over the tab key when there is no snippet bound to it, and
> detects if the user is in a c(x,y,..) structure, and selects the  
> next item
> in the list?
>
> So if the cursor is in item 1 like this
>
>> a = c(1|11,222)
>
> Then hitting tab would move to highlight all of item 2. Preferably  
> hitting
> shift-tab would move to the next previous item, or in front of the
> collection if already at the head.

To do so as you described is a bit complex but doable. A very naïve  
approach would be to use the attached two things:

EditVector.tmMacro (key bound to SHIFT+CTRL+V in scope source.r)
- which calls TM's Find function to select a given vector c(.*?) in  
the current line
- and calls EditVector.tmCommand

EditVector.tmCommand:
- which splits the selection (delimiter := ',') into snippet items
- and replaces the selection with a snippet for all items within the  
vector

Now you can use the TAB-key to go to the next items.
Unfortunately there's no SHIFT+TAB for going one item back.

As I mentioned it's a naïve solution but it works.


Cheers,

Hans




More information about the textmate mailing list