I fixed the issue of multiple lines being selected when you use it. I
think some of the math can be simplified, but I wasn't up for it as
everything seemed to work right.

------------
tell application "BBEdit" to tell front window
        -- Grab line number and offset of text cursor
        tell the selection to set {_n, _selectionstart} to {startLine,
characterOffset}
        set _selectLength to length of (contents of selection as text)
        if (_selectLength) > 0 then
                set _selectionstart to _selectionstart + _selectLength
        end if
        -- Grab offset of line in the document and the contents of the line
        tell line _n to set {_linestart, _line} to {characterOffset,
contents}
        set _cursor to _selectionstart - _linestart
        if _cursor = 0 then return
        set _smart to 0
        -- Go through content of line looking for smart home position
        set _len to count _line
        -- Ensure line is not empty
        if _len = 0 then return
        -- Traverse line to find first non-whitespace
        repeat with _i from 1 to _len
                if item _i of _line is not in {space, tab, ASCII character 202} 
then
                        set _smart to _i - 1
                        exit repeat
                else
                        set _smart to _len
                end if
        end repeat
        -- Ensure smart is not past cursor
        if _smart > _cursor then set _smart to _cursor
        -- Check if smart position is where cursor is, if so select from
start of line
        if _smart is _cursor or (_cursor - _selectLength = _smart) then
                select (characters (_selectionstart - _cursor) through
(_selectionstart - 1))
        else -- Select from smart position
                select (characters (_selectionstart - _cursor + _smart) through
(_selectionstart - 1))
        end if
end tell
------------

-Kendall


On Aug 6, 10:54 am, offtone <aaro...@gmail.com> wrote:
> Thank you, Kendall, for that. It's nearly perfect (throws an error if
> more than one line is selected). Both are now bound to CMD+LEFT and CMD
> +SHIFT+LEFT respectively, and working pretty much identically to those
> other IDEs and text editors! I may need to buy a book on Apple Script,
> I think. Haha. The "library" seems totally insufficient for learning
> it on its own. Did you learn it through experimentation, or books,
> or...? I'm a graphic designer and I have a feeling I could do some
> pretty sweet things with Illustrator and Photoshop too, if I could
> just get a grip on the language.
>
> I may fire off an e-mail to Bare Bones with a link to this thread. I'm
> sure they'd be willing to implement this on their own.
>
> Thanks again!
>

-- 
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