Adding Language Support 1: Syntax Highlighting

Home Forums Multi-Edit User/Developer Additional Language/Compiler Support Adding Language Support 1: Syntax Highlighting

This topic contains 6 replies, has 18,591 voices, and was last updated by  Snow123 11 years, 4 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #2017

    deleyd
    Participant

    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.[list:m8vhrn4m][*:m8vhrn4m]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.
    [/*:m:m8vhrn4m]
    [*:m8vhrn4m]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.)
    [/*:m:m8vhrn4m]
    [*:m8vhrn4m]To change the text to italic check the Italic box for Font Style on the right hand side of the dialog.
    [/*:m:m8vhrn4m]
    [*:m8vhrn4m]To bold the text check the Bold box for Font Style on the right hand side of the dialog.
    [/*:m:m8vhrn4m]
    [*:m8vhrn4m]To create a custom color: Click Define, select a color, and click ‘Add to custom colors’.
    [/*:m:m8vhrn4m]
    [*:m8vhrn4m]To delete a custom color: Select the color (FG appears) and click ‘Delete’. (Then reset your FG color back to what it was.)[/*:m:m8vhrn4m][/list:u:m8vhrn4m]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:[list:m8vhrn4m][*:m8vhrn4m]text color (foreground color FG)[/*:m:m8vhrn4m]
    [*:m8vhrn4m]background of the text color (Background Color BG, for Highlighting text)[/*:m:m8vhrn4m]
    [*:m8vhrn4m]italicFont Style (right hand side of color dialog), check box for Italic[/*:m:m8vhrn4m]
    [*:m8vhrn4m]boldFont Style (right hand side of color dialog), check box for Bold[/*:m:m8vhrn4m][/list:u:m8vhrn4m]

    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.)

    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’. Some typical symbols are +-*/=<>!#$%&,.:;?@\^_`|~

    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:

    [code:m8vhrn4m]"He said, \"Goodbye!\" and then left."[/code:m8vhrn4m]
    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 /* specifies the start of a block comment and the sequence */ specified the end of said block comment. You would enter /* in the ‘Open 1’ field and */ 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 forum.)

    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.[/quote:m8vhrn4m]

    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.

    ——————————————————————————
    Related Articles:







    (Additions to this Adding Language Support series are occasionally made as I have time.)

    Other Related Articles:
    [url:m8vhrn4m]http://www.multieditsoftware.com/addlanguage.php[/url:m8vhrn4m]

    #7040

    ReidSweatman
    Participant

    Being the paranoid soul I am, I’d suggest making your changes to a copy of the .MWL file in the Config directory, then shutting Multi-Edit down and copying the modified copy back over the one in the Config directory. I wouldn’t ever modify anything in the Defaults directory, as the files there are your only default backups, unless you want to reinstall. Besides, you may have already made mods to the in-use file you want to keep.

    One minor note: when I set up the .MWL files originally (I’m sure some have been done since my time), I sorted each of the four keyword lists by increasing length, and by ascending alphabetic order within same-length buckets. My reason for this was to allow the user to write a macro to find all keywords in a given file and substitute the version from the .MWL file for each, regularizing the capitalization (especially if the user had modified the capitalization of some words in one or more .MWL files). This was never incorporated into the program formally, although the .MWL files I wrote shipped this way.

    Sometime in the near future I’ll be posting the macros I used to do the length/alphabetic sort and the keyword replacement, in case anyone’s interested in that sort of thing.

    #7041

    Clay Martin
    Keymaster

    A point worth mentioning to someone who creates their own color scheme, or modifies one of the existing ones. After you have made your changes you need to press the Save button (under the color scheme selector). If you just close the dialog (Ok button) you will see your changes, but they will be for this session only, and after a restart of ME you will be right back to where you were before editing the colors. :shock:

    This one bites me all the time.

    HTH,
    Clay

    #7216

    lbledsoe
    Participant

    I’m using the HTML Language setup. The highlighting generally works, however I entered words "res1 res2 res3 res4" in their respective Reserved Words fields. I then set special colors for the same. I tried entering the words in various place in a .HTM file and… NOTHING. No way can I get these to hilite.

    I can change the color of other stuff and it works fine.

    ALSO – I would like to be able to hilite the Literal char (eg backslash) so I don’t get too confused when working with JavaScript. I added the backslash to the Symbols box and… no change for that either.

    Any ideas?

    #7218

    deleyd
    Participant

    The HTML language is handled in a special way, using Multi-Edit WebLair.

    Here is an example of what can be assigned different colors:

    And this is the color setup I made which shows these colors:

    The keywords and symbols for the JavaScript code inside this HTML file is determined by the setup for the Javascript language. So here a slash / is in the list of symbols for the JavaScript language, which displays in the "Symbol Text" color (blue & bold font in this example). You could add the backslash to the list of symbols for the Javascript language.

    WebLair symbols are set via

      [*:7txtr5m8]TOOLS -> CUSTOMIZE -> WEBLAIR [/*:m:7txtr5m8][*:7txtr5m8]Select HTML4 and click ‘Edit’ to get the HTML4 TAG DATABASE window. [/*:m:7txtr5m8][*:7txtr5m8]Select a tag word and click ‘Edit’.[/*:m:7txtr5m8][/list:o:7txtr5m8]

      (Note: WebLair was initially made back when web browsers weren’t as standardized as they are today, so there are boxes where you can enter which version of HTML the tag was first introduced, and which version of Netscape, Internet Explorer, and Mosaic the tag is first supported in.)

      To add .XHTML to the list of recognized HTML type file extensions:

      [*:7txtr5m8]TOOLS -> CUSTOMIZE -> GENERAL(left side) -> FILENAME EXTENSIONS[/*:m:7txtr5m8][*:7txtr5m8]Select "HTM HTML CDL SHTML" and click ‘Edit’ to get the "Edit Filename Extension Setup" dialog[/*:m:7txtr5m8][*:7txtr5m8]In the upper left corner add XHTML to the "Extension(s)" field[/*:m:7txtr5m8][/list:o:7txtr5m8]
      For more information go to the Multi-Edit online help and do a search for WebLair.
    #7219

    lbledsoe
    Participant

    Thanks… That help a lot!

    Is there anyway to hilite a Special Char or Reserved Word inside a String? For example:

    I’d like to hilite his string: ‘http:\/\/www.foo.com’ …

    … like this: ‘http:\/\/www.foo.com’

    So I can easily see the literal char in strings.

    Thanks again!

    #7831

    Snow123
    Participant

    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’.
    :P

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.