Placing markers

Help
2011-08-12
2013-01-25
  • Michael Brock
    Michael Brock
    2011-08-12

    I am attempting to write  a script  which places a marker on a line  in the margin as a symbol, or preferably, as a character.  I  have this script below which changes the bookmark icon, but when I place a marker the line simply has its background changed.    My understanding is that this might be because the margin  where the marker would go has a 0 width.  However, I tried giving each margin a width and it made no difference.  The scintilla documentation explains that the marker will appear in the "selection margin" but fails to define what exactly that is.

    editor.setMarginWidthN(4, 10)
    editor.setMarginTypeN(4, MARGINTYPE.TEXT)
    editor.markerDeleteAll(8)

    pos = editor.getCurrentPos()
    line = editor.lineFromPosition(pos)

    editor.markerDefine(8, MARKERSYMBOL.CIRCLE) # use a colored symbol (possible symbols are CIRCLE, ROUNDRECT, ARROW, SMALLRECT, SHORTARROW, .
    editor.markerSetFore(8, (255,0,0)) # contour of symbol
    editor.markerSetBack(8, (255,255,0)) # filling

    marker = editor.markerAdd(line,8)

     
  • You're just missing a

    editor.setMarginMaskN(4, 256)
    

    which just says that marker 8 (ie. 256 when expressed as a decimal), should be shown on margin 4.

    Incidentally, you could set a flag if the "setup" has already been done (so all the margin and marker preparation), then only do that once.  You could also remember the line the marker is on, then just remove that marker, rather than calling markerDeleteAll() - I'm not sure how quick markerDeleteAll is, although it's probably got a list of the line numbers cached somewhere so shouldn't be too problematic.

    Cheers,
    Dave.

     
  • Michael Brock
    Michael Brock
    2011-08-12

    Ahh, okay, that makes sense.  I think that single clarification will go a long way towards explaining other marker mysteries.

    Thanks for the help, I'll make this change.  The script is is going to be a replacement for the "numbered bookmarks" script I had questions about a while back.  Turns out that approach has issues in that any time text is added the line numbers get rather un-aligned with the position bookmarked.

    Another quick question.   My original scripts had two scripts for ever bookmark.  One to set it (i.e. to set margin text and save the line number)  and a second script to go to that line number. I  had shortcuts alt-# to set the bookmark, and ctrl-# to go to the bookmark  I'd  like to have shortcuts with this script as well but I'm curious as to whether or not there is a way to use a single shortcut to the script but then enter a number to indicate which mark to  set or go to.  Is it possible to start the script and then have it wait for a keypress (which would be a single number).  Or maybe throw up a dialog to collect that number?

    Thanks again,

    Michael

     
  • You could use notepad.prompt() to throw up a dialog, but that waits for a return key press afterwards - I don't *think* you could wait for an individual keypress, but there may be some way to do it (maybe with PyWin32?).  There are some more Python-experienced people on here that may be able to answer that.

    Cheers,
    Dave.