Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Notepad++ Perl Function List with "Classes"

by VinsWorldcom (Parson)
on Aug 24, 2015 at 16:50 UTC ( #1139708=perlmeditation: print w/replies, xml ) Need Help??

Windows Monks,

As follow-on to my previous meditation regarding Notepad++ Integrated Perl Debugging, I've been doing other things with Notepad++ to make it more friendly when I write Perl (of which I've been doing more than usual lately).

One thing I did was to get Python debugging working the same way as with Perl. In case you're interested, see here:

This got me thinking as I looked in the "Function List" window at Python code: +[Class]h_main __init__ +[Class]h_base toXML convert main

Why does the "Function List" window show Python classes, but not Perl by default? Of course by Perl class, I mean 'package <name>'. All I would see was a list of subs. Take the following example program:

#!perl use strict; use warnings; package MyPkg; sub one { 1; } sub two { 1; } 1; package main; my $p = pre(); print $p . MyPkg->one; sub pre { return "ONE = "; }

The Notepad++ Function List is: one two pre

But there are clearly "classes" (read: packages) under which I'd like my subs grouped. Thankfully, Notepad++ allows customization of a file in the Notepad++ top level directory called 'functionList.xml' (documentation: A quick web search turned up a partial solution and with some more tweaking I finally got it to display: +[Class]MyPkg one two +[Class]main pre

If there are no "packages", then the original display of just filename with the subs is what is displayed. I even tweaked it a bit to ignore stuff after __END__, so any "sub name" that appears in POD won't be mistakenly added to the Function List. I've tested it by viewing a few of my scripts, some modules and a few "custom" codes to demonstrate different use cases. So far, so good.

The solution; save a copy of your existing 'functionList.xml' to something like 'functionList.xml.ORIG' (just in case you want to revert back), open the existing 'functionList.xml' file, find the Perl parser lines:

<parser id="perl_function" displayName="Perl" ... ... </parser>

and replace the whole lot with:

<parser id="perl_function" displayName="Perl" commentExpr="(#.*?$|(__E +ND__.*\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>

Replies are listed 'Best First'.
Re: Notepad++ Perl Function List with "Classes"
by johnniestang (Initiate) on Jul 12, 2017 at 16:41 UTC

    I had to change the following line to get it to work with non-package, non-parentheses defined subroutines

    <function mainExpr="^[\s]*(?&lt;!#)[\s]*sub[\s]+[\w]+[\s]*\(?[^\)\(] +*?\)?[\n\s]*\{">

    changed to:

    <function mainExpr="^[\s]*(?&lt;!#)[\s]*sub[\s]+[\w]+[\n\s]*\{">

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1139708]
Approved by planetscape
Front-paged by ww
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2019-03-20 15:09 GMT
Find Nodes?
    Voting Booth?
    How do you Carpe diem?

    Results (101 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!