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="(?<=^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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Notepad++ Perl Function List with "Classes"
by johnniestang (Initiate) on Jul 12, 2017 at 16:41 UTC | |
by Anonymous Monk on Jul 12, 2017 at 21:22 UTC |