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!

  • Digg
  • Facebook
  • MySpace
  • Twitter
  • Technorati Favorites
  • Evernote
  • Delicious
  • Share/Bookmark
Tagged with: keywordtextpadtutorial
 

Leave a Reply