[TxMt] Smart Home Key

Simon Strandgaard neoneye at gmail.com
Fri Dec 5 19:54:25 UTC 2008


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}"
####################################################


-- 
Simon Strandgaard
my graphics program for mac - http://toolboxapp.com/



More information about the textmate mailing list