HOME   |   ABOUT ME   |    RESUME
ABOUT

This is an editor enhancement that allows you set custom highlight options.



FEATURES
This plug-in allows you to custom draw the contents of the Delphi editor window.  Colors can be specified, font attributes can be tailored, you can even tell CodeRush to draw lines.

You may ask yourself, doesn't the Color tab of Delphi's Editor Properties dialog do the same thing?  The answer, of course, is NO.  True, Delphi does allow you to define colors and font attributes for what appears in the IDE, customizing the appearance to your liking.  However, this plug-in takes things a (big) step further.

In Delphi, what you set are global options, all reserved words can appear in Bold font, all comments can appear Italicized, etc.  What would you do if you wanted all reserved words to appear in Bold but you also wanted to change the color of specific reserved words, say make the word PUBLIC in an object declaration appear in Blue?  Using just Delphi, you really can't do that.

Enter the Custom Highlighting plug-in.

With this plug-in, you have the ability to custom tailor the display of the editor regardless of the color scheme you have selected in Delphi.  Custom Highlighting gives you the power to specify a pattern and have CodeRush:
Using this plug-in, you can make your editor window look like this:






























Setup
This plug-in makes use of a custom INI file named CustomHighlighting.ini.  This file contains all of the settings for the custom highlighting schemes you define.  A sample CustomHighlighting.ini file is included with this plug-in to get you started.  Copy it to the CodeRush\Settings\Editor folder.

How It Works
How does this plug-in give you such flexibility, you may ask?  Simple.  When installed, the Custom Highlighter registers an Options page; it is located under the CodeRush Options|Editor node (see the screenshot below):


















Selecting the Custom Highlighting node displays the new Options page for the Custom Highlighting plug-in.  This page appears below:



































This page is divided into five primary sections:
File Type
The Custom Highlighting plug-in allows you to define highlighting schemes that will be applied to the contents of the editor window.  These highlighting schemes can be designed by file type.  This can be very useful if you edit multiple file types in Delphi and you want each to have its own custom look and feel.  By default, this plug-in is configured to work with several file types, as shown in the screenshot below:








As you change options in the File Type combo box, the contents of the Highlighting Scheme window will change to display just those schemes that have been defined for the active file type.

The Options Page also allows you to add a new file and either edit or delete an existing file type.  This is handled with the three buttons (New, Edit, Delete) that sit to the right of the File Type combo box.  Say, for instance, you wish to create a new file type to work with Delphi Project (*.dpr) files.  First, you would click the New button; the following dialog will appear:










Fill in any descriptive text you would like into the Description field.  This text is used to allow you to identify the file type you are creating; it will appear in the drop-down list of the combo box.  Enter the file extension(s) for the file type in the field titled File extensions.  Do not include the "." symbol.  If more than one extension is entered, separate each with a ";" character.  For this example, I will specify "Project files" as the description and an extension of "dpr".

Click OK to save your new file type definition.  When the dialog closes, you will notice the contents of the Highlighting Scheme window change.  Whatever text was displayed will be replaced with a single grayed-out entry titled #CurrentIdentifier#.  This is used for the HighlightCurrentIdentifier function.

If you wish to make changes to a File Type definition, simply select the file type in the combo box and press the Edit button.  A dialog similar to the following will appear; for this example, I am editing the File Type definition created above:










We can change the Description to "Delphi Project files" and update the File extensions to "dpr;bpg".  When we click OK to save our changes, we can see the File Types combo box now includes our new file type.










Note: CodeRush will automatically select the correct scheme to apply based upon the file type in the editor; you do not have to return to the Options Page to select the active scheme.  If you have multiple files open in the editor, of different file types, CodeRush will display each file in its proper highlighting scheme.

Note: If no highlighting scheme exists for the file type open in the editor Delphi defaults are used instead.

Tip: If you want the same highlighting scheme to be applied regardless of the file type (not recommended), you can simply declare a file type of *.*.

Highlighting
The Highlighting Scheme Window is a check list box displaying the actual highlighting definitions that will be applied for the current file type.  A sample window displaying a list of highlight schemes for Pascal (*.pas) files appears below:





























Each item in the list represents a unique highlight that will be applied to the source file in the editor; the text displayed for each item represents the search text to match for the highlight to be applied.  The meaning of each scheme actually defined in the Search Text, Highlight, and Comment sections which follow.  All of the checked items will be applied when a *.pas file is active in the editor.

To modify an existing highlight scheme, simply make the appropriate alterations in either the Search Text, Highlight, or Comment section and click the Option Page's OK button to save.

To create a new highlight scheme, click the New button.  A new entry will be stubbed out in the Highlighting listbox; its title will be (Enter regular expression to match here).  The Search Text section will display this same information and the Highlight and Comments sections will be reset.

Simply fill in your criteria, as outlined in the following sections, and click OK to save your changes.

Note: Remember to check the boxes for whichever highlight schemes you wish to be active.

Search Text
Search text can be entered in one of two ways.  You can, of course, specify literal text to match.  All occurrences of that text in your source file will be highlighted as indicated in the Highlight section, below.  The real power of this plug-in comes in its ability to allow you to specify a regular expression (regex) to match.

No matter which search method you choose, the plug-in can be instructed to do a Case Sensitive match.

For those familiar with regular expressions, you know they are a hugely powerful method for applying a search criteria to text.  If you are not familiar with the use of regular expressions, you really should be.  Regular expressions can carry a heavy load of meaning in a small amount of space.  There are various regex implementations; the one used in this plug-in is based on the style of the UNIX operating system.

As there are countless books published and references on the Internet on the use of Regular Expressions, this page will not attempt to act as a tutorial.  The examples provided should be enough to get you started.

How do we create a new Search Text?  Easy.  As mentioned in the Highlighting section above, click the New button.  The Search Text window will update to display the following:







All we need to do is replace the text in the edit box with our search criteria.  Suppose I want to create a new highlight to match occurrences of my name in the source code (a little vain, I realize!).  I could simply create a literal search that matches my name exactly, as follows:







That would work fine, but what happens if I want to make sure I get a match whether I enter my name as "Rich Ackerson", "R Ackerson", or "Richard Ackerson"?  I could create a pile of literal search text strings, but why would I want to?  A simple regular expression takes care of everything for me.

If I change the search text entered above as follows:







we will have a search text that matches all occurrences of my name.  Breaking apart the search text section, we see the Regular Expression checkbox is now selected, instructing the plug-in to interpret the contents of the Pattern edit box as a RegEx expression.  The expression itself evaluates as follows:
When the OK button is click to save these changes, all occurrences of my name will be displayed in the highlight pattern specified under the Highlight section.

Note: In the example above, absolutely no effort was made to make the regular expression advanced enough to guarantee something resembling my name is actually matched.  Basically, the RegEx is the example above will match ANY two word string with the first word starting with an upper-case R and the second word starting with an upper-case A.  So "Rich Ackerson" is a match, but so is "Robert Anderson", and "Red Apples", etc.

Highlight
The Highlight section is where you can let your inner-artist come to life!  It is here that you specify exactly what you would like your matched text to look like.  Should it be italicized?  Should it be underlined?  Should it be in bold type?  What color should it be?  How about some fancy lines around it?  All of this is possible in any combination you choose.

The Highlight section is a group of controls for specifying text foreground and background color, line style, line color, and line placement, as follows:



















Using my Search Text example from above, suppose I want my name to appear in red font with a beige background surrounded by a blue frame.  First, I would select my text color.  Do this by passing the mouse over the color cylinder beside the Text Color label.  The current color beneath the mouse cursor will appear in the small window below the color cylinder.  Click the left mouse button to select this color as the foreground (text) color.  Click the right mouse button to select this color as the background color.

Repeat this step for selecting the Line Color.  Note that this is only required if you intend to draw a line as part of this highlight scheme.

To select a line style, select an option from the Line Style combo box.  Available choices are displayed below:











If we wish to shift the line to either the left or right, we can update the Highlight Padding fields.  For this example, we will leave the default values.

Our resulting Highlight definition will look like this:



















Now, whenever my name appears in the body of my source code, it will be displayed as:



Again, maybe not the most useful example, but it gives you an idea of what can be accomplished.

Comment
This section exists for your benefit; it serves no other functional use.  It is a free-form text area allowing you to describe the purpose of each highlight scheme.  This can prove incredibly useful, especially if you use Regular Expressions as part of your Search Text.  Unless you are extremely used to using regular expressions, it might not be immediately obvious that ^[\s\t]*\{ T[A-Za-z0-9_]+ \}$ is a search pattern that highlights class name comments (e.g., "{ TMyClass }").

So instead of guessing what a search text represents, all you have to do is type a brief comment describing it, as follows:






HighlightCurrentIdentifier Function
In addition to providing the automatic highlighting functionality described above, this plug-in registers a new function, HighlightCurrentIdentifier, that you can bind to a keystroke.

You set up the highlight scheme as you would any other highlight definition (see above), with a few limitations.  Basically, there is no Search Text to match.



































Simply go to the Options page and specify your File Type.  In the Highlighting window, select the option for #CurrentIdentifier#.  Declare your highlight criteria next.

Finally, make sure you bind this function to a keystroke.

When you are working with a file, place the cursor on top of any piece of text.  When you activate the HighlightCurrentIdentifier function, all occurrences of the text beneath the cursor will be displayed using the highlight scheme you specified on the Options page.

NOTE: While this IS a Developer Express plug-in, it is included on this site because the Custom Highlighting plug-in does not currently ship with CodeRush.  While it is freely available for the asking from Developer Express, I have also made it available here for your convenience.
WHAT'S  NEW?

Version 1.0

DOWNLOAD LINKS

CodeRush 6

CodeRush 7
Copyright 2004 Ackerson Software, All Rights Reserved.
Ackerson Software
Custom Highlighting
INFORMATION

Authors: Dustin Campbell and Mark Miller

Created: April 11, 2003

Plug-In Type: Standard

Options Page: Yes
This plug-in is currently supported.