Yesterday I wrote about configuring Structural Highlighting, one of Castalia’s advanced syntax highlighting features. Today, I want to talk about Parenthesis Matching, another bit of smart syntax highlighting.
First, I’d like to explain why Castalia has parenthesis matching at all, since the Delphi code editor has had parenthesis matching built in for several versions now. The simplest reason is that it’s historical: I created parenthesis matching for Delphi 5, 6, and 7 (which don’t do it natively), and have kept it as Delphi has evolved. But then, why keep it around if Delphi does it natively now?
The second (and more important) reason is that Delphi’s built-in parenthesis matching is broken and, in my opinion, flawed. Consider this example screenshot (the screenshot is from Delphi XE, but the newer Delphi XE2 has the same broken behavior):
As you can see, Delphi’s built-in parenthesis matching doesn’t work correctly! It matches parenthesis that are not a syntactic match, instead matching a parenthesis that’s encapsulated in a string, which has no syntactic significance. Castalia’s parenthesis matching does not suffer from this problem.
The other major difference is the way closing parenthesis are handled. Castalia’s parenthesis matching is activated when the cursor is to the RIGHT of a closing parenthesis, so that when typing new code, you can see which parenthesis pair you just closed. Delphi’s native parenthesis matching only works when the cursor is to the left of a parenthesis, so it offers no benefit when writing new code.
Like Structural Highlighting, Parenthesis Matching is configurable. To configure, choose Castalia Options… from the Castalia menu, and drill down to Castalia Options | Editor | Smart Highlighting | Parenthesis Matching. You’ll see the Parenthesis Matching Options Pane.
The first two checkboxes toggle the feature on or off. Parenthesis matching also matches square brackets [ and ]. Both are controlled separately with these two checkboxes. If, for some reason, you want to turn Castalia’s parenthesis matching off, here is where you would do it.
The rest of the options control the appearance of the highlighting. There are color options for the foreground and background (so, for example, if you want the parenthesis matching blocks to appear as a green block with a red parenthesis, you can do that here). Finally, the “Bold Characters” checkbox controls whether the parenthesis are drawn bold or regular weight. For most color combinations, keeping the bold option turned on makes the matching parenthesis stand out even more, and I recommend keeping it turned on.
The last of Castalia’s three advanced syntax highlighting features is Flow Control Highlighting. I’ll write more about that later this week. For now, have fun playing with parenthesis matching, and if you don’t already have Castalia installed, download a free trial at twodesk.com/castalia.