I never would have thought of this feature if not for this thread, but
I really like it. Thanks to the original poster, and to everyone who
contributed to this script, which I've now got bound to Command-Left.




On Sat, Jul 31, 2010 at 6:47 PM, Kendall Conrad <angelw...@gmail.com> wrote:
> With more testing I found there were some cases where the script
> didn't work so I have made further improvements. Below is the new
> script. I set command+left to be the shortcut for it, which works out
> pretty well.
>
> ---------------------------------
> tell application "BBEdit"
>        -- Find the character offset for the cursor position
>        set aaa to (characterOffset of line (startLine of selection)) of
> front window
>        set zzz to (characterOffset of selection)
>        set _cursor to zzz - aaa
>        set _smart to 0
>
>        -- Get the column number of the first non-whitespace character
>        set _line to contents of line (startLine of selection) of front
> window
>        -- Ensure line is not empty
>        if (count _line) = 0 then return
>
>        -- Go through content of line looking for smart home position
>        set _len to count (_line as text)
>        repeat with _i from 1 to _len
>                if item _i of _line is not in {space, tab} then
>                        set _smart to _i - 1
>                        exit repeat
>                end if
>        end repeat
>
>        -- Check if we never found non-whitespace
>        if item _i of _line is in {space, tab} then set _smart to _len
>
>        -- Only true if there was no starting whitespace
>        if _smart = 0 then
>                set _smart to 1
>                set _cursor to 1
>        end if
>
>        -- Check if not at smart position already
>        if _cursor is not equal to (_smart) then -- Go to smart home
>                select insertion point after (character (_smart) of line 
> (startLine
> of selection) of front window)
>        else -- Just go to start of line
>                select insertion point before (character (1) of line 
> (startLine of
> selection) of front window)
>        end if
> end tell
> ---------------------------------
>
> -Kendall
>
> On Jul 31, 8:32 am, Kendall Conrad <angelw...@gmail.com> wrote:
>> I reworked your code some and got it to work properly as far as my
>> testing found.
>>
>
> --
> You received this message because you are subscribed to the
> "BBEdit Talk" discussion group on Google Groups.
> To post to this group, send email to bbedit@googlegroups.com
> To unsubscribe from this group, send email to
> bbedit+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/bbedit?hl=en
> If you have a feature request or would like to report a problem,
> please email "supp...@barebones.com" rather than posting to the group.

-- 
You received this message because you are subscribed to the 
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email "supp...@barebones.com" rather than posting to the group.

Reply via email to