Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Notepad++ "Function List" for Perl

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]*(?&lt;!#)[\s]*sub[\s]+[\w]+[\s]*\(?[^\)\(]*?\)?[\n\s]*\{" displayMode="$className->$functionName">
            <functionName>
                <funcNameExpr expr="(sub[\s]+)?\K[\w]+"/>
            </functionName>
        </function>
    </classRange>
    <!--
    <function mainExpr="^[\s]*(?&lt;!#)[\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.

like image 800
beasy Avatar asked Mar 24 '15 22:03

beasy


2 Answers

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="(?&lt;=^package).*?(?=\npackage|\Z)">
                <className>
                    <nameExpr expr="\s\K[^;]+"/>
                </className>
                <function mainExpr="^[\s]*(?&lt;!#)[\s]*sub[\s]+[\w]+[\s]*\(?[^\)\(]*?\)?[\n\s]*\{">
                    <functionName>
                        <funcNameExpr expr="(sub[\s]+)?\K[\w]+"/>
                    </functionName>
                </function>
            </classRange>
            <function mainExpr="^[\s]*(?&lt;!#)[\s]*sub[\s]+[\w]+[\s]*\(?[^\)\(]*?\)?[\n\s]*\{">
                <functionName>
                    <nameExpr expr="(?:sub[\s]+)?\K[\w]+"/>
                </functionName>
            </function>
        </parser>
like image 186
VinsWorldcom Avatar answered Nov 11 '22 17:11

VinsWorldcom


Most probably, you should use funcNameExpr instead of nameExpr:

Example:

<functionName>
    <funcNameExpr expr="(sub[\s]+)?\K[\w]+"/>
</functionName>
like image 38
Wiktor Stribiżew Avatar answered Nov 11 '22 19:11

Wiktor Stribiżew