I reworked your code some and got it to work properly as far as my testing found.
------------------------------------- tell application "BBEdit" activate set _current_line_number to startLine of selection -- 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 _current_point to zzz - aaa -- Get the column number of the first non-whitespace character set _line_contents to contents of line _current_line_number of front window set _chars to characters of _line_contents repeat with _i from 1 to count _chars if item _i of _chars is not in {space, tab} then set _first_non_whitespace_char to _i exit repeat end if end repeat set _smart_point to _first_non_whitespace_char select (character (_smart_point) of line (startLine of selection) of front window) select insertion point before selection of front window tell application "System Events" if _current_point is equal to (_smart_point - 1) then -- Just go to start of line key code 123 using command down end if end tell end tell -------------------------------------- -Kendall On Jul 30, 1:45 pm, offtone <aaro...@gmail.com> wrote: > Why isn't this working? For some reason _current_point and > _smart_point never match... Even when I run it with the cursor before > the first non-whitespace character (at the smart point, basically). > > And how would I go about getting the startColumn of a character in the > line? Is there a shortcut for that, or would I have to iterate each > character and basically count a "tab" as 4 columns (which may even > change depending on user preferences...)? > > What I have so far (Frankensteined from posts above): > > tell application "BBEdit" > activate > > set _current_line_number to startLine of selection > set _current_point to insertion point > > -- Get the column number of the first non-whitespace character > tell the front document > set _line_contents to contents of line _current_line_number > set _chars to characters of _line_contents > repeat with _i from 1 to count _chars > if item _i of _chars is not in {space, tab} then > set _first_non_whitespace_char to _i > exit repeat > end if > end repeat > set _smart_point to (get insertion point before character > _first_non_whitespace_char of line _current_line_number) > end tell > > tell application "System Events" > if _current_point is equal to _smart_point then > -- Just go to start of line > key code 123 using command down > else > -- Go to start of line, then skip over whitespace > key code 123 using {shift down, command down} > key code 124 using {shift down, option down} > end if > end tell > 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.