[TxMt] Working with/Deleting empty space in documents ?? Please help !

Allan Odgaard allan at macromates.com
Tue Nov 23 15:03:22 UTC 2004


On Nov 23, 2004, at 14:40, Mats Persson wrote:

>> Record a macro where you do cmd-f, set the find (regex) string to: 
>> “\A[ \t\n]+” and press return (to find it), press delete and stop 
>> recording. [...]
> THANK YOU !!  : )   You've saved me a lot of grief there and what will 
> amount to quite a bit of time!.  That little Macro is so good, that it 
> should (almost ?) be a standard Macro, or something like that.

Probably I should add some default macros to strip white spaces and 
what some people refer to as gremlins (although I still haven't figured 
out exactly what characters are considered gremlins).

Regarding your macro, in case you want to make it a bit more generic, 
e.g. to bind it to alt-delete (and override the default word delete), 
you can also do “conditions” in regular expressions, for example if 
instead you use this pattern:
    \A([ \t\n])?(?(1)[ \t\n]*:[^ \t\n]*)

It will match 1-n white spaces, but if there are no white spaces, it 
will instead match 1-n non-white spaces (greedy).

To break it down:
     (foo)?

Will match 'foo' in capture register 1 if possible (the parenthesis 
makes it a capture, the question mark afterwards makes it a 0-1 repeat, 
i.e. optional match).

Then this (later in the same expression):
    (?(1)lhs:rhs)

Will match 'lhs' iff there is something in capture register 1 (i.e. 
that we matched 'foo'), otherwise it will match 'rhs'.


  iff = if and only if
  lhs = left hand side
  rhs = right hand side




More information about the textmate mailing list