Smultron syntax colours your document if you have chosen so with the syntax definition of your choice.
(<?php and everything in grey until the closing tag (not shown here) are Instructions. <head><title> are Commands. echo is a keyword.)
Examples of the keys follows here (I use php right here):
beginCommand: < to show html commands
endCommand: >
beginInstruction: <? to start a block of code
endInstruction: ?>
beginVariable: $ the character (or any of the characters) that signals that is variable
endVariable: :;(){}=[]+-/.,*!?%&><\ anyone of these characters ends the variable name
firstString: " only one character is recognised for the strings
secondString: '
firstSingleLineComment: // a comment till the end of the line
secondSingleLineComment: # another comment till the end of the line
beginFirstMultiLineComment: /* the start of a multiline comment
endFirstMultiLineComment: */
beginSecondMultiLineComment: <!-- to allow e.g. html comments in php-code
endSecondMultiLineComment: -->
keywordsCaseSensitive: <false/> set either to </false> or </true> if you want the keywords to be case sensitive
recolourKeywordIfAlreadyColoured: <false/> if you want a keyword to be coloured as a keyword even if its already been coloured as a command
keywords: <string>and</string> a list of keywords
autocompleteWords: <string>auto-complete this word</string> a list of words to add to the auto-completion
functionDefinition: <string>a regular expression</string> a regular expression that finds the beginnings of functions in the document
removeFromFunction: <string>a string</string> a string that is removed from the function name, e.g. if the function is defined by having the word function in fron of it it can be removed from the list to make it easier to read
attributes: you cannot define this yourself but it defined as the word before a = in a command
excludeFromKeywordStartCharacterSet
excludeFromKeywordEndCharacterSet
includeInKeywordStartCharacterSet
includeInKeywordEndCharacterSet
just add all characters you want, to the string to these keys.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<array>
<plist version="1.0"><dict>
<key>name</key>
<string>PHP</string>
<key>file</key>
<string>php</string>
<key>extensions</key>
<array>
<string>php php3 phtml phtm</string>
</dict>
</plist>
The name-key is what shows up in the View menu and the file-key is what you name your file minus the .plist extension. The extensions-key lists the various extensions your language can have, space separated and without dots.
The colours:
The easiest way to learn which colours to choose in Preferences is to test on a document which you know well. But below is an image of a fictional php-code which might help you.
(<?php and everything in grey until the closing tag (not shown here) are Instructions. <head><title> are Commands. echo is a keyword.)
Change a syntax definition:
The syntax definitions are defined in plist files in the Application bundle (ctrl-click on Smultron and choose Show Package Contents -> Contents -> Resources) e.g. html.plist for HTML documents. If you want to change anything or add a keyword you can just change the file and save it. (Remember to treat special characters in the standard xml-way e.g. < instead of < and if you don't want leave a string empty please do it like this <string></string>.)Examples of the keys follows here (I use php right here):
beginCommand: < to show html commands
endCommand: >
beginInstruction: <? to start a block of code
endInstruction: ?>
beginVariable: $ the character (or any of the characters) that signals that is variable
endVariable: :;(){}=[]+-/.,*!?%&><\ anyone of these characters ends the variable name
firstString: " only one character is recognised for the strings
secondString: '
firstSingleLineComment: // a comment till the end of the line
secondSingleLineComment: # another comment till the end of the line
beginFirstMultiLineComment: /* the start of a multiline comment
endFirstMultiLineComment: */
beginSecondMultiLineComment: <!-- to allow e.g. html comments in php-code
endSecondMultiLineComment: -->
keywordsCaseSensitive: <false/> set either to </false> or </true> if you want the keywords to be case sensitive
recolourKeywordIfAlreadyColoured: <false/> if you want a keyword to be coloured as a keyword even if its already been coloured as a command
keywords: <string>and</string> a list of keywords
autocompleteWords: <string>auto-complete this word</string> a list of words to add to the auto-completion
functionDefinition: <string>a regular expression</string> a regular expression that finds the beginnings of functions in the document
removeFromFunction: <string>a string</string> a string that is removed from the function name, e.g. if the function is defined by having the word function in fron of it it can be removed from the list to make it easier to read
attributes: you cannot define this yourself but it defined as the word before a = in a command
Optinal values
You can also add any of four optional strings which adds or removes characters from the character sets that decide where a keyword can start or end. The four keys are:excludeFromKeywordStartCharacterSet
excludeFromKeywordEndCharacterSet
includeInKeywordStartCharacterSet
includeInKeywordEndCharacterSet
just add all characters you want, to the string to these keys.
Add new definition:
If you want to add a new definition, you must create a new file named languagename.plist and fill it with information as per above (it is easiest to copy an a plist file and only change what you need). Then you add a (or open the existing) SyntaxDefinitions.plist file in the /Users/<your home folder>/Library/Application Support/Smultron folder and add a dictionary into the file. The best way to do this is to make a copy of the SyntaxDefinitions.plist that's in the application bundle and start from that one. An example is below:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<array>
<plist version="1.0"><dict>
<key>name</key>
<string>PHP</string>
<key>file</key>
<string>php</string>
<key>extensions</key>
<array>
<string>php php3 phtml phtm</string>
</dict>
</plist>
The name-key is what shows up in the View menu and the file-key is what you name your file minus the .plist extension. The extensions-key lists the various extensions your language can have, space separated and without dots.