• Login
Community
  • Login

Keyword prefix constraint possible ?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
11 Posts 3 Posters 518 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.
  • K
    Klasen Eric
    last edited by Klasen Eric May 6, 2020, 11:00 PM May 6, 2020, 10:58 PM

    Hi all !

    I use N++ for … well … decades ;) . I already defined langages by myself, but this time I’m stuck :
    In GCode, there are commands like G1, G01, M117, G92.1 and so on. Basically speaking, it’s one letter followed by several digits (numbers or dot only, no letters or whatever).
    When I put a letter in the keywords tab (let’s say G for G01…) and check the “prefix” checkbox, it works for G01 and G92.1 which is perfect, but also for Gfoo and Gbar which is not what I want. Is there a way to constrain what can follow the keyword ?
    I tried using the “Number” formating, but I want to have different colors depending on the letter, which is not possible with number which are just … well … numbers ;-)

    Do I have to write a full plugin to do so ?

    I hope I’m clear in my question…

    P 1 Reply Last reply May 6, 2020, 11:32 PM Reply Quote 0
    • P
      PeterJones @Klasen Eric
      last edited by May 6, 2020, 11:32 PM

      @Klasen-Eric said in Keyword prefix constraint possible ?:

      Is there a way to constrain what can follow the keyword ?

      UDL does not inherently have that ability.

      However, if you are willing to install the PythonScript plugin, then you can add extra highlighting to a UDL language using regexes via the script EnhanceUDLLexer.py that @Ekopalypse shares in this linked post – so with multiple regexes, you could color G\d+ green, M\d+ magenta, and so on (color choices are up to you; I based them on the letter of the alphabet).

      K 2 Replies Last reply May 7, 2020, 1:00 AM Reply Quote 1
      • K
        Klasen Eric
        last edited by May 6, 2020, 11:35 PM

        Sounds good ! :D

        I’ll give it a try right now (well, not sure to be efficient, it’s 1:35am here ;) ).

        1 Reply Last reply Reply Quote 0
        • K
          Klasen Eric @PeterJones
          last edited by Klasen Eric May 7, 2020, 1:00 AM May 7, 2020, 1:00 AM

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • K
            Klasen Eric @PeterJones
            last edited by May 7, 2020, 1:10 AM

            @PeterJones I installed pythonscript, edited the enhance UDL lexer script, but it don’t seem to work… I go to [Plugins] > [Python Script] > [Scripts] > “My Script”

            “My Script” is the modified (copy & paste + update of regex) of the one of your link.

            I tried placing it in the “user” folder (with the new script menu) and by hand in the scripts folder. Both case does not work…

            But nothing happens. I’m sure I’m missing something…

            P 1 Reply Last reply May 7, 2020, 2:01 AM Reply Quote 0
            • P
              PeterJones @Klasen Eric
              last edited by PeterJones May 7, 2020, 2:01 AM May 7, 2020, 2:01 AM

              @Klasen-Eric ,

              Please go to Plugins > PythonScript and open the Console window after running it: there is likely an error message, which you can share with us

              K 1 Reply Last reply May 7, 2020, 2:08 AM Reply Quote 0
              • K
                Klasen Eric @PeterJones
                last edited by Klasen Eric May 7, 2020, 2:10 AM May 7, 2020, 2:08 AM

                @PeterJones Nothing in the console… I tried opening it before running the script or after running it (with restart of N++ ). Nothing…
                Full content of console :

                Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:22:17) [MSC v.1500 32 bit (Intel)]
                Initialisation took 32ms
                Ready.
                

                I also modified my code to print something at the beginning, and it works (displays my “Hello World” ;) )

                P 1 Reply Last reply May 7, 2020, 2:17 AM Reply Quote 0
                • P
                  PeterJones @Klasen Eric
                  last edited by May 7, 2020, 2:17 AM

                  @Klasen-Eric ,

                  Did you put the name of your UDL in the appropriate spot? Is that UDL active on the active file?

                  K 2 Replies Last reply May 7, 2020, 2:19 AM Reply Quote 0
                  • K
                    Klasen Eric @PeterJones
                    last edited by May 7, 2020, 2:19 AM

                    @PeterJones I think so. My UDL is just called “gcode”. Quite simple to handle… but I’ll check again… a typo is never too far ;-)

                    And yes, this UDL is active on my file (when I change values in its configuration window, colors changes in the file.

                    1 Reply Last reply Reply Quote 0
                    • K
                      Klasen Eric @PeterJones
                      last edited by May 7, 2020, 2:22 AM

                      @PeterJones

                      I’ve put some print at the beginning of each method of the code. But even the one at the beginning of the “main” method is not printed. The print at the beginning of the file (just after regex configuration) is still ok.

                      E 1 Reply Last reply May 7, 2020, 12:06 PM Reply Quote 0
                      • E
                        Ekopalypse @Klasen Eric
                        last edited by Ekopalypse May 7, 2020, 12:07 PM May 7, 2020, 12:06 PM

                        @Klasen-Eric

                        So my understanding is, that you run it once, right?
                        And after executing you got your main print statement in the console, correct?
                        After that, you need to activate the buffer aka clicking into it or switching
                        from another document into the one which should be handled and then
                        it should start coloring your regex matches.
                        Did you ensure that the match group is 0? Only if you used G\d+.
                        If you used something like
                        G0(\d+) and you are interested to get the digit colored which follow G0
                        you would need to use match group 1.
                        So for example this

                        regexes[(0, (79, 175, 239))] = (r'G\d+', 1)'
                        

                        would be an error as no match group 1 gets created

                        either use this

                        regexes[(0, (79, 175, 239))] = (r'G\d+', 0)'
                        

                        or that (which really doesn’t make sense in this case but …

                        regexes[(0, (79, 175, 239))] = (r'(G\d+)', 1)'
                        
                        1 Reply Last reply Reply Quote 2
                        1 out of 11
                        • First post
                          1/11
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors