beasy
beasy

Reputation: 1227

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.

Upvotes: 7

Views: 1871

Answers (3)

uldics
uldics

Reputation: 134

funcNameExpr or uncomment did not work for me. What worked - commenting out the three regex lines with parentheses:

#\(
#[^()]*
#\)

As Perl does not consider parentheses after function name correct, I do not have such. Parentheses can be at each call of the function, but not where the function is.

Upvotes: 1

VinsWorldcom
VinsWorldcom

Reputation: 81

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>

Upvotes: 5

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627082

Most probably, you should use funcNameExpr instead of nameExpr:

Example:

<functionName>
    <funcNameExpr expr="(sub[\s]+)?\K[\w]+"/>
</functionName>

Upvotes: 3

Related Questions