Community
    • Login

    Function list

    Scheduled Pinned Locked Moved General Discussion
    9 Posts 3 Posters 3.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Ninon_1977N
      Ninon_1977
      last edited by

      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

      example - Notepad++.png

      <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>

      PeterJonesP 1 Reply Last reply Reply Quote 1
      • PeterJonesP
        PeterJones @Ninon_1977
        last edited by PeterJones

        @Ninon_1977 ,

        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) 
        
        1. literal “Group” followed by one or more space characters
        2. zero or more alphanumeric+underscore, followed by exactly one digit from 0-9
        3. zero or more tabs
        4. one character that is uppercase, lowercase, underscore, or extended-ASCII range
        5. 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):

        182c5fbe-40e7-45ae-b827-f5d4d35ea15f-image.png

        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

        43645be1-5a75-4f6d-b6e4-6404a2b2d6fe-image.png

        Ninon_1977N 1 Reply Last reply Reply Quote 2
        • Ninon_1977N
          Ninon_1977 @PeterJones
          last edited by

          @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

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @Ninon_1977
            last edited by PeterJones

            @Ninon_1977 ,

            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

            Alan KilbornA 1 Reply Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @PeterJones
              last edited by

              @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.

              PeterJonesP 1 Reply Last reply Reply Quote 1
              • PeterJonesP
                PeterJones @Alan Kilborn
                last edited by

                @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).

                Alan KilbornA 1 Reply Last reply Reply Quote 1
                • Alan KilbornA
                  Alan Kilborn @PeterJones
                  last edited by

                  @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.

                  1 Reply Last reply Reply Quote 1
                  • Ninon_1977N
                    Ninon_1977
                    last edited by

                    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

                    Alan KilbornA 1 Reply Last reply Reply Quote 1
                    • Alan KilbornA
                      Alan Kilborn @Ninon_1977
                      last edited by

                      @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.

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors