Textpad Document Classes

Textpad is my preferred text editor. It is super-simple, but has a few advanced features that really make writing source code for various things so much nicer. Besides that it has coloring for various document classes.

Document classes are basically groups file extensions whose properties can be changed for each group. Example: you can completely change the coloring, paragraph options, tab-width and printing properties for HTML files only. Or you could add line numbers to Java script files and leave line numbering out for everything else. Or perhaps the PHP comment is not the same as the html comment (which it isn’t! HTML comments look like this: <!– Stuff –> and PHP comments look like this: // stuff or /* more stuff */.

Since I’ve been doing a lot of PHP scripting I was growing tired of looking at their comments and having them displayed as regular text (coloring-wise). So I decided to try and figure out how to add // and /* */ to the comments part of the HTML class (which was where the PHP file extension was located). Editing these options was conveniently located in a few preloaded syntax files (html.syn, text.syn, etc). What I found was much much cooler. I found out how to create an entirely -new- document class and was able to apply the php.syn file to it! Now the coloring on all php documents is specialized to that particular programming language!

Below is the process I took to create the PHP Document Class, although this can be applied to any filetype that you may want to open in Textpad:

  1. Make sure all internal files are closed or you will not be able to add a new document class.
  2. Go to Configure/Preferences.
  3. Click the Document Classes listing (top-level).
  4. Click the Add button. If the add and delete buttons are not available, you still have a file open in the current Textpad session.
  5. Type PHP in the empty box that appears at the bottom of the list and Enter.
  6. Click apply. Your new Document Class entry should appear in the rollout of the “Document Classes entry.
  7. The new entry should inherit the properties from the Default Document Class.
  8. Under the Document Classes listing, select the new PHP entry.
  9. Under the “Files in Class PHP” window, click the “New” button and type *.php. Enter to apply. Also add an entry for *.phps.
  10. Rollout this new PHP Document Class entry.
  11. Select the Syntax entry.
  12. Check Enable Syntax Highlighting. This will enable the Syntax definition file pulldown.
  13. Pull down the “Syntax definition file” box. Select “php.syn” and say OK.
  14. Close all Textpad sessions and re-open a php file to see the changes. Verify that /* */ patterns are the comment color and that () {} and [] are the brackets color.
  15. Optional: If you plan on printing your php sources, you may want to include line numbering.
  16. Select the Printing entry.
  17. Check the Options > “Line Numbers” box.

Other options in a Document Class include a lot of dealing with end-of-line behavior. The important one that I noticed in the HTML Document class (which was NOT included in the default) was the top-level option of “Strip trailing spaces from line when saving”. One other option that I just now decided to explore was the Tabulation entry. This is just a way of determining how big the tab character should be in number of spaces. If you look at the Java entry (which cannot be deleted), you will see that it has a default tab spacing of 4 characters and an indent size of 4 (contrary to the Default document class which is at 8). Therefore, I decided to copy the Java values into the PHP Document Class.

And in the time it’s taken to write this article, I’ve also added a class for CSS files, since they’re not included ANYWHERE!

Anyhow, hopefully this clarifies this type of thing for someone.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *