• Login
Community
  • Login

UDL: Suffix Mode

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
54 Posts 8 Posters 17.2k 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.
  • M
    Michael Miller31
    last edited by Feb 14, 2019, 5:59 PM

    I will get you a recipe when I get home from work. :-)

    The macbooks will take some time. :-D

    E 1 Reply Last reply Feb 15, 2019, 10:54 PM Reply Quote 2
    • M
      Michael Miller31
      last edited by Feb 14, 2019, 11:40 PM

      https://imgur.com/a/GWRaqec @Eko-palypse here’s my favorite recipe for muffins. :-D

      Thanks again for your help.

      I also realized afterwards that there are a few internal functions that end with $ and don’t start with fn but I just modified the regex to take care of them.

      E A 2 Replies Last reply Feb 14, 2019, 11:43 PM Reply Quote 4
      • E
        Eko palypse @Michael Miller31
        last edited by Feb 14, 2019, 11:43 PM

        @Michael-Miller31

        thank you thank you very much - very much appreciated - I LOVE MUFFINS (who doesn’t ?)
        And also nice to see that you already made the script do what you want.
        Have a nice day.

        1 Reply Last reply Reply Quote 1
        • A
          Alan Kilborn @Michael Miller31
          last edited by Feb 15, 2019, 12:21 AM

          @Michael-Miller31

          Much better to have an actual recipe than simply all the talk of “baking cookies” that goes on around here sometimes!

          1 Reply Last reply Reply Quote 3
          • E
            Eko palypse
            last edited by Feb 15, 2019, 12:23 AM

            Help, I need somebody help I need somebody heeeelllppp :-D

            M 1 Reply Last reply Feb 15, 2019, 2:16 PM Reply Quote 1
            • M
              Meta Chuh moderator @Eko palypse
              last edited by Feb 15, 2019, 2:16 PM

              @Eko-palypse

              yesterday … all my troubles seemed so far away :-D

              1 Reply Last reply Reply Quote 1
              • A
                Alan Kilborn
                last edited by Feb 15, 2019, 2:17 PM

                I see the Beatles song lyrics references, but I’m unsure why Eko started it??

                E 1 Reply Last reply Feb 15, 2019, 10:58 PM Reply Quote 0
                • E
                  Eko palypse @Michael Miller31
                  last edited by Eko palypse Feb 15, 2019, 10:55 PM Feb 15, 2019, 10:54 PM

                  @Michael-Miller31

                  I found a little bug in the script.
                  The area which needs to be styled is wrongly calculated if there are folded parts within this area.
                  Please replace, within the style function, this line
                  end_line = start_line + editor.linesOnScreen()
                  with that line
                  end_line = editor.docLineFromVisible(start_line + editor.linesOnScreen())

                  1 Reply Last reply Reply Quote 3
                  • E
                    Eko palypse @Alan Kilborn
                    last edited by Feb 15, 2019, 10:58 PM

                    @Alan-Kilborn said:

                    I see the Beatles song lyrics references, but I’m unsure why Eko started it??

                    because this was the first thing which came into my mind after reading your comment about Scott-Sumner’s baking cookie comments :-D

                    1 Reply Last reply Reply Quote 1
                    • G
                      guy038
                      last edited by guy038 Feb 16, 2019, 11:11 PM Feb 16, 2019, 11:09 PM

                      Hello, @michael-miller31, @eko-palypse, @alan-kilborn, @meta-chuh and All,

                      Eko, I’ve just tried your python script and it works fine :-))

                      I was a bit intrigued by your regex and I wanted to test other syntaxes. But after a while, I understood that your just take care of group 1 and dismiss the solution fn[A-Za-z0-9_]+?\$ Don’t you ?

                      I tested this other solution (\b(?!fn)\w+\$), with success ! Of course, we could get rid of the group 1 but I suppose that your script should be slightly modified !


                      Secondly, I tried to build, from the michael’s picture and text, an equivalent UDL, what I named… EKO and after some tests I was surprised because, although I just missed to update the UDL name, in your script, as below :

                                  self.lexer_name = 'User Defined language file - EKO'
                      

                      Seemingly, it does not care about it ?! ( Just a comment : my BR Basic test file has no extension and I didn’t associate the EKO UDL to a specific extension )

                      Cheers,

                      guy038

                      E 1 Reply Last reply Feb 16, 2019, 11:14 PM Reply Quote 3
                      • E
                        Eko palypse @guy038
                        last edited by Eko palypse Feb 16, 2019, 11:15 PM Feb 16, 2019, 11:14 PM

                        @guy038

                        thanks for testing and sharing an alternative regex.
                        Concerning the script, if you just run the script it will flag the current
                        document being of interest.
                        If you would open multiple UDL documents and switch between them,
                        then you should see that those documents work only if the UDL name
                        is the one configured in the script.

                        1 Reply Last reply Reply Quote 1
                        • A
                          Alexander Seidel
                          last edited by Oct 8, 2019, 3:19 PM

                          Thanks for this great piece of code, Eko, I had a very similar problem, and simply changed the symbol and the color in the relevant line to fit my case.

                          I was just wondering if you could help me with two additions, if it isn’t too much work to integrate:

                          1. I have some cases where I don’t just want to change the color of the text, but also change the text from italic to non italic:
                            int( —> int(
                            Is this possible?

                          2. In an ideal case, I would like comment lines to be excluded from this. In my case every line that start with, or contains # would have to be ignored by the python script.

                          Thanks in advance, and have a nice day :)

                          E 2 Replies Last reply Oct 8, 2019, 3:34 PM Reply Quote 0
                          • E
                            Ekopalypse @Alexander Seidel
                            last edited by Oct 8, 2019, 3:34 PM

                            @Alexander-Seidel

                            I will follow up on this later today from at home as I’m finished with work today. YEAH :-D

                            1 Reply Last reply Reply Quote 0
                            • E
                              Ekopalypse @Alexander Seidel
                              last edited by Oct 8, 2019, 7:31 PM

                              @Alexander-Seidel

                              Hi Alexander, concerning number 2 I would add

                              self.excluded_styles = [1, 2]  # SCE_USER_STYLE_COMMENT=1  SCE_USER_STYLE_COMMENTLINE=2
                              

                              to the init function like

                                      def __init__(self):
                                          editor.callbackSync(self.on_updateui, [SCINTILLANOTIFICATION.UPDATEUI])
                                          notepad.callback(self.on_langchanged, [NOTIFICATION.LANGCHANGED])
                                          notepad.callback(self.on_bufferactivated, [NOTIFICATION.BUFFERACTIVATED])
                                          self.excluded_styles = [1, 2]  # SCE_USER_STYLE_COMMENT=1  SCE_USER_STYLE_COMMENTLINE=2
                                          self.__is_lexer_doc = False
                                          self.lexer_name = None
                                          self.npp_hwnd = user32.FindWindowW(u'Notepad++', None)
                                          self.configure()
                              

                              and modify the if clause line in paint_it function to

                              if (pos >= 0) and (editor.getStyleAt(pos) not in self.excluded_styles):
                              

                              that would skip painting if the matched position is in a comment line or block

                              Regarding the first point, no, unfortunately scintilla doesn’t allow to modify
                              the font attributes via an indicator other than the foreground color.
                              But I’m confused why it is italic at all, in UDL you must have it set explicitly, didn’t you?

                              1 Reply Last reply Reply Quote 0
                              • A
                                Alexander Seidel
                                last edited by Alexander Seidel Oct 9, 2019, 8:53 AM Oct 9, 2019, 8:51 AM

                                Thanks for the quick work, Eko!
                                Sadly, the code doesn’t work :(

                                Now, I checked the conditional function, and noticed that getStyleAt returns 0 if the pos is out of bounds, but weirdly, when I use this line:

                                if (pos >= 0) and (editor.getStyleAt(pos) == 0):
                                

                                the code works and does so just as I intended. Comment lines are not changed, but normal lines are.

                                d6e787c3-dde6-403d-892e-79fbdb564fdb-image.png

                                I really don’t get why it does, because I expected it to only return 0 in case of an error, and not for normal lines in the text, but apparently that’s how it works.

                                Concerning the italic: Yes, I set a lot of variably type names like int and double to italic, but the language I’m programming in also has int(“4”) and string(4) as functions at the same time.

                                E 2 Replies Last reply Oct 9, 2019, 11:54 AM Reply Quote 0
                                • E
                                  Ekopalypse @Alexander Seidel
                                  last edited by Ekopalypse Oct 9, 2019, 11:57 AM Oct 9, 2019, 11:54 AM

                                  @Alexander-Seidel

                                  sorry, Hochmut kommt vor dem Fall, I didn’t test it otherwise I would have
                                  seen that paint_it is a staticmethod and as such it has no access to self object.

                                  Remove the @staticmethod decorator and add self to be the first parameter
                                  to paint_it like this

                                  
                                          def paint_it(self, color, pos, length):
                                              if (pos >= 0) and (editor.getStyleAt(pos) not in self.excluded_styles):
                                                  editor.setIndicatorCurrent(0)
                                                  editor.setIndicatorValue(color)
                                                  editor.indicatorFillRange(pos, length)
                                  

                                  If you open the console window while having the old version running,
                                  you should see that it throws an error - so it didn’t do anything at all.

                                  getStyleAt returns the style id and you compare with style 0, so it works as long as the part to be colored is currently colored with the style 0.

                                  Which means, your code is good as well if you are only interested
                                  in modifying parts of code which are used by style 0.

                                  1 Reply Last reply Reply Quote 1
                                  • E
                                    Ekopalypse @Alexander Seidel
                                    last edited by Oct 9, 2019, 12:11 PM

                                    @Alexander-Seidel

                                    regarding the italic issue, what about using a delimiter with
                                    open int( and closing ) and setting it color to the default color?

                                    1 Reply Last reply Reply Quote 0
                                    • A
                                      Alexander Seidel
                                      last edited by Oct 9, 2019, 12:25 PM

                                      @Ekopalypse said in UDL: Suffix Mode:

                                      If

                                      I just used this line now:
                                      if pos >= 0 and (editor.getStyleAt(pos) not in [1, 2]):

                                      and nice tip for the italics! That worked perfectly. I first tried to just make a keyword int(, but that didn’t work.

                                      E 1 Reply Last reply Oct 9, 2019, 12:27 PM Reply Quote 2
                                      • E
                                        Ekopalypse @Alexander Seidel
                                        last edited by Oct 9, 2019, 12:27 PM

                                        @Alexander-Seidel

                                        or like this yes :-) Many roads to Rome I guess :-D

                                        1 Reply Last reply Reply Quote 0
                                        • bruhB
                                          bruh
                                          last edited by Jan 1, 2021, 11:39 PM

                                          self.regexes[(0, self.rgb(79, 175, 239) | SC_INDICVALUEBIT)] = (r’fn[A-Za-z0-9_]+?$|([A-Za-z0-9_]+?$)', 1)

                                          Will adding ^\w+.(gif|png|jpg|jpeg)$ instead of r’fn[A-Za-z0-9_]+?$|([A-Za-z0-9_]+?$)’ make it work on .gif .png .jpg and .jpeg suffixes?

                                          E 1 Reply Last reply Jan 1, 2021, 11:44 PM Reply Quote 1
                                          • First post
                                            Last post
                                          The Community of users of the Notepad++ text editor.
                                          Powered by NodeBB | Contributors