I'm trying to get the "Fucntion List" feature on notepad++ (v 6.7.5) working for Perl with classes (or packages, in perl parlance). Only regular subroutines outside of packages are supported by default.
Below is the XML snippet in question from the Function List config file (located on my windows machine at C:\Users\user\AppData\Roaming\Notepad++\functionList.xml ). I added the "classRange" node myself on top of the default "function" node.
EDIT: below is the corrected XML, thanks to user stribizhev
UPDATE: I've commented out the "normal" function section, because it was causing all my methods to appear twice in the function list.
<parser id="perl_function" displayName="Perl">
<classRange mainExpr="^package.*?(?=\npackage|\Z)">
<className>
<nameExpr expr="\s\K[^;]+"/>
</className>
<function mainExpr="^[\s]*(?<!#)[\s]*sub[\s]+[\w]+[\s]*\(?[^\)\(]*?\)?[\n\s]*\{" displayMode="$className->$functionName">
<functionName>
<funcNameExpr expr="(sub[\s]+)?\K[\w]+"/>
</functionName>
</function>
</classRange>
<!--
<function mainExpr="^[\s]*(?<!#)[\s]*sub[\s]+[\w]+[\s]*\(?[^\)\(]*?\)?[\n\s]*\{" displayMode="$className->$functionName">
<functionName>
<nameExpr expr="(sub[\s]+)?\K[\w]+"/>
</functionName>
</function>
-->
</parser>
The documentation for this is here.
I tried your XML in Notepad++ 6.8.1 and while it does work for Perl with 'packages', my plain scripts without packages fail to produce subs now. I uncommented the lines you commented out and it fixes that problem, but does exhibit the behavior you mentioned - doubled up subs within the 'packages'.
I found the following works nicely and even ignores subs in POD (which may be there as example usage) so they aren't added to the list:
<parser id="perl_function" displayName="Perl" commentExpr="(#.*?$|(__END__.*\Z))">
<classRange mainExpr="(?<=^package).*?(?=\npackage|\Z)">
<className>
<nameExpr expr="\s\K[^;]+"/>
</className>
<function mainExpr="^[\s]*(?<!#)[\s]*sub[\s]+[\w]+[\s]*\(?[^\)\(]*?\)?[\n\s]*\{">
<functionName>
<funcNameExpr expr="(sub[\s]+)?\K[\w]+"/>
</functionName>
</function>
</classRange>
<function mainExpr="^[\s]*(?<!#)[\s]*sub[\s]+[\w]+[\s]*\(?[^\)\(]*?\)?[\n\s]*\{">
<functionName>
<nameExpr expr="(?:sub[\s]+)?\K[\w]+"/>
</functionName>
</function>
</parser>
Most probably, you should use funcNameExpr
instead of nameExpr
:
Example:
<functionName>
<funcNameExpr expr="(sub[\s]+)?\K[\w]+"/>
</functionName>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With