[TxMt] Re: smart home

Steve King steve at narbat.com
Mon Apr 9 15:50:09 UTC 2007


On Sat, 7 Apr 2007, Simon Strandgaard wrote:

> Still, any ideas how to jump between beginning of line and beginning of 
> text ?  (aka. smart-home in the pc world)

Here's a command that will do the trick.  If the cursor is at the 
beginning of the line it gets moved to the first non-whitespace character. 
Otherwise it gets moved to the beginning of the line.

Input:  Selected Text or Line
Output: Insert as Snippet

----- Cut Here -----
#! /usr/bin/perl

$line       = $ENV{'TM_CURRENT_LINE'};
$column     = $ENV{'TM_COLUMN_NUMBER'};
$whitespace = '';

if ($column == 1) {
     # Chop leading whitespace from the line and
     # place it into its own variable.
     $line =~ s/^([ \t]*)//;
     $whitespace = $1;
}

# Escape anything in the line that might be mistaken
# as a snippet token.
$line =~ s/([\$\\`])/\\\1/g;

# Print the line as a snippet. The cursor will be
# placed at the ${1} token.
printf '%s${1}%s', $whitespace, $line;

----- Cut Here -----

-- 
Steve King, <steve at narbat.com>



More information about the textmate mailing list