No need to script stuff that already works.
Alex Satrapa | web.mac.com/alexsatrapa | Ph: 0407 705 332
The original poster wants to be able to move the cursor to a position
immediately before the first non-whitespace character of the current
line. The best the numeric keypad option can do is move it to the very
start of the line.
>
> Alex Satrapa | web.mac.com/alexsatrapa | Ph: 0407 705 332
>
> On 30/07/2010, at 6:37, offtone <aar...@gmail.com> wrote:
>
>> My PC editors had a sorely-missed feature that basically
>> enabled the HOME button on my keyboard to intelligently go to the
>> "real" beginning of the line I was on.
>
> --
> 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 bbe...@googlegroups.com
> To unsubscribe from this group, send email to
> bbedit+un...@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 "sup...@barebones.com" rather than posting to the group.
>> BBEdit User Manual -> Use Numeric Keypad for Cursor Movement
>>
>> No need to script stuff that already works.
>
> The original poster wants to be able to move the cursor to a position
> immediately before the first non-whitespace character of the current
> line. The best the numeric keypad option can do is move it to the very
> start of the line.
whoops - my bad!
> The original poster wants to be able to move the cursor to a position
> immediately before the first non-whitespace character of the current
> line. The best the numeric keypad option can do is move it to the very
> start of the line.
I think the best you could do *without* a script is two key combinations: Command-Left Arrow to move the cursor to the beginning of the line, followed by an Option-Right Arrow to move to the position of the first non-whitespace character (this can also be done with the numeric keypad or emacs key bindings).
To do it with a single key combination, however, I think a script is required. Try something like this:
1. Read about scripting searches in the BBEdit User Manual (page 316). You can open the manual from BBEdit's Help menu.
2. In your script, tell BBEdit to move the cursor to the beginning of the current line.
3. Tell BBEdit to perform a scripted grep search for the first non-whitespace character (\S).
4. If a match is found, tell BBEdit to position the cursor before the matching character (select insertion point before...).
5. Test for fringe cases and debug as necessary.
6. Save your new script to ~/Library/Application Support/BBEdit/Scripts/.
7. Assign a key combination using the Scripts palette (Window -> Palettes -> Scripts).
Hope this helps.
-Dennis
> From AppleScript Editor you can open dictionaries for each
>application. Check out BBEdit's and look for the pieces that let you
>look at the current line, then you can make use of the regex you gave
>combined with grep search and you should be on your way pretty
>quickly. Getting use to the Applescript language will be the biggest
>hurdle.
You bet! for someone who's only had a Mac for a month. Likely to send
a man howling back to Windows!
First it's worth pointing out that command+leftarrow take the
insertion point to the beginning of the line in any Mac editor and
adding the shift key selects all text from the insertion point to the
beginning of the line.
But to answer the question...
... if you paste the script below into Script Editor or Smile and
save it (as script) in your BBEdit Scripts folder, which you will
locate using the Scripts menu (scroll thing) in BBEdit...
tell application "BBEdit"
set _n to startLine of selection
tell the front document
set _line to contents of line _n
set _chars to characters of _line
repeat with _i from 1 to count _chars
if item _i of _chars is not in {space, tab} then
set _start to _i
exit repeat
end if
end repeat
select insertion point before character _start of line _n
end tell
end tell
then you will be able to do what you want from the menu, which will
be a pain. so you will then do menu Window::Palettes-> and check
Scripts, where you will see your new script listed. Select it and
click the Set Key button. You will then be able to assign whatever
key combination you want to the script (including command+leftarrow
if you like).
JD
Here is another quick applescript solution. As another poster pointed out The two shortcuts Cmd + left and Option + right will bring your cursor to the desired position. You can glue this two shortcuts together with applescript using System Events. After that you can assign a single shortcut to this script in BBEdit.
tell application "BBEdit"
activate
tell application "System Events"
key code 123 using command down
key code 124 using option down
end tell
end tell
System Events allow you to simulate keyboard and GUI events in applescript. To work properly you must turn on the option "Enable access for assistive devices" in the Universal Access System Preference pane of your mac. Tables of key codes should be easily found with a search engine of your choice.
Another tip: If you are fed up fiddling around with Applescript you might consider using a macro software like Keyboard Maestro. It fulfills most of my tweaking desires much faster than spluttering my way to the correct Applescript pronunciation.
happy keyboarding
Roland
>Thanks, all, for the flood of helpfulness! I didn't know about the CMD
>+ LEFT / OPTION + RIGHT trick. Would definitely be simpler to just
>emulate those two keypresses and bind them to my HOME key.
Simpler still: go to the Editing:Keyboard preferences and change
the preference setting under "Home" and "End" keys:
( ) Scroll to beginning and end of document
( o ) Move cursor to beginning and end of current line
This does not address your need for a "smarter" version as
you've described, but it seems like you're well on your way to
scripting that.
Enjoy,
R.
--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <http://www.barebones.com/>
Someday I'll look back on all this and laugh... until they
sedate me.
>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
>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
> repeat with _i from 1 to _linelength
> if item _i of _line is not in {space, tab, ASCII character 202} then
I've just realized that's not very clever. Should be:
set _nbsp to ASCII character 202
repeat with _i from 1 to _linelength
if item _i of _line is not in {space, tab, _nbsp} then
otherwise time is wasted calling the OSAX at each iteration.
JD