## custmode.sl

Have you ever needed to syntax highlight a file but you did not have the appropriate mode for it? With this set of macros you can define a custom syntax in the highlighted file.

### Example

You have a simple text file. You decide that you want to higlight the words: @Title, @Author, @Date. The case of the words does not matter. You would also like to see the numbers in a different color. Also the strings should be highlighted. You put this at the beginning of your file:

      ;; -*- mode: custom; -*-
      ;; ### %words= @0-9a-zA-Z_
      ;; ### %keywords1= @Title @Author @Date
      ;; ### %numbers= -+0-9.
      ;; ### %string1= '
      ;; ### %string2= "
      ;; ### %syntaxflags= nocase

When you save the file and reopen it, you will see the desired effect.

### Syntax

The first thing to do is to add the modeline:

      ;; -*- mode: custom; -*-

The syntax definition must follow the modeline immediately. Each line must start with an optional comment symbol followed by `###`. Then there can be an arbitrary number of spaces and a tag: `%tagname=`.

      ;; ### %tagname= values

The syntax definition ends at the first line without `###`.

### Known tags

Tag | Type | Description | Value example
--- | --- | --- | ---
`%keywords1=` | list of keywords | List of keywords to be highlited; if the list is too long it can be split into multiple lines beginning with `%keywords1=` | `if then else`
`%keywords2=` | list of keywords | Defines the second set of keywords (see `%keywords1=`) | `sin cos tan`
`%words=` | set of characters | Defines the characters that compose a word | `a-zA-Z_0-9`
`%numbers=` | set of characters | Defines the characters that compose a number | `-+0-9.`
`%string1=` | character | Defines the single quote character | `'`
`%string2=` | character | Defines the double quote character | `"`
`%commenteol=` | string | Defines the end-of-line comment marker | `//`
`%preprocessor=` | character | Defines the preprocessor character | `#`
`%quote=` | character | Defines the 'Escape' character | `\`
`%parens=` | string | Defines the matching parenthesis | `[({])}`
`%modeflags=` | list of flags | Defines the flags for the mode (see a separate table for the list of possible flags) | `language fortran`
`%syntaxflags=` | list of flags | Defines the flags for the syntax (see a separate table for the list of possible flags) | `tex nocase`

See also `define_syntax()`.

List of flags for `%modeflags=`

`wrap` | 0x01
`c` | 0x02
`language` | 0x04
`slang` | 0x08
`fortran` | 0x10
`tex` | 0x20

See also `set_mode()`.

List of flags for `%syntaxflags=`

`nocase` | 0x01
`comfortran` | 0x02
`nocmodeldspc` | 0x04
`tex` | 0x08
`comeolspc` | 0x10
`preprocline` | 0x20
`preprocldspc` | 0x40
`nostrspan` | 0x80

See also `set_syntax_flags()`.

### Installation

Put the file somewhere on your jed_library_path and

       autoload ("custom_mode", "custmode.sl");

in your .jedrc file.