In TextMate, open the Bundle Editor and select the language in which you would like to do this. (If you want to have this functionality in all languages, use the source pool) Click the plus symbol in the lower left, and select "New Team." Select Nothing for the Save field and Selected Text or Line for the two input fields. Then paste this into the "Commands" field:
#!/usr/bin/python import sys commandLine = raw_input("") tmArgs = commandLine.split() numberOfArgs = len(tmArgs) for i in range(eval(tmArgs[0])): for j in range(1, numberOfArgs): sys.stdout.write(tmArgs[j])
Then you can select a key combination to activate it in the "Activation" field. The way it works is very similar to the emacs command: enter the number of characters you want followed by a character. Then select both of them (this step is not needed if they are the only text in the line) and press the shortcut key. My script allows me to specify multiple characters for printing, marked with spaces. Therefore, if you typed
10 - =
and press the shortcut key, you will get
-=-=-=-=-=-=-=-=-=-=
Edit : thinking about it ... here is another version. This will print a line after the number. For example,
6 -= (space)
prints
-= -= -= -= -= -=
Here is this version:
#!/usr/bin/python import sys import string commandLine = raw_input("") timesToPrint = eval(commandLine.split()[0]) firstSpace = string.find(commandLine, " ") for i in range(timesToPrint): sys.stdout.write(commandLine[firstSpace + 1:])
Kevin griffin
source share