How to get TextPad to highlight keywords? A Syntax definition file (as the log.syn.zip attached) contains the information TextPad uses to highlight keywords in different colors:

Textpad - highlight keywords with syntax definition

Textpad - highlight keywords with syntax definition

If you want to implement syntax highlighting for a document class (for example for .txt files) you must create a file of keywords that you want to be colored, as described below, and copy it as for example “log.syn” in the Syntax folder.

To add a Syntax definition file, open Textpad and close ALL the open documents. Then go to:

Configure -> Preferences -> Document Classes

There you have “User defined classes”, add a new class clicking the rectangular shape and call it for example “Log Files”, then click Apply.
After this if you expand the “Document Classes” you will see the “Log Files” class.

Click the “Log Files” class and choose what kind of files to associate with it in “Files in class Lof Files”, as for example “*.txt” and “.log”.

Expand the “Log Files” class and go to “Syntax”. Check on “Enable syntax highlighting” and click Open and browse to the file “log.syn”.

From the submenu “Colors” you can also modify the colors to use with the Keywords 1, 2, 3, 4, 5, 6.

For example as default Textpad will display with red (Keyword 1) color the following:

[Keywords 1]
ABORT
ABORTED
ABORTING
BAD
CANCEL
CANCELLING
CANCELLED
CANNOT

You can then add / remove keywords in the list from the log.syn depending by how much colors you want to see ;)

General instructions for formatting the Syntax definition file

The first line of the file must be one of the following:

* TEXT=1 means that only URLs will be highlighted. All sections of the syntax definition file are ignored, so do not use this type.

* C=1 means that full syntax highlighting is available for languages which broadly conform to C syntax. All keywords are in a single namespace, so duplicates are not allowed.

* HTML=1 means that full syntax highlighting is available for languages which broadly conform to HTML syntax. Keywords are in two namespaces, with tags in one and their attributes in the other. The [i]Namespace1[/i] parameter controls how many of the six [i][Keyword][/i] sections are in the first namespace. Having two namespaces allows keywords such as TITLE, which can be both a tag and an attribute, to be colored according to context.

* PERL=1 is a variant of C=1, to take account of some peculiarities of Perl syntax.

* LaTeX=1 is a variant of C=1, to take account of some peculiarities of LaTeX syntax.

The rest looks like an .INI file, with the following sections:

* [Syntax]

* [Keywords 1]

* [Keywords 2]

* [Keywords 3]

* [Keywords 4]

* [Keywords 5]

* [Keywords 6]

* [Preprocessor keywords]

The [Syntax] section must be first, followed by [Keywords 1]. The other sections are optional. The [Preprocessor keywords] section can only be used when a single character (such as “#”) is used to start a statement that is handled by a pre-processor.

Keywords are entered one per line. The split between the keyword sections is arbitrary. You only need to use Keywords 2-6, if you want some keywords in different colors. They are all in the same namespace, unless “HTML=1″ is used, when “Namespace1 = n” specifies how many of the keyword sections are in the first namespace, with the remainder in another. This means that the same name can appear in both namespaces when “HTML=1″. The pre-processor keywords are always in their own namespace.

You can select the newly created .SYN file using the Preferences command on the Configure menu. It should be displayed in the drop-down list box for Syntax settings, for the new document class you created.

You can use my log.syn.zip package to check this out in Textpad!

DiggFacebookMySpaceTwitterTechnorati FavoritesEvernoteDeliciousShare
Tagged with: keywordtextpadtutorial
 

4 Responses to “TextPad – highlight keywords with Syntax Definition Files”

    Is it also possible to highlight a section based on its horizontal location instead? Let’s say I have a file in which lines look like this:
    111112223333333
    aaaaabbbccccccc

    I want the following syntax definition for each line: position 1-5 color red, 6-8 color green and 9-15 color blue. So 11111 and aaaaa should become red, etc.
    Cheers.

  1. Kjeld Sigtermans says:
  2. Hi! I am not sure if that is possible. You can try to define a number as belonging to a certain keyword, for exmaple “[Keywords 1] 1″, but if I have to guess I think that 1111122233333 would be interpreted as one whole word so I am not sure if it would work! :)

  3. Meanwhile I tried to find such functionality in TextPad as well as other popular text editors (who all seem to have a syntax definition implementation of some kind) but no luck. I guess its kind of logical because syntax definition means you define syntax, not a location. Still trying to find a solution.
    Thanks!

  4. Kjeld Sigtermans says:
  5. You’re right! good luck then :)

Leave a Reply