Message from discussion
A different kind of "select word"
Date: Wed, 17 Oct 2012 16:10:41 -0700 (PDT)
From: Kendall Conrad <angelw...@gmail.com>
To: bbedit@googlegroups.com
Message-Id: <5b6cc118-9514-4c92-bcbc-e5a587b8991e@googlegroups.com>
In-Reply-To: <E2D550B7-D336-4C34-8D69-6D5A478FB9FB@me.com>
References: <E2D550B7-D336-4C34-8D69-6D5A478FB9FB@me.com>
Subject: Re: A different kind of "select word"
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_874_28293493.1350515441780"
------=_Part_874_28293493.1350515441780
Content-Type: multipart/alternative;
boundary="----=_Part_875_32597004.1350515441780"
------=_Part_875_32597004.1350515441780
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
I've used something like this with a couple of my scripts.
if character 1 of found text of nextChar is in (characters 1 through -1 of
" ,;'\"") then
-Kendall
On Wednesday, October 17, 2012 6:17:22 PM UTC-4, Oliver Taylor wrote:
>
> 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*
>
------=_Part_875_32597004.1350515441780
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
I've used something like this with a couple of my scripts.<br><br>if charac=
ter 1 of found text of nextChar is in (characters 1 through -1 of " ,;'\"")=
then<br><br>-Kendall<br><br><br>On Wednesday, October 17, 2012 6:17:22 PM =
UTC-4, Oliver Taylor wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><di=
v style=3D"word-wrap:break-word">I'm trying to write a different kind of "S=
elect Word" script. I've used Gruber's and several others, but find them la=
cking 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 sear=
ches.<div><br></div><div>The logic I'm using is this:</div><div>1. Start by=
looking at the character to the right of the insertion point.</div><div>2.=
If that character is a <b>space</b>, then move to the beginning of the wor=
d (using customized regex),</div><div>3. and then select to the end of the =
word (again, using a custom regex)</div><div>4. <b>if not</b> reverse =
the order of the searches.</div><div><br></div><div>This works very well fo=
r 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.</div><div><br></div><div>Is it possible to test the <span st=
yle=3D"font-family:Verdana;font-size:12px;color:rgb(129,47,220)">found text=
</span><span style=3D"font-family:Verdana;font-size:12px"> <b>of</b>&n=
bsp;</span><span style=3D"font-family:Verdana;font-size:12px;color:rgb(79,1=
43,0)">nextChar</span> as regex?</div><div><br></div><div>If you can p=
oint me in the right direction, I'd be grateful.</div><div><br></div><div><=
div style=3D"margin:0px;font-size:12px;font-family:Verdana"><div style=3D"m=
argin:0px"><b>tell</b> <span style=3D"color:#0433ff"><i>application</i></sp=
an> "BBEdit"</div><p style=3D"margin:0px 0px 0px 39.2px;min-height:15px"><s=
pan style=3D"white-space:pre">=09</span><br></p><div style=3D"margin:0px 0p=
x 0px 39.2px;color:rgb(94,97,97)"><span style=3D"color:#000000"><span style=
=3D"white-space:pre">=09</span></span>--look at the next character</div><di=
v style=3D"margin:0px 0px 0px 39.2px;color:rgb(4,51,255)"><span style=3D"co=
lor:#000000"><span style=3D"white-space:pre">=09</span><b>set</b> </span><s=
pan style=3D"color:#4f8f00">nextChar</span><span style=3D"color:#000000"> <=
b>to</b> </span><b>find</b><span style=3D"color:#000000"> "." </span>search=
ing in<span style=3D"color:#000000"> </span><i>text</i><span style=3D"color=
:#000000"> <b>of</b> <b>front</b> </span><i>text window</i><span style=3D"c=
olor:#000000"> </span>options<span style=3D"color:#000000"> {</span><span s=
tyle=3D"color:#812fdc">search mode</span><span style=3D"color:#000000">:</s=
pan><span style=3D"color:#5d3292">grep</span><span style=3D"color:#000000">=
, </span><span style=3D"color:#812fdc">wrap around</span><span style=3D"col=
or:#000000">:</span><span style=3D"color:#5d3292">false</span><span style=
=3D"color:#000000">}</span></div><p style=3D"margin:0px 0px 0px 39.2px;min-=
height:15px"><span style=3D"white-space:pre">=09</span><br></p><div style=
=3D"margin:0px 0px 0px 39.2px;color:rgb(94,97,97)"><span style=3D"color:#00=
0000"><span style=3D"white-space:pre">=09</span><b>if</b> </span><span styl=
e=3D"color:#812fdc">found text</span><span style=3D"color:#000000"> <b>of</=
b> </span><span style=3D"color:#4f8f00">nextChar</span><span style=3D"color=
:#000000"> =3D " " <b>then</b> </span>--should also test for punctuation</d=
iv><div style=3D"margin:0px 0px 0px 78.5px;color:rgb(94,97,97)"><span style=
=3D"color:#000000"><span style=3D"white-space:pre">=09=09</span></span>-- s=
earch for the beginning of the word</div><div style=3D"margin:0px 0px 0px 7=
8.5px"><span style=3D"white-space:pre">=09=09</span><span style=3D"color:#0=
433ff"><b>find</b></span> "^|(?<!\\w[^\\w\\s])<a>\\b(?=3D\\w)</a><wbr>" =
<span style=3D"color:#0433ff">searching in</span> <span style=3D"color:#043=
3ff"><i>text</i></span> <b>of</b> <b>front</b> <span style=3D"color:#0433ff=
"><i>text window</i></span> <span style=3D"color:#0433ff">options</span> {<=
span style=3D"color:#812fdc">search mode</span>:<span style=3D"color:#5d329=
2">grep</span>, <span style=3D"color:#812fdc">wrap around</span>:<span styl=
e=3D"color:#5d3292">false</span>, <span style=3D"color:#812fdc">backwards</=
span>:<span style=3D"color:#5d3292">true</span>} <b>with</b> <span style=3D=
"color:#0433ff">selecting match</span></div><div style=3D"margin:0px 0px 0p=
x 78.5px;color:rgb(94,97,97)"><span style=3D"color:#000000"><span style=3D"=
white-space:pre">=09=09</span></span>-- then extend the selection to the en=
d</div><div style=3D"margin:0px 0px 0px 78.5px"><span style=3D"white-space:=
pre">=09=09</span><span style=3D"color:#0433ff"><b>find</b></span> "(?<=
=3D\\w)<a>\\b(?![^\\w\\s]\\w)|$</a><wbr>" <span style=3D"color:#0433ff">sea=
rching in</span> <span style=3D"color:#0433ff"><i>text</i></span> <b>of</b>=
<b>front</b> <span style=3D"color:#0433ff"><i>text window</i></span> <span=
style=3D"color:#0433ff">options</span> {<span style=3D"color:#812fdc">sear=
ch mode</span>:<span style=3D"color:#5d3292">grep</span>, <span style=3D"co=
lor:#812fdc">wrap around</span>:<span style=3D"color:#5d3292">false</span>,=
<span style=3D"color:#812fdc">extend selection</span>:<span style=3D"color=
:#5d3292">true</span>} <b>with</b> <span style=3D"color:#0433ff">selecting =
match</span></div><div style=3D"margin:0px 0px 0px 39.2px"><span style=3D"w=
hite-space:pre">=09</span><b>else</b></div><div style=3D"margin:0px 0px 0px=
78.5px;color:rgb(94,97,97)"><span style=3D"color:#000000"><span style=3D"w=
hite-space:pre">=09=09</span></span>-- search for the end of the word</div>=
<div style=3D"margin:0px 0px 0px 78.5px"><span style=3D"white-space:pre">=
=09=09</span><span style=3D"color:#0433ff"><b>find</b></span> "(?<=3D\\w=
)<a>\\b(?![^\\w\\s]\\w)|$</a><wbr>" <span style=3D"color:#0433ff">searching=
in</span> <span style=3D"color:#0433ff"><i>text</i></span> <b>of</b> <b>fr=
ont</b> <span style=3D"color:#0433ff"><i>text window</i></span> <span style=
=3D"color:#0433ff">options</span> {<span style=3D"color:#812fdc">search mod=
e</span>:<span style=3D"color:#5d3292">grep</span>, <span style=3D"color:#8=
12fdc">wrap around</span>:<span style=3D"color:#5d3292">false</span>} <b>wi=
th</b> <span style=3D"color:#0433ff">selecting match</span></div><div style=
=3D"margin:0px 0px 0px 78.5px;color:rgb(94,97,97)"><span style=3D"color:#00=
0000"><span style=3D"white-space:pre">=09=09</span></span>-- then extend th=
e selection to the beginning</div><div style=3D"margin:0px 0px 0px 78.5px">=
<span style=3D"white-space:pre">=09=09</span><span style=3D"color:#0433ff">=
<b>find</b></span> "^|(?<!\\w[^\\w\\s])<a>\\b(?=3D\\w)</a><wbr>" <span s=
tyle=3D"color:#0433ff">searching in</span> <span style=3D"color:#0433ff"><i=
>text</i></span> <b>of</b> <b>front</b> <span style=3D"color:#0433ff"><i>te=
xt window</i></span> <span style=3D"color:#0433ff">options</span> {<span st=
yle=3D"color:#812fdc">search mode</span>:<span style=3D"color:#5d3292">grep=
</span>, <span style=3D"color:#812fdc">wrap around</span>:<span style=3D"co=
lor:#5d3292">false</span>, <span style=3D"color:#812fdc">backwards</span>:<=
span style=3D"color:#5d3292">true</span>, <span style=3D"color:#812fdc">ext=
end selection</span>:<span style=3D"color:#5d3292">true</span>} <b>with</b>=
<span style=3D"color:#0433ff">selecting match</span></div><div style=3D"ma=
rgin:0px 0px 0px 39.2px"><span style=3D"white-space:pre">=09</span><b>end</=
b> <b>if</b></div><p style=3D"margin:0px 0px 0px 39.2px;min-height:15px"><s=
pan style=3D"white-space:pre">=09</span><br></p><div style=3D"margin:0px"><=
b>end</b> <b>tell</b></div></div></div></div></blockquote>
------=_Part_875_32597004.1350515441780--
------=_Part_874_28293493.1350515441780--