Lets say I have a list of code like this
foo <- "test" foo <- "test" foo <- "test" foo <- "test" foo <- "test" foo <- "test" foo <- "test" foo <- "test" foo <- "test" foo <- ³test"
Is it possible to automate the insertion of columns of numbers. The output should be this:
foo1 <- "test1" foo2 <- "test2" foo3 <- "test3" foo4 <- "test4" foo5 <- "test5" foo6 <- "test6" foo7 <- "test7" foo8 <- "test8" foo9 <- "test9" foo10 <- ³test10²
Is there perhaps a regex or other automation that could be used? I¹m aware that it is possible to insert line numbers but this will only be useful if the 10 lines of code happen to be on lines 1-10.
Thanks Ross
There’s no regex. You’d have to write a command.
If you made a rectangular selection, a command to fill the right hand side with increments of the first number would be quick to write
I think that there’s an unexploited gap for a bundle handling numeric input and row/column/cell structures, enabling things like fill down, across, sum down etc.
On 8 Oct 2013, at 11:21 AM, Ross Ahmed rossahmed@googlemail.com wrote:
Lets say I have a list of code like this
foo <- "test" foo <- "test" foo <- "test" foo <- "test" foo <- "test" foo <- "test" foo <- "test" foo <- "test" foo <- "test" foo <- “test"
Is it possible to automate the insertion of columns of numbers. The output should be this:
foo1 <- "test1" foo2 <- "test2" foo3 <- "test3" foo4 <- "test4" foo5 <- "test5" foo6 <- "test6" foo7 <- "test7" foo8 <- "test8" foo9 <- "test9" foo10 <- “test10”
Is there perhaps a regex or other automation that could be used? I’m aware that it is possible to insert line numbers but this will only be useful if the 10 lines of code happen to be on lines 1-10.
Thanks Ross
On 08.10.2013, at 12:21, Ross Ahmed rossahmed@googlemail.com wrote:
Is there perhaps a regex or other automation that could be used? I’m aware that it is possible to insert line numbers but this will only be useful if the 10 lines of code happen to be on lines 1-10.
Highlight / select the lines you want to number, choose Text->Filter Trough Command. Use “nl” as command, “Replace Input” as result. Now only your selected lines are numbered, regardless of their position in the file.
From there you can simply use multiple carrets to cut and paste the numbers to the two positions per line you want them to be with a couple of keystrokes.
Thanks that works fairly well thanks.
I think the number of keystrokes could be reduced however, by for example making a column selection then inserting numbers. Or is this asking too much?!
Ross
On 8 Oct 2013, at 11:45, Kai Brust kai.brust@gmail.com wrote:
On 08.10.2013, at 12:21, Ross Ahmed rossahmed@googlemail.com wrote:
Is there perhaps a regex or other automation that could be used? I’m aware that it is possible to insert line numbers but this will only be useful if the 10 lines of code happen to be on lines 1-10.
Highlight / select the lines you want to number, choose Text->Filter Trough Command. Use “nl” as command, “Replace Input” as result. Now only your selected lines are numbered, regardless of their position in the file.
From there you can simply use multiple carrets to cut and paste the numbers to the two positions per line you want them to be with a couple of keystrokes.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On 8 Oct 2013, at 12:53, Ross Ahmed wrote:
I think the number of keystrokes could be reduced however, by for example making a column selection then inserting numbers. Or is this asking too much?!
TextMate 1.x did work fine with column selections filtered through commands, unfortunately this is not yet handled gracefully in 2.0 and your email was a reminder that I need to finish that part.
On the general subject, I’ve been considering introducing something like a counting variable to use in the replacement (format) string, e.g. ${iota[:«start»[:«step»]]} which would insert a number starting with the optional “«start»” value and incrementing by “«step»” each time inserted.
Though this wouldn’t allow inserting the same number twice (as in your example). Another approach would be allow “math expression” so that one could replace with $((i += 1)) which would inesrt the value of $i and then increment it by one. But even this is not overly flexible, yet fairly complex (i.e. no-one would probably use it).
I am leaning toward the counting variable, and will probably add that when I find a good way to implement it and/or refactor the relevant code. Until then, a user could simply insert the literal $iota string (via find/relace) and then have a command post-process the document to insert seqeunce numbers for these.
On 08.10.2013, at 12:53, Ross Ahmed rossahmed@googlemail.com wrote:
Thanks that works fairly well thanks.
I think the number of keystrokes could be reduced however, by for example making a column selection then inserting numbers. Or is this asking too much?!
Allan answered the part about column selection already. Meanwhile, until this stuff is implemented, you could filter your lines through the following command and number them in one go:
nl | awk '{ print $2$1 " " $3 " " substr($4, 0, length($4)-1) $1 """ }’
(Assuming the quoted words in your example are never containing any additional spaces)
On 08.10.2013, at 13:47, Kai Brust kai.brust@gmail.com wrote:
On 08.10.2013, at 12:53, Ross Ahmed rossahmed@googlemail.com wrote:
Thanks that works fairly well thanks.
I think the number of keystrokes could be reduced however, by for example making a column selection then inserting numbers. Or is this asking too much?!
Allan answered the part about column selection already. Meanwhile, until this stuff is implemented, you could filter your lines through the following command and number them in one go:
nl | awk '{ print $2$1 " " $3 " " substr($4, 0, length($4)-1) $1 """ }’
(Assuming the quoted words in your example are never containing any additional spaces)
Sorry, last char should have been a single quote:
nl | awk '{ print $2$1 " " $3 " " substr($4, 0, length($4)-1) $1 """ }'
Ah, everyone's in on the fun: my take follows.
Select the lines and use
Text => Filter through command... (replace input)
perl -pe '$i++;s/(\w+)/$1$i/g'
Not too bad!
Cheers, Paul