Function list
-
Dear all,
I’m struggling a bit with the syntax in the function list. Here you can see an example - I would like to see also the text behind the “Group” in the function list.
Does anyone has an idea how I can do that?
I find the explanation regarding the syntax in the function not so well understandable - is there a good one?BR,
Ninon<NotepadPlus>
<functionList>
<!-- ================================ [ Batch / Command Shell Script ] --><parser displayName="Example_sensors" id ="example_sensors" commentExpr="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`) (?m-s:(?i:REM)(?:\h.+)?$) # Single Line Comment 1 | (?m-s::{2}.*$) # Single Line Comment 2 " > <function mainExpr="Group\s+\w*[0-9]\t*[A-Za-z_\x7F-\xFF][\w\x7F-\xFF]*" /> </parser> </functionList>
</NotepadPlus>
-
It’s regular expression “regex” syntax, and the function list docs aren’t going to repeat what’s already elsewhere in the manual.
Looking at your main expression:
Group\s+\w*[0-9]\t*[A-Za-z_\x7F-\xFF][\w\x7F-\xFF]* ^^^^^^^^~~~~~~~~^^^~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^ (1) (2) (3)(4) (5)
- literal “Group” followed by one or more space characters
- zero or more alphanumeric+underscore, followed by exactly one digit from 0-9
- zero or more tabs
- one character that is uppercase, lowercase, underscore, or extended-ASCII range
- zero or more characters that are alphanumeric+underscore or extended-ASCII
With the expression you supplied, I would expect it to work.
And, in fact, when I tried it, it did work (or, at least, mostly):
FILE (with UDL=“Example_sensors” selected)
Group 04 Some Text text 1 text 2 text 3 text 4 text 5
example_sensors.xml:
<?xml version="1.0" encoding="UTF-8" ?> <!-- ==========================================================================\ | | To learn how to make your own language parser, please check the following | link: | https://npp-user-manual.org/docs/function-list/ | \=========================================================================== --> <NotepadPlus> <functionList> <!-- ================================ [ Batch / Command Shell Script ] --> <parser displayName="Batch / Command Shell Script" id ="batch_label" commentExpr="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`) (?m-s:(?i:REM)(?:\h.+)?$) # Single Line Comment 1 | (?m-s::{2}.*$) # Single Line Comment 2 " > <function mainExpr="Group\s+\w*[0-9]\t*[A-Za-z_\x7F-\xFF][\w\x7F-\xFF]*" /> </parser> </functionList> </NotepadPlus>
overrideMap.xml (snippet):
<!-- ==================== User Defined Languages ============================ --> <association id= "example_sensors.xml" userDefinedLangName="Example_sensors"/>
I said “mostly”, because it only grabbed “Some”, not “Some Text”, because “Some Text” has a space in it, and your regex never allowed spaces, so it obviously couldn’t go any farther. If I were doing it, I would simplify it down to
(?-s)Group\h+\w*[0-9]\t*.*
, which will grab everything on that line after the optional tab -
@PeterJones
Hi Peter,
your answer was very helpful - thank you for that!
Just one last question regarding this issue - now I can see this in the function list:
Group 04Some Text
Is there a way to include a space after the number - like this?
Group 04 Some Text
BR,
Ninon -
Is there a way to include a space after the number
As the documentation says, you cannot change/replace characters in the Function List panel; you can just choose which characters from the file match and get displayed.
There is a tab character in your file … and unfortunately, the Function List doesn’t display a tab as you might expect. For that, you might want to file a bug report following the instructions in the FAQ
-
@PeterJones said in Function list:
As the documentation says, you cannot change/replace characters
Specifically, it says so HERE.
the Function List doesn’t display a tab as you might expect
It appears to display nothing for the tab position. Not sure what it should display; probably it should look up the number of spaces for the current “language” of the source file, and insert multiple spaces? It seems a bit ambitious; if it were me, I’d probably accept how it shows currently.
-
@Alan-Kilborn said in Function list:
It seems a bit ambitious; if it were me, I’d probably accept how it shows currently.
Whether or not it’s ambitious probably depends on the current implementation. If the application is just sending the raw text to the treeview widget (or whatever widget is being used in that panel), and the widget itself is just choosing not to display the tab, then there might not be much that the developer can do about it. But if the application is removing tabs before sending the function names to the widget, then instead of removing them, I would suggest just replacing with a single space (which I would think would be just as easy as removing them).
-
@PeterJones said in Function list:
If the application is just sending the raw text to the treeview widget (or whatever widget is being used in that panel), and the widget itself is just choosing not to display the tab…
A quick look at the source code seems to indicate that is the case.
-
Dear Alen and Peter,
thank you for your thoughts!
I changed the input file now - I added whitespaces after the Group number - now the function list looks perfect ;-)Group 04 Some Text
BR,
Ninon -
@Ninon_1977 said in Function list:
I changed the input file now - I added whitespaces after the Group number - now the function list looks perfect
Well, that’s the ultimate situation, when you have control over the data. Much more often, the format is dictated to you.
Had we known that, we’d have advised you to just change your format before even discussing how the tab might be playing in the function list.