On 11/30/2017, at 16:57, Oliver Boermans <[email protected] 
<mailto:[email protected]>> wrote:
> I’ve fantasised about taking keyboard word selection further, I’d like the 
> same keyboard shortcut to do a little more if the word was already >selected<.
> 
> Specifically I’d like it to attempt to expand to inside (then around) the 
> next closest pair of delimiters (<[{“"''"”}]>), a “selection expander” e.g.


Hey Oliver,

Gruber's script is elegant in its economy, but it doesn't handle hyphenated 
words (and perhaps some other cases).

I'll use it for a while and then have a go at improving it.

Here's what I think is a pretty good effort at your 
expand-selection-to-delimeter request, although it hasn't been tested enough 
yet for me to be confident.

----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/12/02 01:30
# dMod: 2017/12/02 01:52 
# Appl: BBEdit
# Task: Expand selection to next closest pair of delimiters.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @BBEdit, @Expand, @Selection, @Next, 
@Closest, @Pair, @Delimiters
----------------------------------------------------------------

tell application "BBEdit"
    tell front text window
        
        set findBackwardsRec to find "[{‘’“”\"'}]" options {search mode:grep, 
backwards:true}
        set startChar to characterOffset of found object of findBackwardsRec
        set findForwardsRec to find "[{‘’“”\"'}]" options {search mode:grep}
        set endChar to characterOffset of found object of findForwardsRec
        
        select (characters startChar thru endChar)
        
    end tell
end tell

----------------------------------------------------------------

So — if the cursor is positioned between the “><” symbols below — the first 
iteration will select to the quotes and the second iteration will select to the 
brackets.

{ "Mary Pop><pins" }

I think it will be easy to incorporate the select-word script into it by doing 
something like this:

----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/12/02 01:30
# dMod: 2017/12/02 01:52 
# Appl: BBEdit
# Task: Select word next to cursor if not already selected — otherwise expand 
selection to next closest pair of delimiters.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @BBEdit, @Expand, @Selection, @Next, 
@Closest, @Pair, @Delimiters, @Word, @Cursor
----------------------------------------------------------------

tell application "BBEdit"
    tell front text window
        
        set selText to contents of selection
        
        if selText = "" then
            selectWordAtCursor() of me
        else
            set findBackwardsRec to find "[{‘’“”\"'}]" options {search 
mode:grep, backwards:true}
            set startChar to characterOffset of found object of findBackwardsRec
            set findForwardsRec to find "[{‘’“”\"'}]" options {search mode:grep}
            set endChar to characterOffset of found object of findForwardsRec
            
            select (characters startChar thru endChar)
            
        end if
        
    end tell
end tell

----------------------------------------------------------------
--» HANDLERS
----------------------------------------------------------------
on selectWordAtCursor()
    tell application "BBEdit"
        tell front text window
            
            set sel_offset to characterOffset of selection
            set cur_line to startDisplayLine of selection
            
            try
                select (last word of display_line cur_line ¬
                    whose characterOffset ≤ sel_offset)
            on error
                select display_line cur_line
            end try
            
        end tell
    end tell
end selectWordAtCursor
----------------------------------------------------------------

Yep — it seems to be working satisfactorily — although I've just cobbled it 
together from Gruber's script and mine.

If I use it regularly I'll put it all together to eke the last couple of 
milliseconds of speed out of it.

--
Best Regards,
Chris

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bbedit.

Reply via email to