Hi there,
Just playing with the R console mode. It's nice, so thanks to the writers!
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.
PS: One thing that keeps me in R, is the useful last command function (like in tcsh, hitting "up" and "down" scrolls through a command history, replacing the current line. Is it possible to scan the doc, make a list of lines, and just give this as a drop down menu when up is hit hit?
On 23 Apr 2007, at 16:33, Timothy Bates wrote:
... PS: One thing that keeps me in R, is the useful last command function (like in tcsh, hitting "up" and "down" scrolls through a command history, replacing the current line. Is it possible to scan the doc, make a list of lines, and just give this as a drop down menu when up is hit hit?
Did you try OPTION+UP and OPTION+DOWN? Or R console: "Show History List"
Hans
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
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.
An other way would be simply to use TM's Find Function. Look for regexp [0-9A-z]+. Use the APPLE+G for jumping forwards, and SHIFT +APPLE+G for jumping backwards (this only works partly; sometimes you have to press SHIFT+APPLE+G several times).
With that regexp you can create your own macros easily.
Cheers,
Hans
Thanks Hans,
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.
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
Running the macro, I get an error
interpreter failed: Exec format error
I imagine it is in the Perl #!/usr/bin/perl -X $i=1; $sel= $ENV{'TM_SELECTED_TEXT'}; $sel=~s/^c {0,}( {0,}//;$sel=~s/ {0,})$//; for(split(/ *, */,$sel)) {push(@out, "${".$i++.":$_}")} print "c(".join(", ",@out).")${".$i."}";
Cheers, tim
Running the macro, I get an error
interpreter failed: Exec format error
I imagine it is in the Perl #!/usr/bin/perl -X $i=1; $sel= $ENV{'TM_SELECTED_TEXT'}; $sel=~s/^c {0,}( {0,}//;$sel=~s/ {0,})$//; for(split(/ *, */,$sel)) {push(@out, "${".$i++.":$_}")} print "c(".join(", ",@out).")${".$i."}";
I suppose, perl is not in /usr/bin. Execute in the Terminal 'which perl' to figure out where perl is. But I would suggest to use the two macros SelectNextWord, SelectPrevWord in my today's mail 'Re: [TxMt] Re: TM Find Dialog Enhancement (?)'. These work better and they're overall functions.
The perl script only has the advantage that it reformats the c() vector.
Hans