Adding Language Support. 1: Syntax Highlighting

COLOR SETUP DIALOG

First become familiar with the COLOR SETUP dialog.

TOOLS → CUSTOMIZE → General(left side) → COLOR SETUP (right side)

Click on HELP in that dialog and read all about the COLOR SETUP dialog.

Also look up COLORS in the index of the Multi-Edit User's Guide and read what it has to say there about the Color Setup Dialog. Be sure to try out all the different Color Templates (upper left of the Color Setup dialog).

In the COLOR SETUP dialog scroll down the listbox on the left side until you come to the Syntax Highlighting section. There is a direct correspondence between items here and items in the Language Setup dialog.

Note the entries are:
Reserved Words 1
Reserved Words 2
Reserved Words 3
Reserved Words 4
Symbol Text
Brackets
EOL Comment 1
EOL Comment 2
EOL Comment 3
EOL Comment 4
Open/Close Comment 1
Open/Close Comment 2
Numeric Text
String Text

Brief Overview of Setting Colors
Select an item in the list, such as Reserved Words 1.

  • The text color is the foreground color (FG). To set the foreground color select one of the Basic Colors or Custom Colors with the mouse and left-click.
  • To highlight text set the background color (BG). To set the background color select one of the Basic Colors or Custom Colors with the mouse and right-click. (For no highlighting set the background color to be the same as the background color for 'Normal Text', which is at the very top of the list.)
  • To change the text to italic check the Italic box for Font Style on the right hand side of the dialog.
  • To bold the text check the Bold box for Font Style on the right hand side of the dialog.
  • To create a custom color: Click Define, select a color, and click 'Add to custom colors'.
  • To delete a custom color: Select the color (FG appears) and click 'Delete'. (Then reset your FG color back to what it was.)

Make sure the On checkbox for Syntax Highlighting is checked (top of dialog), otherwise none of the language's reserved words will be shown in the special color you specify.

Also, for each entry in the listbox under the Syntax Highlighting heading, make sure the Use Color and Use Font checkboxes in the Control section (right side) are checked. Otherwise you won't get the color and/or you won't get the font style you selected for that entry.

In the following discussion of the Language Setup Dialog, when I say “the color specified in the Color Setup dialog” you can specify more than just color, you can specify:

  • text color — foreground color FG
  • background of the text color — Background Color BG, for Highlighting text
  • italic — Font Style (right hand side of color dialog), check box for Italic
  • bold — Font Style (right hand side of color dialog), check box for Bold

LANGUAGE SETUP DIALOG

Now have a look at the Language Setup Dialog.

TOOLS → CUSTOMIZE → General (left side) → Languages (right side).

You may view any existing language setup by selecting the language and clicking EDIT. To add support for a new language, click INSERT to get an empty Language Setup dialog which you can fill in. (Click the HELP button in the lower right corner and read what it has to say about the Language Setup dialog.)

Image

Let's go through the fields from top to bottom:

  • Language — The name of your language. (Later we will go to the File Extension Setup dialog and assign a file extension to your language using this name.)
  • Case Sensitive — Check this if your language is case sensitive. Otherwise the language is treated as case insensitive and reserved words will be recognized regardless of their case.
  • Reserved Words
    1. All words entered here will be displayed using the color specified in the Color Setup dialog for 'Reserved Words 1'.
    2. All words entered here will be displayed using the color specified in the Color Setup dialog for 'Reserved Words 2'.
    3. All words entered here will be displayed using the color specified in the Color Setup dialog for 'Reserved Words 3'.
    4. All words entered here will be displayed using the color specified in the Color Setup dialog for 'Reserved Words 4'.
  • Note — The four Reserved Words fields each have a maximum length of 3000 characters.
  • Note — See section below titled Using *.mwl files to specify syntax keywords for a new alternate way of specifying keywords. That is now the preferred method.
  • Symbols — Symbols entered here will be displayed using the color specified in the Color Setup Dialog for 'Symbol Text'.
  • Brackets — Brackets entered here will be displayed using the color specified in the Color Setup Dialog for 'Brackets'. Common brackets are ()[]{}
  • Strings — Enter a double quotation mark (”) if strings in your language are enclosed in double quotation marks. Enter a single quotation mark (') if strings in your language are enclosed in single quotation marks. You may enter both a single and a double quotation mark if strings in your language may be enclosed in either. (Other delimiters may work, but I've never encountered a language that uses something other than single or double quotation marks.) Strings will then be displayed using the color specified in the Color Setup dialog for 'String Text'.
  • Literal — If there is a special escape character which when found in a string means take the next character literally, enter that character in the 'Literal' field. For example, in CMAC in a double-quoted string the backslash character is a special character, so we enter a backslash here. This way a double quote will not be interpreted as the end of the string if it is preceded by a backslash. Thus the following string will be properly interpreted as a single string rather than two strings: “He said, \”Goodbye!\” and then left.”

Tech Note — Some predefined languages in Multi-Edit have two backslashes in the 'Literal' field. This is not necessary. One will suffice.

Numeric
When Multi-Edit comes across a word which starts with a character entered in this field it will display that word using the color specified in the Color Setup dialog for 'Numeric Text'. Digits 0-9 are implied, so you don't have to enter them. For example, if you enter # in this field, then any word starting with # will be displayed using the color specified in the Color Setup dialog for 'Numeric Text'.

Block Comments
If your language supports starting and ending block comment characters enter them here. For example, in C and CMAC the sequence specified the end of said block comment. You would enter in the 'Close 1' field. Then these comments will be displayed using the color specified in the Color Setup dialog for 'Open/Close Comment 1'.

Similarly, a block comment specified by the starting and ending characters in the 'Open 2' and 'Close 2' fields will be displayed using the color specified in the Color Setup dialog for 'Open/Close Comment 2'.

End of line comments
Specify the character or character sequence that identifies the beginning of a comment which extends to the end of the line.

  • A comment identified by End of line comments 1: will be displayed using the color specified in the Color Setup dialog for 'EOL Comment 1'.
  • A comment identified by End of line comments 2: will be displayed using the color specified in the Color Setup dialog for 'EOL Comment 2'.
  • A comment identified by End of line comments 3: will be displayed using the color specified in the Color Setup dialog for 'EOL Comment 3'.
  • A comment identified by End of line comments 4: will be displayed using the color specified in the Color Setup dialog for 'EOL Comment 4'.

If your language dictates that any text beyond a certain column number is to be treated as a comment, enter that column number in the Column: field for one of the entires. For example, FORTRAN-77 specifies that any text beyond column 72 is a comment, so you would enter 73 in this field to specify that comments begin with column 73.

You can also combine Comment Character(s) with Comment Column to specify that if a certain character is in a certain column, then starting there to the end of the line is a comment. For example, in FORTRAN-77 a “C” in column 1 specifies that line is a comment, so you enter a C for the character and 1 for the column.

You can also specify that a comment character or character sequence must be the first non-whitespace character on the line in order for it to be a comment character by specifying -1 as the comment column number.

Some people have been creative in their use of the four different end of line comments you can define. They have used them for other things that they want to stand out. (See the thread Coloring Specific Lines in the Suggestions forum.)
Quote:
I have set up four different EOL comments, each with their own color scheme. I can then insert the appropriate comments in my code to make lines show up as different colors. I have colors (with varying intensities) for “TODO/CRITICAL”, “Headings”, “Normal Comments”, and a very muted gray for code I comment out that is slated for the chopping block. I use a muted color to help keep it from distracting me whereas for TODO/Critical I use a very loud red. The headings are intense yellow, and my normal comments are a pale yellow. It breaks up the code very nicely.

SepChars
(See Multi-Edit help. The only example I have found of this being used is with PERL.)

Note: If you make a change to the display colors in the Color Setup dialog for a color used by a particular language, and you have a file already loaded which uses those colors, you will need to close and reopen that file for the new colors to take effect.

Note: The color template name you have displayed in the Color Templates field of the Color Setup dialog will become the default color template when you click the OK button. The default color template is used when no special color template is specified for a particular language.

Using *.mwl files to specify syntax keywords

New to Multi-Edit 9.10.04, you can now use an external *.mwl word list file to specify an unlimited number of keywords to syntax highlight. This can be used instead of entering keywords in the Reserved Words fields of the Language Setup dialog above. By default each language can have a word list file with the name of the language such as CMac.mwl and C.mwl. These files are stored in the \Defaults subdirectory of the Multi-Edit installation (e.g. C:\Program Files\Multi-Edit\Defaults). See the *.mwl files in the \Defaults directory for an example of the format.

By default when the first file of a specific language is loaded the *.mwl with the same name as the language will be opened and the words in the list added to the syntax highlighting keyword list.

At first Multi-Edit will copy the *.mwl file from the \Defaults subdirectory to the \Config directory and format it for use. After that, when Multi-Edit loads the first file of a specific language, it will first search the \Config directory for a formatted *.mwl file. If one is found it will use it. If one is not found, Multi-Edit will search the \Defaults directory.

Do not edit or change the *.mwl files in the \Config directory. Instead, make your changes to the *.mwl file in the \Defaults directory, then delete the corresponding *.mwl file in the \Config directory so Multi-Edit will load the new *.mwl file from the \Defaults directory.

Edit: The location of the Multi-Edit \Config directory depends on what version of Multi-Edit you have. See
“How to find the Multi-Edit Config Directory” http://www.multiedit.com/forums/viewtopic.php?t=2013

If additional word lists are desired for a language, then setting the WORDLISTMAC= property string in the Language Setup dialog to “WORDLISTMAC=LangWordList /F=WordList1.mwl;Wordlist2.mwl” will cause them to be loaded when loading a file with the specified language is loaded. To access the Language Setup dialog, go to Tools | Customize | General | Languages, select your language and click 'Edit'. Then click 'Property Strings' (lower right) to get the Edit Property Strings dialog. There add your line. Tech note: There are currently no examples of this, although the HTML language has a “WORDLISTMAC=wl_LoadWordList” property string.

 
doc/tutorial/add_new_lang_01.txt · Last modified: 2009/02/18 11:37 by geofff     Back to top