[TxMt] Re: regular expression to count words OR inserting shell output in regular expressions

Hans-Jörg Bibiko bibiko at eva.mpg.de
Fri Dec 5 08:30:48 UTC 2008


On 05.12.2008, at 07:07, Abhimanyu Lad wrote:
>               """
>               $TM_FILENAME ${1:args}
>               """
>
>               if len(argv) != <some regex that counts number of  
> words in $1>:
>                   exit(1)
>
>               $0
>
> Depending on the number of words that I enter for args, I want the
> appropriate number to be inserted in front of "if len(argv) != ...".

Ad hoc I have no solution by using a single regexp but a quick&dirty  
solution would be this snippet:

"""
$TM_FILENAME ${1:args}
"""

     if len(argv) != ${2:ruby -e 'p "$1".strip.split(/\S+/).size'}:
         exit(1)
     $0


invoke it, type something for args, press TAB, press CTRL+OPT+R (it  
executes the selection in bash and replaces the selection by the result)

Or write a tmcommand which counts the words in selection and replaces  
the selection with that number.
then:
"""
$TM_FILENAME ${1:args}
"""

     if len(argv) != ${2:$1}:
         exit(1)
     $0

type args, press TAB, invoke that tmcommand


--Hans



More information about the textmate mailing list