tags:

views:

221

answers:

3

I often need to enter text (consisting of repeated characters) like this:

------------------------------------
 TODO
------------------------------------

In emacs, I can do a

C-u 60 -

that's a Ctrl+U followed by a "60" followed by a "-", which makes entering a repeated sequence of characters easy.

Is there any way to do something like this in TextMate?

A: 

I think you'll have to use a bundle command for that. You can easily write your own, or there might already be a bundle that does this.

Can Berk Güder
+2  A: 

For the specific example you've given, you can type Ctrl-Shift-B, "TODO" to create a text banner.

Ryan Bright
+2  A: 

In TextMate, open the Bundle Editor and select the language you'd like to do this in. (If you'd like to have this functionality in all languages, use the Source bundle) Click the plus symbol at the bottom left, and choose "New Command." Chose "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])

You can then choose a keyboard shortcut to activate this with in the Activation field. The way it works is very similar to that emacs command: type the number of characters you want followed by the character. Then select both of them (this step is unnecessary if they're the only text on the line) and press the shortcut key. My script allows you to specify multiple characters to print, delimited by spaces. So if you typed

10 - =

and hit the shortcut key, you'd get

-=-=-=-=-=-=-=-=-=-=

Edit: After thinking about it...here's another version. This one will print the string after the number. So for example

6 -= (space)

prints

-= -= -= -= -= -=

Here's that 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