How to use Notepad++ with Editor 2

Editor 2 has a lot of great features but customizability is so far not one of them (I’m looking at you, autocomplete) and there are some other missing things like a function/code outline window that are particularly useful for larger projects. If you’re on Windows then Notepad++ can be configured to provide these features.

1. Folder as workspace (solution explorer)
In Notepad++ go to View -> Folder as workspace then right-click in the window and Add your Defold project directory. Now you can view and navigate between all your files.

2. File extensions (syntax highlighting)
By default Notepad++ doesn’t know what language Defold’s .script, .render_script and .gui_script files are so there is no syntax highlighting. Find the Notepad++ configuration XML files, mine were in C:\Users\Connor\AppData\Roaming\Notepad++ and open the langs.xml file. Replace this line:
<Language commentLine="--" ext="lua" name="lua">
with
<Language commentLine="--" ext="lua script render_script gui_script" name="lua">
The ext="..." bit is a space-separated list of file extensions to recognise as Lua and we’ve just added Defold’s .script, .render_script and .gui_script. If you restart Notepad++ then open a .script file through the workspace window it should now have correct Lua syntax highlighting. You will have to close and reopen any already open files.

3. Language definition (function list / code outline)
Go to View -> Function list to open a window that will show all functions for the currently open file and can be double clicked to navigate between them. However, by default Notepad++ doesn’t have a definition of what constitutes a Lua function so cannot list them here. Alongside the langs.xml file from point 2 should be functionList.xml - this is the file that defines what a function looks like in each language and we’re going to add a definition for Lua.

In the language association map at the top add the following line:
<association langID="23" id="lua_function"/>

Then somewhere in the list of parser functions add the following, taken from here. Again you’ll have to restart Notepad++ and close and reopen any already open files.

<!-- Basic lua parser for functionList.xml in Notepad++ 6.5.3 -->
<!-- See http://notepad-plus-plus.org/features/function-list.html -->
<parser id="lua_function" displayName="Lua" commentExpr="--.*?$">
    <!-- Basic lua table view, nested lua table not supported -->
    <classRange
        mainExpr="[.\w]+[\s]*=[\s]*\{"
        openSymbole="\{"
        closeSymbole="\}"
        displayMode="node">
        <className>
            <nameExpr expr="[.\w]+"/>
        </className>
        <function
            mainExpr="[.\w]+[\s]*=[\s]*['&quot;]?[\w]+['&quot;]?">
            <functionName>
                <funcNameExpr expr=".*"/>
            </functionName>
        </function>
    </classRange>
    <!-- Basic lua functions support -->
    <function 
        mainExpr="(function[\s]+[.\w]+(:[\w]+)?)|([.\w]+[\s]*=[\s]*function)"
        displayMode="$className->$functionName">
        <functionName>
            <nameExpr expr="((?<=function)[\s]+[.:\w]+)|(([.\w]+)(?=([\s]*=[\s]*function)))"/>
        </functionName>
        <className>
            <nameExpr expr="[.\w]+(?=:)"/>
        </className>
    </function>
</parser>

4. Default code editor (not recommended)
If you want to you can configure Defold to automatically open script files in Notepad++ but I wouldn’t recommend it as you want to open scripts in Defold while using the debugger, plus opening files in Notepad++ can be done through the workspace explorer we setup in point 1. If you want to, in Defold go to File -> Preferences -> Code and set the Custom Editor to point at the Notepad++ executable, mine was at D:\Program Files\Notepad++\notepad++.exe

9 Likes