[TxMt] Re: Need help editing a bundle
Steve King
sking at arbor.net
Tue Aug 16 19:24:39 UTC 2011
Ah. You can do it almost all of it with a single regular expression
search-and-replace. This gets you everything except cleanup on the
leading digit. I assume the leading number can go above 9; that makes
the regex a little harder if you want to do cleanup. If that's not the
case, add a 0 to the beginning of the replace string and it'll do
everything you want.
Find: ^(\d+)'(\d\d)\.(\d+)\d\s+(Start|End)$
Replace: $1:$2:$3
Just record a new macro, do "Replace All" with the above parameters, and
save. The search and replace strings will get saved in the macro.
Of course, search and replace isn't the right tool for the job. :-)
Here's a little Python script that you can save as a bundle command. Set
the input to "Selected Text or Document" and the output to "Replace
Selected Text". This script has the benefit of rounding values
(0'12.9999 becomes 00:13:000) and dealing with pathological cases
(0'99.1234 becomes 01:39.123).
#! /usr/bin/env python
import re
import sys
regex = re.compile(r"^(\d+)'(.*?)\s+(Start|End)$")
for line in sys.stdin:
mo = regex.match(line.strip())
if mo:
ms = round((int(mo.group(1))*60.0 + float(mo.group(2))) * 1000.0)
mm = int(ms/60.0/1000.0)
ms -= mm*60.0*1000.0
ss = int(ms/1000.0)
ms -= ss*1000.0
print '%02d:%02d:%03d'%(mm,ss,ms)
--
Steve King
Sr. Software Engineer
Arbor Networks
+1 734 821 1461
www.arbornetworks.com <http://www.arbornetworks.com/>
More information about the textmate
mailing list