Prenthesis matching

1,695 views
Skip to first unread message

shoez

unread,
Jul 1, 2008, 7:23:42 AM7/1/08
to BBEdit Talk
In the next version of BBedit, I really, really hope they add better
parenthesis matching.

I use Ultraedit quite a bit when I have to use Windows, and even Vim
offers a really good feature whereby you position your cursor to the
left or right (depending on whether or not there are other
parentheses) or a bracket, and it highlights the opening and closing.
This allows you to scroll up large blocks of code and work out where a
block starts and ends. Very, very useful !

I've noticed that BBedit goes someway towards this, when you write a
new block and then close it, it will highlight the opening bracket.
But this needs to persist so one can scroll up the page without losing
focus.


tom

Rich Siegel

unread,
Jul 1, 2008, 7:32:33 AM7/1/08
to bbe...@googlegroups.com
On 7/1/08 at 7:23 AM, tom.l...@gmail.com (shoez) wrote:

> I use Ultraedit quite a bit when I have to use Windows, and even Vim
> offers a really good feature whereby you position your cursor to the
> left or right (depending on whether or not there are other
> parentheses) or a bracket, and it highlights the opening and closing.

View -> Balance.

Or double-click on a parenthesis, brace, or bracket.

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.

Maarten Sneep

unread,
Jul 1, 2008, 7:36:18 AM7/1/08
to bbe...@googlegroups.com

On 1 jul 2008, at 13:23, shoez wrote:

> I've noticed that BBedit goes someway towards this, when you write a
> new block and then close it, it will highlight the opening bracket.
> But this needs to persist so one can scroll up the page without losing
> focus.

cmd-B (Balance in the View menu) will select the contents of the pair
of delimiters the insertion point currently sits in between. Balance &
Fold in the same menu may also be of use.

Hope this helps,

Maarten

Roddie Grant

unread,
Jul 1, 2008, 8:35:11 AM7/1/08
to bbe...@googlegroups.com
On 1/7/08 12:32, "Rich Siegel" <sie...@barebones.com> wrote:

> On 7/1/08 at 7:23 AM, tom.l...@gmail.com (shoez) wrote:
>
>> I use Ultraedit quite a bit when I have to use Windows, and even Vim
>> offers a really good feature whereby you position your cursor to the
>> left or right (depending on whether or not there are other
>> parentheses) or a bracket, and it highlights the opening and closing.
>
> View -> Balance.
>
> Or double-click on a parenthesis, brace, or bracket.
>
> R.

It would be great if other delimiters could be added such as < and >, and
even selecting text between two (non-curly) apostrophes, with or without the
apostrophes.

And while we are at it ;-) some easy means to select "$varname" including
the $.

Regards

Roddie Grant


Carlton Gibson

unread,
Jul 1, 2008, 12:25:12 PM7/1/08
to bbe...@googlegroups.com
2008/7/1 Roddie Grant <rod...@myword.co.uk>:


Errr... , all of these things can be done pretty easily with the
existing search features (and maybe a bit of AppleScript) if you so
desire...

(What I wouldn't want is every little feature being added as an
explicit and inflexible menu option when the ability is already there
is a totally open form...)

Roddie Grant

unread,
Jul 1, 2008, 3:26:49 PM7/1/08
to bbe...@googlegroups.com
On 1/7/08 17:25, "Carlton Gibson" <carlton...@gmail.com> wrote:
> 2008/7/1 Roddie Grant <rod...@myword.co.uk>:
>> On 1/7/08 12:32, "Rich Siegel" <sie...@barebones.com> wrote:
>>> On 7/1/08 at 7:23 AM, tom.l...@gmail.com (shoez) wrote:
>>>
>>>> I use Ultraedit quite a bit when I have to use Windows, and even Vim
>>>> offers a really good feature whereby you position your cursor to the
>>>> left or right (depending on whether or not there are other
>>>> parentheses) or a bracket, and it highlights the opening and closing.
>>>
>>> View -> Balance.
>>>
>>> Or double-click on a parenthesis, brace, or bracket.
>>
>> It would be great if other delimiters could be added such as < and >, and
>> even selecting text between two (non-curly) apostrophes, with or without the
>> apostrophes.
>>
>> And while we are at it ;-) some easy means to select "$varname" including
>> the $.
>
> Errr... , all of these things can be done pretty easily with the
> existing search features (and maybe a bit of AppleScript) if you so
> desire...
>
> (What I wouldn't want is every little feature being added as an
> explicit and inflexible menu option when the ability is already there
> is a totally open form...)

I quite agree with the last point. Too many things means you miss them -
like the OP and View->Balance.

In these days of XML I'm always surprised the there isn't Balance for < and
> as they work much like brackets. Though I suppose in inequalities one can
appear without its counterpart which might be a complication.

If you can point me to a quick way of selecting "$abc" or "#FFCC66" I'd be
delighted. Learning AppleScript is on my ToDo list but at the moment it's
not a priority.

Thanks

Roddie Grant


Maarten Sneep

unread,
Jul 1, 2008, 3:32:59 PM7/1/08
to bbe...@googlegroups.com
On 1 jul 2008, at 21:26, Roddie Grant wrote:
> In these days of XML I'm always surprised the there isn't Balance for
> < and <as they work much like brackets. Though I suppose in
> inequalities
> one can appear without its counterpart which might be a complication.

In html and xml mode, the balancing distinguishes between the type of
the tags:
<p> balances with </p>, but not with </b>. I think that is even better.

Maarten

Carlton Gibson

unread,
Jul 1, 2008, 3:38:35 PM7/1/08
to bbe...@googlegroups.com
2008/7/1 Roddie Grant <rod...@myword.co.uk>:

>
> If you can point me to a quick way of selecting "$abc" or "#FFCC66" I'd be
> delighted. Learning AppleScript is on my ToDo list but at the moment it's
> not a priority.

Roddie,

Just quickly, searching using grep is your answer.

\$.+?\b will match variables like $abc, $variable, etc.

#[A-F0-9]{6} will match hex colour codes (using capitals).

The BBEdit Manual and Help has **excellent** guides to using grep.

Hope this helps.

Regards
Carlton

Roddie Grant

unread,
Jul 2, 2008, 5:03:35 AM7/2/08
to bbe...@googlegroups.com

Hi Carlton

Thanks for your help with this; grep is invaluable. What I was looking for
was a quick way to select with the mouse or a simple keystroke - like
double-click selects the word (but not the $ or #) and triple-click selects
a line or like Cmd-B selects from bracket to bracket.

This is not of major importance - my first post was only an "Ooh yes! It
would be nice if...", but I'm always ready to learn more efficient ways of
working.

Regards

Roddie

kaidoh

unread,
Jul 2, 2008, 5:40:21 AM7/2/08
to BBEdit Talk

Am 01.07.2008 um 14:35 schrieb Roddie Grant:

It would be great if other delimiters could be added such as < and >,
and
even selecting text between two (non-curly) apostrophes, with or
without the
apostrophes.

Applescript can be your friend on this. With the recording feature in
BBEdit's script menu you can easily mimicry missing features without
having to dig too deep into Applescript. I did this on exactly that
"Select text between string"-example.

Here is the script (not sure if the linebreaks survive this posting
from Googles webfrontend correctly, so watch out):

tell application "BBEdit"
find "(\"|')" searching in text 1 of text document 1 options {search
mode:grep, starting at top:false, wrap around:false, backwards:true,
case sensitive:false, match words:false, extend selection:false} with
selecting match
set daString to (grep substitution of "\\1")
select insertion point after selection
set theStart to characterOffset of selection
find daString searching in text 1 of text document 1 options {search
mode:grep, starting at top:false, wrap around:false, backwards:false,
case sensitive:false, match words:false, extend selection:false} with
selecting match
select insertion point before selection
set theEnd to (characterOffset of selection) - 1
select characters theStart through theEnd of text 1 of text document
1
end tell


Very quick and dirty and with a few quirks (misbehaves on single
unpaired apostrophes as in text's) but for me it gets the job done in
about 95 % and I use it all the time. Just add a keyboard shortcut and
off you go.

Enjoy
Roland

Roddie Grant

unread,
Jul 2, 2008, 6:40:53 AM7/2/08
to bbe...@googlegroups.com
On 2/7/08 10:40, "kaidoh" <medien...@googlemail.com> wrote:

> Applescript can be your friend on this. With the recording feature in
> BBEdit's script menu you can easily mimicry missing features without
> having to dig too deep into Applescript. I did this on exactly that
> "Select text between string"-example.
>
> Here is the script (not sure if the linebreaks survive this posting
> from Googles webfrontend correctly, so watch out):
>
> tell application "BBEdit"
> find "(\"|')" searching in text 1 of text document 1 options {search
> mode:grep, starting at top:false, wrap around:false, backwards:true,
> case sensitive:false, match words:false, extend selection:false} with
> selecting match
> set daString to (grep substitution of "\\1")
> select insertion point after selection
> set theStart to characterOffset of selection
> find daString searching in text 1 of text document 1 options {search
> mode:grep, starting at top:false, wrap around:false, backwards:false,
> case sensitive:false, match words:false, extend selection:false} with
> selecting match
> select insertion point before selection
> set theEnd to (characterOffset of selection) - 1
> select characters theStart through theEnd of text 1 of text document
> 1
> end tell

Brilliant!

I'm going to have to give learning AppleScript more priority.

Thanks

Roddie Grant


Carlton Gibson

unread,
Jul 2, 2008, 7:41:26 AM7/2/08
to bbe...@googlegroups.com
2008/7/2 Roddie Grant <rod...@myword.co.uk>:

> Brilliant!
>
> I'm going to have to give learning AppleScript more priority.
>
> Thanks
>
> Roddie Grant

Exactly the right reasoning. :-)

If you're basically using AppleScript just to automate tasks you'd do
with other BBEdit commands (like perform the kind of grep search we
talked about) then the AppleScript chapter in the BBEdit manual
contains all you need to get started.

Good luck.

Carlton

Bill Verity

unread,
Jul 2, 2008, 9:32:46 AM7/2/08
to bbe...@googlegroups.com, Roddie Grant
At 10:03 AM +0100 7/2/08, Roddie Grant wrote about Re: Prenthesis matching:
>...

>Hi Carlton
>
>Thanks for your help with this; grep is invaluable. What I was looking for
>was a quick way to select with the mouse or a simple keystroke - like
>double-click selects the word (but not the $ or #) and triple-click selects
>a line or like Cmd-B selects from bracket to bracket.
>
>This is not of major importance - my first post was only an "Ooh yes! It
>would be nice if...", but I'm always ready to learn more efficient ways of
>working.

If you double-click on a word and hold the "mouse" button down after
the second click, you can move the cursor left or right to pick up
the next "word".

So if you do this to #FFCC66, you will select FFCC66 first, then
moving left it will pick up the # and so on.

--
Good friends are hard to find, harder to leave, and impossible to forget.

Bill Verity - 814-865-4758 Fax: 814-863-7049
204S Wagner Building - Information Technology Services, Penn State University
At the office - on my Mac, of course ;-)

shoez

unread,
Jul 7, 2008, 5:24:43 AM7/7/08
to BBEdit Talk
Ahh that's really useful - thanks for that !

What are the possibilities of adding something less "proactive", in
the sense, I don't want to always activate a command in order to see
something - but I would still like the information conveyed - a sort
of "ambient balancing" ?
Reply all
Reply to author
Forward
0 new messages