A Notepad++ function list for MATLAB
Notepad++ is a free and open source code editor running in MS Windows. It has been around since 2003 and it's still under development. There is a long list of user contributed Plugins and an active community. Compared to the Matlab editor it's fast.
I regard Notepad++ as a useful complement to the editor of Matlab. I use it daily to
- inspect large text files, e.g. data and log files. A few hundred thousand lines is no problem.
- search (and replace) in m-files; refactor code. It supports regular expressions.
- quickly approach an unknown code-base
- and more
Notepad++ supports many languages and it is possible for the user to customize it for more "languages" with
Notepad++ comes with built-in Syntax Highlighting for Matlab, but not Function List. This submission comprises a couple of different Function List definitions for Matlab.
This submission contains xml-code, <parser>-elements, which creates the content displayed in the Function List. There are four files, functionListMatlabNameStrict.xml, functionListMatlabSignatureStrict.xml, functionListMatlabName.xml and functionListMatlabSignature.xml, each of which contains one <parser>-element. The four <parser>-elements differ regarding the output and the requirements on the formatting of the m-code.
- Display of the function name or the full function signature in the function list. The strings, "Name" and "Signature", indicates which file does what.
- Different trade-off between requirements on the formatting of the m-code and the function list result. The existence of the string, "Strict", in the file name indicates that it requires m-files that are formated strictly accourding to "Smart Indent" and with one statment per line. Most examples in the Matlab documentation fullfil these requirements. The absence of the string, "Strict", indicates less strict reguirements on the format of the m-code.
A <parser>-element comprises a bunch regular expressions and Matlab code is challenging to regular expressions. I include both the "Strict" and the "less strict" files, because I've elaborated the two approaches and hope someone might be interested to see them as an exercise with regular expressions. The files are commented.
UDL_matlab2.xml provides syntax highlighting for a language, which I call matlab2. It's used to switch between showing the function name and the full function signature.
Notepad++ provides support for importing user defined languages. Perform the following three steps:
- In Notepad++ menu bar, click Language and select Define your language...
- In User Defined Language windows, click Import then open UDL_matlab2.xml
- Restart Notepad++
<parser>-elements shall be copy&pasted to the file, functionList.xml. The absence or presence of the file, doLocalConf.xml in the installation folder, controlls where Notepad++ looks for functionList.xml. If present, Notepad++ looks in the installation folder. If absent, Notepad++ looks in %APPDATA%\Notepad++ (use the Matlab command, getenv appdata, to find its value). In my installation, different versions of the file existed in the two folders, which caused a bit confusing. A legacy from old updates, I guess.
To install Function List, perform the following steps:
- Make a backup-copy of the file, functionList.xml
- Open the file, functionList.xml
- Copy&paste the content of matlab2_syntax_id.xml to the end of the <associationMap>-element of functionList.xml
- Copy&paste the content of functionListMatlabSignatureStrict.xml to the end of the <parsers>-element of functionList.xml
- Copy&paste the content of functionListMatlabNameStrict.xml to the end of the <parsers>-elements of functionList.xml
- Make sure that the value of id in the two <parser>-elements are matlab_syntax and matlab2_syntax, respectively.
- Save the file, functionList.xml
- Restart Notepad++
To confirm the installation, perform the following steps:
- Start Notepad++
- Open the file, aCompleteClassWithFunctionAndNested.m.
- Display the Function List panel, View,Function List. (It's possible to rearrange the layout by dragging panels, much like in Matlab. However, I sometimes encounter problems. )
- Verify that a function list with the full signature is displayed in the panel.
- Switch to language, matlab2, Language,matlab2. (This setting, which overtakes the extension, is honored until the file is newly opened.
- Reload the Function List panel content by clicking the Reload icon.
- Verify that a function list with names is displayed in the panel.
This file contains two nested function, which show up in the function list as a method and a sub-function, repectively. AFAIK, it isn't possible to show the nested function intended one level. The "less strict" <parser>elements don't show the nested functions. Neither way is perfect.