Community
    • Login

    Marker number

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    19 Posts 3 Posters 1.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.
    • Paul WormerP
      Paul Wormer
      last edited by Paul Wormer

      The following code, which sets MARKERSYMBOL.CIRCLEPLUS
      in margin 4, gives a result that is dependent on markerNr.

      # -*- coding: utf-8 -*-
      from __future__ import print_function # Python 2.7
      from Npp import *
      
      line = 6    
      markerNr  = 25   
      marginNr  = 4 
      editor.markerDefine(markerNr, MARKERSYMBOL.CIRCLEPLUS)  
      nSymbol =  editor.markerSymbolDefined(markerNr)    
      editor.setMarginWidthN(marginNr, 16)               
      editor.setMarginTypeN(marginNr,  MARGINTYPE.SYMBOL)
      editor.setMarginMaskN(marginNr, 1<<markerNr )      
      editor.markerAdd(line-1,markerNr)     
      

      A few examples:

      MarkerNr = 6:
      markerNr6.png

      MarkerNr = 17:
      markerNr17.png

      MarkerNr = 25:
      markerNr25.png

      Is this a feature or a bug? If it is the former, could somebody in the audience explain its workings?

      PS On my screen at home and in the preview the sizes of the examples are reasonable, after submit they become horrendous. Sorry about that!

      Michael VincentM Alan KilbornA 2 Replies Last reply Reply Quote 0
      • Michael VincentM
        Michael Vincent @Paul Wormer
        last edited by Michael Vincent

        @Paul-Wormer said in Marker number:

        Is this a feature or a bug?

        Neither - you’re stepping on markers already assigned.

        You need to pick a marker number that is not used by something else and thus already has it’s mask applied to a margin. 6 was indeed a good choice. 17 is bad since Notepad++ already uses that for MARK_HIDELINESUNDERLINE:

        https://github.com/notepad-plus-plus/notepad-plus-plus/blob/11f7ba2e0a80dae890c5162a92635d6c6151af64/PowerEditor/src/ScintillaComponent/ScintillaEditView.h#L116-L119

        25 is another bad choice since Scintilla uses that for folding margins .

        Stick to the low numbered markers, like under 10 should be OK, but don’t be surprised of some wonkiness there too if a plugin you are using has already claimed one. Unfortunately there is no interface to see what markers are already assigned.

        Cheers.

        Paul WormerP 1 Reply Last reply Reply Quote 2
        • Alan KilbornA
          Alan Kilborn @Paul Wormer
          last edited by

          @Paul-Wormer said in Marker number:

          On my screen at home and in the preview the sizes of the examples are reasonable, after submit they become horrendous

          I don’t know that they are all that horrendously large this time. So, it’s OK.

          1 Reply Last reply Reply Quote 0
          • Paul WormerP
            Paul Wormer @Michael Vincent
            last edited by

            @Michael-Vincent Thank you. I suspected something like that. Because the Scintilla manual says that 0 to 20 are free, I had some doubts. It is indeed a pity that the marker numbers cannot be inspected.

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

              @Paul-Wormer said in Marker number:

              Because the Scintilla manual says that 0 to 20 are free

              They are free from Scintilla’s perspective.
              Notepad++, as a user of Scintilla, is allowed to use the free ones as it sees fit.
              You, as a user, have to avoid markers used by both Scintilla and Notepad++.
              (pretty sure this is obvious by now)

              a pity that the marker numbers cannot be inspected

              The N++ “bookmark” marker ID can be retrieved, see HERE (and also HERE), but that is of limited usefulness because it only gives you one ID value that is tied up.

              But yes, there should be a “cough up a free marker ID, and then don’t give that same marker ID to anyone else that asks for a free one” plugin message/function.

              Then plugins that play nice would use that interface when they need markers for their use. This includes the PythonScript plugin. Although PS has no use for markers on its own, such a function would be made available to scripters (like you) in order to obtain a unique marker ID.

              Paul WormerP 1 Reply Last reply Reply Quote 2
              • Paul WormerP
                Paul Wormer @Alan Kilborn
                last edited by Paul Wormer

                @Alan-Kilborn Yes, I understand that is obvious to me now. I’m groping my way into the Notepad++/Scintilla jungle and start getting a feel for its philosophy.

                BTW, how about your promise of a few day ago?

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

                  there should be a “cough up a free marker ID, and then don’t give that same marker ID to anyone else that asks for a free one” plugin message/function.

                  Oh wait, it appears there IS the plugin message I’m talking about. Doh!

                  See HERE in N++ code.

                  And then this in the PS docs:

                  9d0c1166-1309-4b3b-a904-e9fc3c980ba9-image.png

                  I suppose I haven’t noticed this because in all of my scripting endeavors, I haven’t needed to use a custom marker (or, I just don’t remember – failing memory disclaimer!).

                  Paul WormerP 1 Reply Last reply Reply Quote 2
                  • Paul WormerP
                    Paul Wormer @Alan Kilborn
                    last edited by

                    @Alan-Kilborn I tried in the PythonScript console:

                    >>> print(notepad.allocateMarker(25))
                    None
                    >>> print(notepad.allocateMarker(0))
                    None
                    

                    What does that mean?

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

                      @Paul-Wormer said in Marker number:

                      BTW, how about your promise of a few day ago?

                      See HERE for “status”.
                      :-)

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

                        @Paul-Wormer said in Marker number:

                        print(notepad.allocateMarker(25))
                        None
                        print(notepad.allocateMarker(0))
                        None

                        What does that mean?

                        So the argument is numberRequested.

                        In the first case you are asking for 25, presumably contiguous, markers to be allocated. That’s way too many; that many aren’t going to be found.

                        In the second case you are asking for 0 markers to be allocated. That’s also pretty nonsensical.

                        If you want one marker, try notepad.allocateMarker(1). Each time you call that, you should get a new number returned.

                        (It appears you are thinking that you tell it which marker ID you want, at least from your usage of 25 – that isn’t how it works)

                        Paul WormerP 1 Reply Last reply Reply Quote 2
                        • Paul WormerP
                          Paul Wormer @Alan Kilborn
                          last edited by

                          @Alan-Kilborn I expected a boolean upon return: if true markerNr is allocated; if false markerNr is free. That is not how it works apparently.

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

                            @Paul-Wormer said in Marker number:

                            I expected a boolean upon return: if true markerNr is allocated; if false markerNr is free. That is not how it works apparently.

                            No, it isn’t, but…why do you care what the actual number is?
                            In your code, go with:

                            my_marker_id = notepad.allocateMarker(1)

                            and then wherever you were using a hard-coded-magic-number for a marker number, use my_marker_id instead:

                                my_marker_id = notepad.allocateMarker(1)
                                editor.markerDefine(my_marker_id, MARKERSYMBOL.CIRCLEPLUS)  
                                nSymbol =  editor.markerSymbolDefined(my_marker_id)    
                                editor.setMarginWidthN(marginNr, 16)               
                                editor.setMarginTypeN(marginNr,  MARGINTYPE.SYMBOL)
                                editor.setMarginMaskN(marginNr, 1<<my_marker_id )      
                                editor.markerAdd(line-1,my_marker_id) 
                            

                            Note that this kind of code will allocate a new number each time you run the script. So, as you’re working on the script, you’ll probably find you’ll be out of markers fairly quickly. :-(

                            To solve that, you could do:

                            try:                                              # <-- important change!
                                my_marker_id                                  # <-- important change!
                            except NameError:                                 # <-- important change!
                                my_marker_id = notepad.allocateMarker(1)      # <-- important change!
                            editor.markerDefine(my_marker_id, MARKERSYMBOL.CIRCLEPLUS)  
                            nSymbol =  editor.markerSymbolDefined(my_marker_id)    
                            editor.setMarginWidthN(marginNr, 16)               
                            editor.setMarginTypeN(marginNr,  MARGINTYPE.SYMBOL)
                            editor.setMarginMaskN(marginNr, 1<<my_marker_id )      
                            editor.markerAdd(line-1,my_marker_id)  
                            
                            Paul WormerP 1 Reply Last reply Reply Quote 2
                            • Paul WormerP
                              Paul Wormer @Alan Kilborn
                              last edited by

                              @Alan-Kilborn Yes, of course. It seems that the description of notepad.allocateMarker is wrong by stating --> bool. Instead it should state --> int. That put me off.

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

                                @Paul-Wormer said in Marker number:

                                It seems that the description of notepad.allocateMarker is wrong by stating --> bool. Instead it should state --> int. That put me off.

                                Good catch!
                                See HERE.

                                Paul WormerP 1 Reply Last reply Reply Quote 0
                                • Paul WormerP
                                  Paul Wormer @Alan Kilborn
                                  last edited by

                                  @Alan-Kilborn Very good. Will Bruderstein listen, what is your experience?

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

                                    @Paul-Wormer said in Marker number:

                                    Will Bruderstein listen, what is your experience?

                                    Dave Bruderstein and @chcg (Christian) are active on the PythonScript project; maybe not “super” active, but active.

                                    I’d think they’d listen, it’s just an easy documentation error.

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

                                      I wrote some test code:

                                      for j in range(100):
                                          my_marker_id = notepad.allocateMarker(1)
                                          print(my_marker_id)
                                          if my_marker_id is None: break
                                      

                                      and obtained as output:

                                      1
                                      2
                                      3
                                      4
                                      5
                                      6
                                      7
                                      8
                                      9
                                      10
                                      11
                                      12
                                      13
                                      14
                                      None
                                      

                                      Not sure where 0, 15, and 16 are…?

                                      Paul WormerP 1 Reply Last reply Reply Quote 1
                                      • Paul WormerP
                                        Paul Wormer @Alan Kilborn
                                        last edited by Paul Wormer

                                        @Alan-Kilborn When I run my original script with markerNr (is marker_id) = 0 or 15, all is OK. The circleplus appears where you would expect it.

                                        When I run your little script I get:

                                        7
                                        8
                                        9
                                        10
                                        11
                                        12
                                        13
                                        14
                                        None
                                        

                                        So during my session I claimed 0 thru 6 and 15. You probably claimed only 0 and 15. Apparently 16 and higher are taken by some plugins.

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

                                          @Paul-Wormer said in Marker number:

                                          You probably claimed only 0 and 15. Apparently 16 and higher are taken by some plugins.

                                          I ran on a virgin system with only the PythonScript plugin (aside from the plugins that come with Notepad++). I’m fairly confident (as I hinted before) that PS doesn’t claim any itself.

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