NotePad++ Lua Function List (with tables)

This morning was a morning well spent, despite being constantly distracted I managed to roll up my sleeves and do a lua function parser for Notepad++ (rather than wasting my time with actual work). In the process I learned that a) Notepad++ function list doesn’t support lua by default, you have to add them manually, b) the function list looks very pretty and allows not only function but class definitions as well c) regex have lookaheads, lookbacks and K.

I used this StackOverflow question as a starting point, but noticed that the solution that best matched my situation ignores table functions. This was unacceptable because most of my code tends to be structured in classes. After fiddling around with it I got it just about right.

The first thing to do is locate functionList.xml and open it. It may reside in the installation directory or %APPDATA%Notepad++, depending on your installation. Open it and add to <associationMap> the the folloing:

<association langID="23" id="lua_function"/>

The next snipped is added to <parsers>.

<parser id="lua_function" displayName="Lua">
	<function mainExpr="^[t|locals]*functions+[^0-9][_A-Za-z0-9.: ]+s*(" displayMode="$functionName">
		<functionName>
			<nameExpr expr="[.:]?s*K[^0-9][_A-Za-z0-9]+s*("/>
			<nameExpr expr="[^0-9][_A-Za-z0-9]+s*("/>
			<nameExpr expr="[^0-9][_A-Za-z0-9]+"/>
		</functionName>
		<className>
			<nameExpr expr="functions*K[^0-9][_A-Za-z0-9.:]+(?=s*[.:])"/>
		</className>
	</function>
</parser>

This will group together functions defined as <class>.<function> and <class>:<function> (or <class>.<class>./:<function>) and place them in their appropriate classes in the Function List viewer. It will also capture lose global or local functions and display them as normal. It will unfortunately accept illegal constructs and definitions, but you get compile errors for those.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s