Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Notepad++ Perl Function List with "Classes"

by VinsWorldcom (Prior)
on Aug 24, 2015 at 16:50 UTC ( [id://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: http://vinsworldcom.blogspot.com/2015/08/notepad-dbgp-and-python.html.

This got me thinking as I looked in the "Function List" window at Python code:

file.py +[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:

file.pl 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: https://notepad-plus-plus.org/features/function-list.html). A quick web search turned up a partial solution and with some more tweaking I finally got it to display:

file.pl +[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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-19 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found