Uniquely changing a lines formatting

Help
2011-05-06
2013-01-25
  • Michael Brock
    Michael Brock
    2011-05-06

    In my last editor,  bookmarks were numbered.  It made it easier to return to a specific bookmark (obviously) and each bookmark was indicated with a small numbered bullet in the margin.  I have accomplished this in notepad++ with scripts which save the current line number to a text file (one file for each bookmark "number") when setting the bookmark, then retrieving the line number from the text file and moving the caret to the line number.  It works quite well.   However, what I'm missing is the ability to uniquely identify a line with the bookmark.  Currently I set the line to be a bookmark so I get the bullet/icon in the margin.  But is it possible to some way give that line a unique characteristic such as a particular color or highlighting (each bookmark would have it's own color)? I'll settle for any unique, identifiable change but what I had in mind was similar to the the current line has a distinct background color. I tinkered with editor.addmarker and others but had no luck.  Is it possible?

    Thanks,

     
  • You could use markers for this, but I think you'd run out quickly, as there are only 32 in total, and many are used for the fold markers and so on.  Your best bet is to add a margin (3 is unused in N++, unless you have the Change Markers plugin installed), then set the type of margin to TEXT.  Then you can set the text of the margin on any line.

    # initialisation
    editor.setMarginWidthN(3, 10)
    editor.setMarginTypeN(3, MARGINTYPE.TEXT)
    # then, later, to set the text of line 37 (zero indexed) to "C"
    editor.marginSetText(37, "C")
    

    Any chance you could post your script to the script showcase forum - I'm sure others (me included) would find your script(s) useful!

    Cheers,
    Dave.

     
  • Michael Brock
    Michael Brock
    2011-05-09

    Thanks Dave, that worked perfectly. Well, almost perfectly, but certainly well enough.  I  modified the script to set a margin character to match the bookmark #.  So now it works very similarly to my previous editor.  The only little niggle is that I have notepad++ configured  to color the left margin.  When deleting the  margin character with:

    editor.marginSetText(37,"")

    it leaves behind a white "square" where the magin text had been.  I tinkered with the scintilla margin styles but had no luck.  Anyway, this works better than I had hoped.    Thanks again!  I'll post my scripts in the showcase.

    Michael