I'm trying to write a different kind of "Select Word" script. I've used
Gruber's and several others, but find them lacking or buggy in lengthy
documents. Because I'm an applescript simpleton, and this is an interesting
exercise, I've done it with a chain of grep searches.
The logic I'm using is this:
1. Start by looking at the character to the right of the insertion point.
2. If that character is a space, then move to the beginning of the word (using
customized regex),
3. and then select to the end of the word (again, using a custom regex)
4. if not reverse the order of the searches.
This works very well for what I need, but I'd like to test for more than just a
space. Meaning: if the character to the right of the insertion point is a
space, or anything I define.
Is it possible to test the found text of nextChar as regex?
If you can point me in the right direction, I'd be grateful.
tell application "BBEdit"
--look at the next character
set nextChar to find "." searching in text of front text window options
{search mode:grep, wrap around:false}
if found text of nextChar = " " then --should also test for punctuation
-- search for the beginning of the word
find "^|(?<!\\w[^\\w\\s])\\b(?=\\w)" searching in text of front
text window options {search mode:grep, wrap around:false, backwards:true} with
selecting match
-- then extend the selection to the end
find "(?<=\\w)\\b(?![^\\w\\s]\\w)|$" searching in text of front
text window options {search mode:grep, wrap around:false, extend
selection:true} with selecting match
else
-- search for the end of the word
find "(?<=\\w)\\b(?![^\\w\\s]\\w)|$" searching in text of front
text window options {search mode:grep, wrap around:false} with selecting match
-- then extend the selection to the beginning
find "^|(?<!\\w[^\\w\\s])\\b(?=\\w)" searching in text of front
text window options {search mode:grep, wrap around:false, backwards:true,
extend selection:true} with selecting match
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>