[TxMt] Re: Smart Home Key

Neil neil at voidfx.net
Fri Dec 5 22:18:09 UTC 2008


I second both.

-N.

On 5 Dec 2008, at 17:11, Louis D Walch wrote:

> On the same subject, I would like my END key to go to the end of the
> line instead of scroll the document. Can this be achieved?
>
> The 'Smart Home' concept Simon describes is also interesting to me. I
> bet this would be handy.
>
> Simon Strandgaard wrote:
>> Is there a way to bind the Home key in a way so that it
>> behaves similar to UltraEdit?
>>
>>
>> Nearly 2 years has past, since I last asked about this:
>> http://thread.gmane.org/gmane.editors.textmate.general/16116
>>
>> Maybe there is a solution now?
>>
>>
>>
>> The first time you press Home then the cursor jumps to
>> the first letter on the line (/^\s*/).
>>
>> The second time you press Home it jumps to
>> the beginning of the line (/^/).
>>
>>
>> position A = ^
>> position B = ^\s*
>>
>> Item1. pressing home and cursor jumps to position B.
>> Item2. except when cursor already is at position B, then it jumps  
>> to A.
>> Item3. doesn't modify the file.
>> Item4. when shift is held down then it preserves the selection  
>> correct.
>>
>>
>> I have tried different approaches mentioned in the past on
>> this list, but they have problems with Item3 and Item4.
>> I have also tried making my own ruby scripts for it, but
>> there was also problems with Item3 and Item4.
>>
>>
>> Has anyone a well behaved Smart Home command?
>>
>>
>>
>>
>>
>>
>> ####################################################
>> # Good: Item1 and Item2
>> # Bad: Item3 and Item4
>> #
>> # Save: Nothing
>> # Input: Selected Text or Line
>> # Output: Insert as Snippet
>> # Activation: Key Equivalent, HomeKeyArrow
>> # Scope Selector: <blank>
>> ####################################################
>> #! /usr/bin/ruby
>> line   = ENV['TM_CURRENT_LINE']
>> index  = ENV['TM_LINE_INDEX'].to_i
>>
>> # extract leading whitespace
>> remain = line.sub(/(^[ \t]*)/, '')
>>
>> whitespace = $1
>>
>> if whitespace == nil
>>  whitespace = ''
>> elsif index == whitespace.size
>>  whitespace = ''
>> else
>>  line = remain
>> end
>>
>> # escape $ \ `
>> line.gsub!(/([\$\\`])/){"\\#$1"}
>>
>> # place cursor
>> print "#{whitespace}${1}#{line}"
>> ####################################################
>>
>>
>>
>
> _______________________________________________
> textmate mailing list
> textmate at lists.macromates.com
> http://lists.macromates.com/listinfo/textmate
>




More information about the textmate mailing list