User Defined Languages
Notepad++ makes it possible to define "languages", or more precisely highlighting schemes. The original purpose of the feature is to enable proper highlighting of files in a programming language for which an internal Scintilla lexer is not available. Some users have reported they were succesfully using a custom defined language in areas unrelated to programming, like to-do lists. A directory of known User Defined Language Files is being maintained, enabling to share such files across all the user community..
As you can see, the syntax highlighting and the syntax folding are applied on the document userDefineLang.xml (on the left) thanks to the definition in the User Defined Language dialog (on the right).
Please note that:
- When the dialog is undocked, a slider is displayed so as to make its transparency adjustable;
- When displaying the default ("User Define Language") language, the Rename and Remove buttons are not displayed.
Built-in versus User Defined Languages
Some of the 'standard' or 'more common' programming languages are not built with this tool. For example, Batch. And they cannot because they often have very idiosyncratic syntax features which are nearly unique. Making them as something parametrisable like in the User Defined Languages panel seems both unrealistic and unconvenient, as it would lead to an even more complex interface. Parts of the bounds of what can be achieved appear in Limitations Of User Defined Languages.
If you want to modify a language that was not built with the User Define Dialog, then you use 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, nor can you add keyword categories.
Overriding a built-in language
If you want to replace a built-in language such as Batch, do the following.
- Go to Settings -> Preferences -> Language Menu. 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). Obviously, common limitaions of user defined languages will apply to yours.
The Language menu
The Language menu of Notepad++ lists user selected (by default, all) Built-in Languages, as well as any user defined languages found in userDefineLang.xml, plus imported user defined languages and those using external lexers. If there are duplicate entries in userDefineLang.xml, the last one wins.
Using the Settings -> Preferences -> Language Menu tab, you can select which built-in languages will appear on that menu. This is specially handy as the full menu is more than 50 item tall and may not fit on all monitors - you may check the Make language menu compact checkbox above the lists for better results. The languages are presented in the order they are loaded from langs.xml and stylers.xml.
User defined languages are all listed beneath the built-in ones, after a menu separator. They cannot be hidden. To temporarily cause a user defined language not to appear, cut and paste its data from userDefineLang.xml to some text file. The specific procedures that Editing Configuration Files involves apply.
How To Create or Modify User-Defined Languages
You get the tool for creating or changing your language from View -> User Define Dialog.... Be patient, it can take quite a while to load.
Because the dialog is very tall and is not expected to fit on an average monitor, it is recommended to dock it, and then use the vertical scrollbar to access contents which might not be visible. You will need to undock the dialog in order to close it when done. A screen resolution of 1280 x 1024 ensures most parts are visible.
Overview of User Define Language dialog
It consists of 2 parts : global functionalities part and definition part.
The global functionalities are for the global operations:
- Choosing the language.
- Creating a user language. The new name must not exist already.
- Renaming a user language. The new name must not exist already.
- Removing a user define language
- Deciding whether the language is case sensitive
- Declaring the file extensions it will be associated with. If such an extension is already bound to a built-in language, it will be ignored.
The definition part is about:
- Defining the default style, typically used to display identifiers
- Defining the folder symbols for the language.
- Defining the keyword lists for the language
- Defining the comment, string and character delimiters
- Defining operators.
"Defining" involves choosing background and foreground colors, as well as font face, sizee and attributes, much like on the Styler Configurator dialog.
The definition is split across several tabs for convenience. The global part remains visible at all times.
The default language
You can define your keywords, folder block and comment under the default User Define Language.
However, all the definition you made will be temporary under the User Define Language (ie. they will disappear in the next session). If you want to keep you definitions, you have to save it by clicking Save as... button. Once you give it a name and save it, you can use it or modify it afterward.
You can also associate file extensions with your defined language - so every time you open the files with the extension that you associated, the highlighting of your defined language will be applied on the document automatically.
Of course, you can rename your language, use it as a model (Save as...), or remove it.
The tabbed part of the dialog
The main developer of UDL v2 onwards has a nice tutorial on his webste. Here is the link : http://udl20.weebly.com . So why not just go and read his fine manual?
It also appears at the top of the first tab on the UDL dialog, as shown below. The dialog is tall indeed, so at low resolution docking it becomes necessary to ensure usability.