• Login
Community
  • Login

Margin Manipulation

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
10 Posts 3 Posters 6.7k 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.
  • S
    Scott Sumner @Claudia Frank
    last edited by Sep 29, 2016, 2:06 PM

    @Claudia-Frank ,

    A short pythonscript example for margin-manipulation would be nice to see if you have one…hint, hint… Reading the documentation on this and deriving something that works doesn’t seem to be easy (tried a bit of time ago…)

    I’m not interested in zero-basing line numbers (intrigued by what drives that desire, though!), but rather how to use the margin for other purposes.

    If pressed to be more specific, perhaps the type of margin manipulation that the LocationNavigate plugin provides for changed line marking would be a good example. Note that I’m NOT asking for a rewrite of that complete functionality in pythonscript, just something that illustrates that type of margin-marking.

    D 1 Reply Last reply Sep 29, 2016, 2:14 PM Reply Quote 0
    • D
      dail @Scott Sumner
      last edited by Sep 29, 2016, 2:14 PM

      @Scott-Sumner

      I’m not familiar with that plugin. Do you have a screen shot or link to the exact functionality you are referring to?

      The only image I could quickly find regarding the location navigation plugin and margins is this:

      img

      S 1 Reply Last reply Sep 29, 2016, 2:27 PM Reply Quote 0
      • S
        Scott Sumner @dail
        last edited by Sep 29, 2016, 2:27 PM

        @dail

        Your image shows the functionality. The marker on line 3 is an unsaved changed line and the marker on line 2 is a saved changed line. Ideally I’m interested in finding a short pythonscript example on how to do that sort of margin/marker manipulation.

        1 Reply Last reply Reply Quote 0
        • D
          dail
          last edited by dail Sep 29, 2016, 2:45 PM Sep 29, 2016, 2:44 PM

          Since I don’t know the PythonScript API (or a current way of testing it) too well I can describe the general idea

          1. Create a marker
          2. Set the margin’s options to allow this marker
          3. Add/Remove it to lines as desired

          I can show a LuaScript example. You should be able to easily translate it into PythonScript:

          -- Pick a marker ID (not sure what is best)
          id = 10
          
          editor:MarkerDefine(id, SC_MARK_CIRCLE)
          -- can set fore/back color if desired here
          editor.MarginMaskN[1] = editor.MarginMaskN[1] | (1 << id)
          editor:MarkerAdd(30, id) -- add it to line 30
          

          Notepad++ uses some markers internally that you shouldn’t use. So probably any marker ID under 21 would be fine assuming it doesn’t clash with another plugin.

          Notepad++ uses margin 1 to show markers. The margin mask needs a bit set to allow it to use that id.

          I’m sure Claudia can show better examples using Python ;)

          1 Reply Last reply Reply Quote 0
          • D
            dail
            last edited by Sep 29, 2016, 2:55 PM

            Since this topic got totally away from the original question I split it into a new topic ;) Sorry @Eric-Colossal

            1 Reply Last reply Reply Quote 0
            • S
              Scott Sumner
              last edited by Sep 29, 2016, 3:30 PM

              Sorry for the derailing…not sure it was a TOTAL derailing as some examples on how to do the alternate line # margin might have helped the OP (of the original topic ).

              dail, thanks for the Lua, I’ll be taking a look at it.

              1 Reply Last reply Reply Quote 0
              • D
                dail
                last edited by Sep 29, 2016, 3:39 PM

                Ok not total derailment but worth its own discussion for now ;)

                Sorry for the derailing

                Mostly my fault since I like playing around with scripting capabilities in Notepad++ :)

                S 1 Reply Last reply Sep 29, 2016, 6:22 PM Reply Quote 0
                • S
                  Scott Sumner @dail
                  last edited by Sep 29, 2016, 6:22 PM

                  @dail

                  So I ported it to Pythonscript (very easy to do):

                  arbitrary_marker_id = 10
                  npp_marker_margin_nbr = 1
                  editor.markerDefine(arbitrary_marker_id, MARKERSYMBOL.CIRCLE)
                  editor.setMarginMaskN(npp_marker_margin_nbr, editor.getMarginMaskN(npp_marker_margin_nbr) | (1 << arbitrary_marker_id))
                  test_line_nbr_to_mark = 30
                  editor.markerAdd(test_line_nbr_to_mark - 1, arbitrary_marker_id)
                  

                  Running it I can see how it uses the same margin that N++ uses for Bookmarks. I was hoping for something that would show how to create a brand-new margin and then use that (so that Bookmarks wouldn’t cover over it, i.e., could co-exist).

                  I also notice that it must be conflicting with something that LocationNavigate uses, because now the color of my new marker follows Loc Navi’s line change indicators, and other interesting effects…

                  Anyway, it’s a starting point for further experimentation.

                  C 1 Reply Last reply Sep 29, 2016, 10:49 PM Reply Quote 0
                  • D
                    dail
                    last edited by Sep 29, 2016, 6:38 PM

                    Notepad++ uses margins 0, 1, and 2 for line numbers, bookmarks, and folding symbols, respectively. There are 5 margins in total so you can use 3 and 4.

                    my_margin = 3
                    editor.MarginWidthN[my_margin] = 14 -- Show the margin, using 0 hides it
                    editor.MarginMaskN[my_margin] = editor.MarginMaskN[my_margin] | (1 << id)
                    

                    Now when you add a marker it will show up in the new margin.

                    1 Reply Last reply Reply Quote 1
                    • C
                      Claudia Frank @Scott Sumner
                      last edited by Sep 29, 2016, 10:49 PM

                      @Scott-Sumner

                      Hi Scott,

                      are you more interested in how to create your own marker symbol or how to show a marker
                      in the margin when changes occur?

                      A quick script for the later would look like

                      editor.setMarginTypeN(3,4)   
                      editor.setMarginWidthN(3,20)
                      
                      def callback_MODIFIED(args):
                          if args['modificationType'] & 0x1:
                              editor.marginSetText(editor.lineFromPosition(args['position']), '>')
                          elif args['modificationType'] & 0x2: 
                              editor.marginSetText(editor.lineFromPosition(args['position']), '<')
                      
                      
                      editor.clearCallbacks([SCINTILLANOTIFICATION.MODIFIED])
                      editor.callback(callback_MODIFIED, [SCINTILLANOTIFICATION.MODIFIED])
                      

                      The script uses a text marker instead of a real symbol.
                      ‘>’ should indicate that something was added, and … you know ;-)

                      If it is about changing symbols, hmm …, I didn’t play with it yet. It would involve using

                      SCI_MARKERDEFINEPIXMAP(int markerNumber, const char *xpm)
                      SCI_MARKERDEFINERGBAIMAGE(int markerNumber, const char *pixels)
                      

                      and others to create the images first and then assign like @dail already showed.
                      If there is something I can do, let me know - this would be much more interesting than
                      writing boring documentation.

                      Cheers
                      Claudia

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