User Defined Languages
(Added section on external lexers)
|Line 27:||Line 27:|
Revision as of 18:36, 10 May 2009
How To Create User-Defined Languages
This page holds some tips about defining your own language in Notepad++ (originally posted here: https://sourceforge.net/forum/message.php?msg_id=5939037).
- You get the tool for creating your language from View > User Define Dialog.... Be patient, it can take quite a while to load.
- Some of the 'standard' or 'more common' languages are not built with this tool. For example, Batch.
- If you want to modify a language that was not built with the User Define Dialog then you use the Style Configurator (Settings > Styler Configurator...). Note, there are some features in the 'more common' languages you can't modify. For example, you can't add to the list of operators in Batch.
- If you want to replace an 'inbuilt' language such as Batch, do the following.
- Go to Language Menu tab of Settings > Preferences. Disable Batch by moving it to the right hand panel. Now there is no definition for the '.bat' extension.
- Create a new language with User Define Dialog and specify the extension (.bat for batch files)
- User created languages appear on the Language menu, below the divider.
- Once a language has been saved there is no need to save it again. Any changes made on the dialog page are immediately saved. A nice effect of this is that if you have the appropriate file open in NPP, any changes made to the language are immediately reflected in the NPP file window.
- If Prefix mode is checked, then all the words with the prefixes defined will be recognized. For example, with definition "bla", all the following words are recognized: "blapu" "blabla" "blablablabla" "blabc" etc.
"userDefineLang.xml" can be shared with other users so they don't need to do setup for themselves. Place this in your friend's install folder for him to pickup your settings. More detailt on this in Sharing syntax highlighting.
A detailed description of the creation process, complete with illustration, is to be found at http://notepad-plus.sourceforge.net/uk/UserLanguageDefineSystem-HOWTO.php
Some languages have features that the User Defined Language framework does not handle, like mutipart keywords, keywords with non letters inside, escaped quotes, and more. Notepad++ can cause its embedded Scintilla controls to highlight source code in these languages proerly, using external lexers, which are ordinary plugins with some extra functionality.
For generalities on plugin development, see Plugin Development.
There are examples of such lexers around which will probably help you. Search Plugin Development forum for "external lexer", and see what you can fish out. There is also an unofficial (as of April 2009) helper plugin.