Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Grep next with AppleScript
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Macdrifter  
View profile  
 More options Jan 7, 11:39 pm
From: Macdrifter <weath...@gmail.com>
Date: Sat, 7 Jan 2012 20:39:17 -0800 (PST)
Local: Sat, Jan 7 2012 11:39 pm
Subject: Grep next with AppleScript
I'm trying to figure out how to perform a grep for the next whole word
from the current insertion point. I had assumed I could use the find
function like so:

set results to find "\\b\\S+\\b" searching in lineOfInsertionPoint
options {search mode:grep, showing results:false, returning
results:true} with selecting match

but for a long line, this is very slow (as expected) since there are
so many matches. I really just want to select the next whole word and
stop there. I don't want to extend the selection like the built in opt-
shift-right arrow but rather change the entire selection to just the
next word.

Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christopher Stone  
View profile  
 More options Jan 8, 11:31 am
From: Christopher Stone <listmeis...@thestoneforge.com>
Date: Sun, 8 Jan 2012 10:31:21 -0600
Local: Sun, Jan 8 2012 11:31 am
Subject: Re: Grep next with AppleScript

On Jan 07, 2012, at 22:39, Macdrifter wrote:

> I'm trying to figure out how to perform a grep for the next whole word from the current insertion point. I had assumed I could use the find function like so:

______________________________________________________________________

Hey There,

I'm not certain how you can limit the search to the current line without it starting over and over again.

Try this, and see if you can live with it.

try

        tell application "BBEdit"
                tell text of front text document
                        set results to find "\\b\\S+\\b" options {search mode:grep, showing results:false, returning results:true} with selecting match
                end tell
        end tell

on error errMsg number errNum
        set {cr, sep} to {return, "------------------------------------------"}
        set e to sep & cr & "Error: " & errMsg & cr & sep & cr & "Error Number: " & errNum & cr & sep
        beep
        display dialog e
end try

--
Best Regards,
Chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Macdrifter  
View profile  
 More options Jan 8, 2:43 pm
From: Macdrifter <weath...@gmail.com>
Date: Sun, 8 Jan 2012 11:43:15 -0800 (PST)
Local: Sun, Jan 8 2012 2:43 pm
Subject: Re: Grep next with AppleScript
Hi Chris,

Very nice. I am a bit confused though. This seems much faster than
when the "searching in" modifier is used. This also only seems to
return one result where "searching in" returns all matches. I guess I
don't understand why limiting the the search to a specific line
returns all results a more generic find only returns one result. Did
you expect that? Whatever the reason, thanks for the help. This is
quite useful when triggered by a a hot key. It provides a mechanism to
quickly jump selections through the text. If I add a test for the
current selection length, I can also use an if statement to use the
Gruber "select current word" script.

Thanks again Chris. Nice work.

Gabe

On Jan 8, 11:31 am, Christopher Stone <listmeis...@thestoneforge.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Macdrifter  
View profile  
 More options Jan 8, 2:49 pm
From: Macdrifter <weath...@gmail.com>
Date: Sun, 8 Jan 2012 11:49:04 -0800 (PST)
Local: Sun, Jan 8 2012 2:49 pm
Subject: Re: Grep next with AppleScript
Here's the modified version that also incorporates John Gruber's Select
+Word script:

try
        tell application "BBEdit"
                tell text of front text document
                        set current_offset to characterOffset of selection
                        set current_line to startDisplayLine of selection
                        if length of selection = 0 then
                                select (last word of display_line current_line whose
characterOffset ≤ current_offset)
                        else
                                set results to find "\\b\\S+\\b" options {search mode:grep,
showing results:false, returning results:true} with selecting match
                        end if
                end tell
        end tell
on error errMsg number errNum
        set {cr, sep} to {return,
"------------------------------------------"}
        set e to sep & cr & "Error: " & errMsg & cr & sep & cr & "Error
Number: " & errNum & cr & sep
        beep
        display dialog e
end try

On Jan 8, 11:31 am, Christopher Stone <listmeis...@thestoneforge.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »