[TxMt] Re: Transpose chars and transpose words

Juan juanfc at lcc.uma.es
Mon Feb 12 02:44:41 UTC 2007


El 12/02/2007, a las 1:18, Jacob Rus escribió:

> Juan <juanfc at ...> writes:
>
>> I have been using different approaches to Transpose chars and
>> transpose words in AlphaX for a long time.
>>
>> The usual way is really annoying, it swaps the chars around the
>> cursor.  In the Cocoa (emacs-like) version it is also not symmetric:
>> if you do it two times the result is not the original (!)
>>
>> Usually you notice you made a mistake after you have written the
>> chars.  It is annoying to need to position yourself between the last
>> two chars to swap them.
>>
>> The approach I use (and many Alpha users) is
>> transpose the last really chars, though spaces or parenthesis, etc
>> could be in between the cursor and the last two chars!
>
> You should just make a macro for this (it's trivial!), or even a  
> binding that
> will work in all cocoa apps, if you want.  A command is overkill.
>


	did you receive the commands (only for TM) I sent:

---------------------------- transpose chars ^T (v)SelecText|line (^) 
ReplaceSel
#!/usr/bin/env ruby

sel = ENV['TM_SELECTED_TEXT']
if sel != nil
   sel = sel.dup
   sel.gsub!(/^(\w)(.*)(\w)$/u, '\3\2\1')
   print sel
   exit 0
end

left  = ENV['TM_CURRENT_LINE'][0, ENV['TM_LINE_INDEX'].to_i]
right = ENV['TM_CURRENT_LINE'][ENV['TM_LINE_INDEX'].to_i .. -1]

left.gsub!(/(\w)(\W*)(\w)(\W*)$/u, '\3\2\1\4')

print left + right
----------------------



---------------------------- transpose chars ^-Opt-T (v)SelecText| 
line (^)ReplaceSel
#!/usr/bin/env ruby

sel = ENV['TM_SELECTED_TEXT']
if sel != nil
   sel = sel.dup
   sel.gsub!(/^(\w+)(.+?)(\w+)$/u, '\3\2\1\4')
   print sel
   exit 0
end

left  = ENV['TM_CURRENT_LINE'][0, ENV['TM_LINE_INDEX'].to_i]
right = ENV['TM_CURRENT_LINE'][ENV['TM_LINE_INDEX'].to_i .. -1]

left.gsub!(/(\w+)(\W+)(\w+)(\W*)$/u, '\3\2\1\4')

print left + right
--------------------------------






More information about the textmate mailing list