Community
    • Login

    Perl language syntax highlighting troubles (bug or limitation ?)

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    112 Posts 6 Posters 44.0k 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.
    • EkopalypseE
      Ekopalypse @Gilles Maisonneuve
      last edited by Ekopalypse

      @Gilles-Maisonneuve

      We’ll see that perhaps next week (or this we if you’re at home) when (if) you have time.

      I assume that I’m online again in about 16-20hours, mostly depends on what
      my BOSS wants me to do in the garden :-D

      Gilles MaisonneuveG 1 Reply Last reply Reply Quote 1
      • Gilles MaisonneuveG
        Gilles Maisonneuve @Ekopalypse
        last edited by

        @Ekopalypse
        Hello, I’m back

        Did the test for Python.

        Got:

        Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)]
        Initialisation took 359ms
        Ready.
        >>> ?
        File "<console>", line 1
        ?
        ^
        SyntaxError: invalid syntax
        >>> notepad.new()
        

        It opened a new window. I changed the language of that window to ‘Perl’ (from 'Normal ‘Text’) but still the qr, qx, … remains in white which is none of Perl defined color for my 'vim dark blue" theme.
        Is the color defined in your Python script ? And if so, where and how ?

        EkopalypseE 1 Reply Last reply Reply Quote 0
        • EkopalypseE
          Ekopalypse @Gilles Maisonneuve
          last edited by

          @Gilles-Maisonneuve

          Having a break right now - currently there is a lot to do at work so can’t really monitor
          the community site.
          First, great it looks like pythonscript has been correctly installed. I assume that notepad.new
          resulted in a new document, hasn’t it?
          When you say you changed the doc to perl and nothing happened, does it mean you
          executed the script afterwards as well or did you choose to use the automatically start?
          Maybe give a short description about how you created the script, like the name and settings you chose and the workflow how it should get started.

          If you haven’t changed anything within the script then those lines define the color

          regexes[(1, 5)] = (r'\bq[rwqx]{0,1}\b([^\h]).*?\1|(\bq[rwqx]{0,1}\b\h+(\w).*?\3)', [0])
          regexes[(2, 5)] = (r'\bq[rwqx]{0,1}\b\h*(\(.+?\)|\[.+?\]|\{.+?\})', [0])
          
          regexes[(3, (130,130,170))] = (r'(?s)((<<)"*(\w+?)"*;.*?\3)', [2])
          regexes[(4, (130,130,170))] = (r'(?s)((<<)\h+"(\w+?)";.*?\3)', [2,3])
          

          The first two, 1 and 2, would use the same color of style id 5 as defined by your used theme.
          The next two, 3 and 4, explicitly define a color of (130,130,170) = rgb values.

          So, at least the heredoc should be painted in a violet/gray color.

          Working for another ~5 hour - so will be online in about ~8 hours again.

          Gilles MaisonneuveG 1 Reply Last reply Reply Quote 1
          • Gilles MaisonneuveG
            Gilles Maisonneuve @Ekopalypse
            last edited by

            @Ekopalypse

            • list itemWhen I said " I changed the language of that window to ‘Perl’ ", I meant I specifically changed the language for that newly created window (the one creatd by python with “notepad.new()”) to Perl syntax and then entered some perl statements (namely qx, qr, qq) and the color was white.

            • then I executed the python script (manually, not in auto, suspecting autorun might not work) on (having the focus on) both Windows : the new one and the one with the previous Perl code I had in screen copy in one of my messages above. In both cases I could not get the color else than white.

            Going to revert my theme to default one and also change the colors by hand in your code (Python) then re-execute everything.
            I’ll let you know.

            Don’t bother too much w/ my pb, concentrate on your job. I don’t want to be a pain in the neck for you just for a small detail. It’s just that I’d like to understand why it works for you and not for me, nasty curiosity.

            Gilles

            Gilles MaisonneuveG 1 Reply Last reply Reply Quote 0
            • Gilles MaisonneuveG
              Gilles Maisonneuve @Gilles Maisonneuve
              last edited by

              PS: did it, correction the color is not white but very light yellow
              I commented out color code in your py script, changed to 0 0 0 RGB, NO CHANGE when I execute the script again (saved, changed thme back to default, left n++, restarted it, executed the py script manually… no change…)

              bit confused.

              EkopalypseE 1 Reply Last reply Reply Quote 1
              • EkopalypseE
                Ekopalypse @Gilles Maisonneuve
                last edited by Ekopalypse

                @Gilles-Maisonneuve

                Don’t bother too much w/ my pb, concentrate on your job

                :-) That’s for sure - we are allowed to surf the web as long as work related stuff is
                priority 1 and we take this very seriously.

                bit confused.

                Actually me too.
                If you don’t mind - would you try to do the following.

                1. Restart npp (Only one single instance should run)
                2. Click Plugins->PythonScript->Show Console
                3. Click Plugins->PythonScript->Scripts->NAME_OF_YOUR_SCRIPT
                  -> check if there is an error reported in the console, if so - stop here and post it
                  If no error has been written to console
                4. Open a perl file or a new file and change the language to PERL and put some code in it
                  -> check if there is an error reported in the console, if so - stop here and post it
                  If no error has been written to console
                  execute the following in the console run edit box
                editor.getLexer()
                

                Does it return 6 as specified in the script (BUILTIN_LEXER_ID = 6)?
                If it does, execute the following in the console run edit box

                EnhanceBuiltinLexer
                

                What does it return?

                1 Reply Last reply Reply Quote 2
                • Gilles MaisonneuveG
                  Gilles Maisonneuve
                  last edited by

                  1. restarted NPP, only one instance: checked

                  2. python console:

                    Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)]
                    Initialisation took 109ms
                    Ready.

                  3. Plugins/PythonScript/Scripts->EnhancePerlLexer.py: checked. Result: NOTHING in the console, no error but no confirmation that the py script as run either, is it normal?

                  4. Opened a new window, made it Perl syntaxing. See screen copy for colors. Did not do it. Here is the code for the colors in your script that I modified:

                    regexes[(1, 5)] = (r’\bq[rwqx]{0,1}\b([^\h]).?\1|(\bq[rwqx]{0,1}\b\h+(\w).?\3)', [0])

                    regexes[(2, 5)] = (r’\bq[rwqx]{0,1}\b\h*((.+?)|[.+?]|{.+?})', [0])

                    own defined color and non-default match group(s) used

                    regexes[(1, (0,0,0))] = (r’\bq[rwqx]{0,1}\b([^\h]).?\1|(\bq[rwqx]{0,1}\b\h+(\w).?\3)‘, [0])
                    regexes[(2, (0,0,0))] = (r’\bq[rwqx]{0,1}\b\h*((.+?)|[.+?]|{.+?})‘, [0])
                    regexes[(3, (0,0,0))] = (r’(?s)((<<)"(\w+?)";.?\3)‘, [2])
                    regexes[(4, (128,128,128))] = (r’(?s)((<<)\h+“(\w+?)”;.
                    ?\3)', [2,3])

                  Executed editor.getLexer(), got a return of 1; executed EnhanceBuiltinLexer, results:

                  Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)]
                  Initialisation took 125ms
                  Ready.
                  >>> editor.getLexer()
                  1
                  >>> EnhanceBuiltinLexer
                  <class '__main__.EnhanceBuiltinLexer'>
                  

                  Seems that I get the wrong return code… don’t I ?

                  EkopalypseE 2 Replies Last reply Reply Quote 2
                  • EkopalypseE
                    Ekopalypse @Gilles Maisonneuve
                    last edited by

                    @Gilles-Maisonneuve

                    Seems that I get the wrong return code… don’t I ?

                    Indeed - would you mind executing the following in the console run edit box?

                    editor.getLexerLanguage()
                    

                    no error but no confirmation that the py script as run either, is it normal?

                    yes.

                    Gilles MaisonneuveG 1 Reply Last reply Reply Quote 2
                    • EkopalypseE
                      Ekopalypse @Gilles Maisonneuve
                      last edited by

                      @Gilles-Maisonneuve

                      I get 1 returned if the language is set to Normal Text.
                      Sorry for asking, but sure you have set the language to Perl?

                      1 Reply Last reply Reply Quote 1
                      • Gilles MaisonneuveG
                        Gilles Maisonneuve @Ekopalypse
                        last edited by Gilles Maisonneuve

                        @Ekopalypse

                        >>> editor.getLexerLanguage()
                        'perl'
                        

                        Would it be (more) convenient for you to connect directly on my machine ? (DWservice) ?

                        EkopalypseE 1 Reply Last reply Reply Quote 0
                        • EkopalypseE
                          Ekopalypse @Gilles Maisonneuve
                          last edited by

                          @Gilles-Maisonneuve

                          Could it be that you have two views open, one with a perl document and one with a normal text document?

                          1 Reply Last reply Reply Quote 0
                          • Gilles MaisonneuveG
                            Gilles Maisonneuve
                            last edited by Gilles Maisonneuve

                            I have many documents opened in different Windows ([edited]TABS). Is this what you mean by “views” ?

                            No double Windows at a time like in “compare” or so.

                            EkopalypseE 1 Reply Last reply Reply Quote 1
                            • EkopalypseE
                              Ekopalypse @Gilles Maisonneuve
                              last edited by

                              @Gilles-Maisonneuve

                              No double Windows at a time like in “compare” or so.

                              Ok, then it seems we have learned that the id is not always the same.
                              Gimme a second to see what needs to be changed to use editor.getLexerLanguage() instead.

                              1 Reply Last reply Reply Quote 2
                              • Gilles MaisonneuveG
                                Gilles Maisonneuve
                                last edited by Gilles Maisonneuve

                                all right, take your time.
                                i’ll be there late tonight.

                                about DWservice, it’s GNU, hosted in DE I guess, not smthg like Teamviewer. But perhaps you are right, one should always be paranoiac.

                                EkopalypseE 1 Reply Last reply Reply Quote 0
                                • EkopalypseE
                                  Ekopalypse @Gilles Maisonneuve
                                  last edited by

                                  @Gilles-Maisonneuve

                                  I’m living in DE but have to admit, that I haven’t heard of DWservice before, shame on me :-)

                                  Changes
                                  line 9 to BUILTIN_LEXER = 'perl'
                                  line 111 self.lexer_name = BUILTIN_LEXER.lower()
                                  line 219 to self.doc_is_of_interest = True if editor.getLexerLanguage().lower() == self.lexer_name else False

                                  As python is very picky about whitespaces make sure that you either use
                                  spaces or tabs for indentation only. Best python practice is to set
                                  Settings->Preferences->Language->TabSettings->Python
                                  Tab size = 4 and check replace by space checkbox
                                  (if this isn’t your default setting, of course)

                                  Gilles MaisonneuveG 1 Reply Last reply Reply Quote 2
                                  • Gilles MaisonneuveG
                                    Gilles Maisonneuve @Ekopalypse
                                    last edited by Gilles Maisonneuve

                                    @Ekopalypse

                                    Oops, I must have made some mistakes but can’t find where… Here is the console log:

                                    Traceback (most recent call last):
                                      File "C:\Users\gm\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\startup.py", line 1, in <module>
                                        import EnhancePerlLexer
                                      File "C:\Users\gm\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\EnhancePerlLexer.py", line 283, in <module>
                                        EnhanceBuiltinLexer().main()
                                      File "C:\Users\gm\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\EnhancePerlLexer.py", line 280, in main
                                        self.on_bufferactivated(None)
                                      File "C:\Users\gm\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\EnhancePerlLexer.py", line 237, in on_bufferactivated
                                        self.check_lexer()
                                      File "C:\Users\gm\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\EnhancePerlLexer.py", line 224, in check_lexer
                                        self.doc_is_of_interest = True if editor.getLexerLanguage().lower() == self.lexer_name else False
                                    AttributeError: 'EnhanceBuiltinLexer' object has no attribute 'lexer_name'
                                    Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)]
                                    Initialisation took 343ms
                                    Ready.
                                    
                                    Traceback (most recent call last):
                                      File "C:\Users\gm\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\EnhancePerlLexer.py", line 73, in <module>
                                        EnhanceBuiltinLexer().main()
                                      File "C:\Users\gm\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\EnhancePerlLexer.py", line 280, in main
                                        self.on_bufferactivated(None)
                                      File "C:\Users\gm\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\EnhancePerlLexer.py", line 237, in on_bufferactivated
                                        self.check_lexer()
                                      File "C:\Users\gm\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\EnhancePerlLexer.py", line 224, in check_lexer
                                        self.doc_is_of_interest = True if editor.getLexerLanguage().lower() == self.lexer_name else False
                                    AttributeError: 'EnhanceBuiltinLexer' object has no attribute 'lexer_name'
                                    

                                    Line numbers don’t match because I already commented out some of your lines but kept them in the file, and duplicated them with my own changes. But I did do the changes at the places you told me to do them.

                                    EkopalypseE 1 Reply Last reply Reply Quote 1
                                    • EkopalypseE
                                      Ekopalypse @Gilles Maisonneuve
                                      last edited by

                                      @Gilles-Maisonneuve

                                      check line 111 - it defines the lexer_name

                                      Gilles MaisonneuveG 1 Reply Last reply Reply Quote 2
                                      • Gilles MaisonneuveG
                                        Gilles Maisonneuve
                                        last edited by

                                        OOPS, yours :== self.lexer_name, mine :== self_lexer_name, I am really a dumb when dealing with OO programming, can’t realize that ‘self’ is the current object and of course separated by a dot.

                                        Colour has changed for q* keywords and there text (black on dark blue, can’t read but now just need to ajust the colors).
                                        No change for here docs, but don’t know if I properly set the colors, have to check.

                                        Send you a screen copy in a few minutes.

                                        1 Reply Last reply Reply Quote 2
                                        • Gilles MaisonneuveG
                                          Gilles Maisonneuve @Ekopalypse
                                          last edited by Gilles Maisonneuve

                                          @Ekopalypse

                                          All right, nearly done: with the following regexp in your python code:

                                          regexes[(1, (255,0,128))] = (r'\bq[rwqx]{0,1}\b([^\h]).*?\1|(\bq[rwqx]{0,1}\b\h+(\w).*?\3)', [0])
                                          regexes[(2, (255,0,128))] = (r'\bq[rwqx]{0,1}\b\h*(\(.+?\)|\[.+?\]|\{.+?\})', [0])
                                          regexes[(3, (0,0,0))] = (r'(?s)((<<)"*(\w+?)"*;.*?\3)', [2])
                                          regexes[(4, (0,0,0))] = (r'(?s)((<<)\h+"(\w+?)";.*?\3)', [2,3])
                                          

                                          I get the following colors:

                                          q* colors OK, here docs no

                                          Q* colors are good {well I might have an uggly taste in colors but at least they match ;-)) }

                                          Would you have any clue about why the here docs= are still not handled properly ? They should be black, I think.

                                          EkopalypseE 1 Reply Last reply Reply Quote 2
                                          • EkopalypseE
                                            Ekopalypse @Gilles Maisonneuve
                                            last edited by

                                            @Gilles-Maisonneuve

                                            the regexes assumes double quotes and semicolon directly attached to EOT.
                                            Like

                                            print << "EOT";
                                            
                                            --------------------- separation line ------------------
                                            
                                            EOT
                                            

                                            Is there a rule how this is specified?

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