Re: Newbie: Scripting a better HOME button?
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 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.
Re: Newbie: Scripting a better HOME button?
At 08:52 -0700 30/7/10, offtone wrote: I'll tinker around! Some solutions have already been posted, and they're helpful starts for sure. The script I posted is more than a "helpful start"; it is a full solution. Have you tried it?! JD -- 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.
Re: Newbie: Scripting a better HOME button?
Well, offtone was wanting the script to first go to the smart home position, and if done again, would go to the start of the line, and if already at the start of the line, would go to the smart home. The same behavior often found in IDEs like NetBeans when using the home key. Your script only went to the smart home, so it was not a "full solution" to his problem. It should be obvious he tried your script as he used most of it in the script he posted. -Kendall On Jul 31, 9:30 am, John Delacour wrote: > At 08:52 -0700 30/7/10, offtone wrote: > > >I'll tinker around! Some solutions have already been posted, and > >they're helpful starts for sure. > > The script I posted is more than a "helpful start"; it is a full > solution. Have you tried it?! > > JD -- 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.
Re: Newbie: Scripting a better HOME button?
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 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.
Re: Newbie: Scripting a better HOME button?
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 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 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.
Re: Newbie: Scripting a better HOME button?
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.