Margin Manipulation

  • @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.

  • @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:


  • @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.

  • 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 ;)

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

  • 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.

  • 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++ :)

  • @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.

  • 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.

  • @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

    def callback_MODIFIED(args):
        if args['modificationType'] & 0x1:
            editor.marginSetText(editor.lineFromPosition(args['position']), '>')
        elif args['modificationType'] & 0x2: 
            editor.marginSetText(editor.lineFromPosition(args['position']), '<')

    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.


Log in to reply