Ah, Delacour's and Conrad's solution seems to be pretty much spot on. I've been wrestling with it a bit and still can't get the bugger to behave the same when the SHIFT key is held down -- that is, using the same "Smart Home" behaviour while trying to SELECT to the start of the line. It ought to first select to the intelligent beginning of the line, and then another press ought to extend it to include any whitespace, and then susequent presses would flip-flop between the two as this script is doing now (wonderfully).
And Mr. Roth, I'm glad you've found it helpful! Thanks again to everyone who's contributed; wouldn't be working if it weren't for them. Clearly I'm incapable. Haha. And hopefully more people discover this discussion and find it useful, too. I was shocked to have found it missing from BBEdit, as it seems to do most everything else, and then some! On Jul 31, 10:10 pm, John Delacour <johndelac...@gmail.com> wrote: > At 15:47 -0700 31/7/10, Kendall Conrad 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. > > Applescript is verbose enough without any help at all! Here's a > trimmed down version that takes account of the no-break space. > > tell application "BBEdit" to tell front window > tell the selection to set {_n, _selectionstart} to {startLine, > characterOffset} > tell line _n to set {_linestart, _line} to {characterOffset, contents} > set _cursor to _selectionstart - _linestart > set _smart to 0 > set _linelength to count _line > if _linelength = 0 then return > repeat with _i from 1 to _linelength > 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 _linelength > end if > end repeat > if _smart = 0 then > set _smart to 1 > set _cursor to 1 > end if > if _cursor is not _smart then > select insertion point after character _smart of line _n > else > select insertion point before line _n > end if > end tell > > > > >--------------------------------- > >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 -- 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.