PythonScript, editor.markerAdd has stopped working
-
@peterjones
It had actually uninstalled PythonScript entirely when I updated. I had to re-install it so I do currently have 2.0.0 installed. -
MARK_BOOKMARK = 24 # this is Notepad++'s bookmark flag currentLine = editor.lineFromPosition(editor.getCurrentPos()) marker = editor.markerAdd(currentLine, MARK_BOOKMARK)
works for me: it puts Notepad++'s bookmark symbol in the gutter
Are you sure there’s a marker defined for marker slot 1?
-
@peterjones Thanks! That might be what has changed. I’ll have to try to remember why and how I was getting the numbers themselves to show as markers (I have similar scripts for 1 through 9).
-
@michael-brock said in PythonScript, editor.markerAdd has stopped working:
remember why and how I was getting the numbers themselves to show as markers (I have similar scripts for 1 through 9).
Could it be you were using a extra plugin that shows the numbers themselves?
-
Thanks for the responses. They jogged my memory. I have a python startup script which is run when Notepad++ starts. It sets the markers to the text 1-9. The upgrade to 8.3.3 overwrote that script. I reverted to a back up copy and it is back to working.
-
@michael-brock said in PythonScript, editor.markerAdd has stopped working:
It sets the markers to the text 1-9.
Cool. Could you share that portion of your startup script? I’ve usually only seen markers be one of the 32 predefined symbols, so seeing how you did that might be a learning experience for me or others.
-
@michael-brock said in PythonScript, editor.markerAdd has stopped working:
The upgrade to 8.3.3 overwrote that script.
I find that difficult to believe.
I think what happened is that you were using the machine
startup.py
(c:\Program Files\Notepad++\Plugins\PythonScript\Scripts
is the normal machine-script folder) instead of the userstartup.py
(%AppData%\Notepad++\Plugins\Config\PythonScript\Scripts
for a normal installation or<portable-npp-folder...>\Plugins\Config\PythonScript\Scripts
for a portable) … Thus, when you installed PythonScript 2.0.0, it overwrite the machinestartup.py
; the plugin expects that it can overwrite that file, because users are expected to use the userstartup.py
for their own customization (though the docs don’t emphasize that enough, IMO; we in the forum do actively encourage PythonScript users to customize in the user startup, not the machine startup). -
More specifically then: I upgraded Notepad++, that uninstalled Pyton Script. I reinstalled Python Script and in the process the startup.py script I was using was overwritten.
This is the snippet of code:
# sets margins and markers for bookmarks editor.setMarginWidthN(4, 10) editor.setMarginTypeN(4, MARGINTYPE.TEXT) for x in range(1,9): marginMask = 1 << x editor.setMarginMaskN(4, 510 ) editor.markerDefine(x, 10048 + x) # use a colored symbol (possible symbols are CIRCLE, ROUNDRECT, ARROW, SMALLRECT, SHORTARROW, . editor.markerSetFore(x, (0,0,0)) # contour of symbol editor.markerSetBack(x, (255,255,0)) # filling
-
@michael-brock said in PythonScript, editor.markerAdd has stopped working:
editor.markerDefine(x, 10048 + x)
When I try something like this, with e.g. x = 2, I only get a half-width bookmark, looking like this:
Unless… I zoom way up in which case it looks better:
But that isn’t a realistic working environment for me. :-)
If I try other types of boomarks (as well as the default blue/purple ball symbol), they all look fine at my preferred zoom level, here’s the “bookmark” one:
-
-
-
from Npp import * # sets margins and markers for bookmarks editor.setMarginWidthN(4, 10) editor.setMarginTypeN(4, MARGINTYPE.TEXT) # this will make margin#4 allow markers 1-10 editor.setMarginMaskN(4, 0x03FF ) for x in range(1,9+1): editor.markerDefine(x, 10048 + x) # use a colored symbol (possible symbols are CIRCLE, ROUNDRECT, ARROW, SMALLRECT, SHORTARROW, . editor.markerSetFore(x, (0,0,0)) # contour of symbol editor.markerSetBack(x, (255,255,0)) # filling for i in range(1,9+1): editor.markerAdd(5+i,i) editor.setMarginMaskN(1, editor.getMarginMaskN(1) | 0x3FF ) # set those bits from time import sleep sleep(10) # five seconds later editor.setMarginMaskN(1, editor.getMarginMaskN(1) & ~0x3FF ) # clear those bits
It appears that if you are putting the character style in margin 1, where the bookmark round icon goes, the characters are strangely placed. I think it might have to do with the
editor.setMarginTypeN(1, ...)
that is implicit in Notepad++ default condition. Because the margin=1 column cuts off the characters, but margin=4 column does not.I added
for i in range(0,4+1): t = editor.getMarginTypeN(i) console.write("margin type #{} = {} {}\n".format(i, t, MARGINTYPE.values[t]))
to see the types for each of the 5 margins:
margin type #0 = 1 NUMBER margin type #1 = 6 COLOUR margin type #2 = 0 SYMBOL margin type #3 = 0 SYMBOL margin type #4 = 4 TEXT
but even if I add
editor.setMarginTypeN(1,4)
near the beginning, the margin=1 column still cuts off half of the character. -
So there are some nuances here that I haven’t thought about before, or at least not in a long time, so I will expend some more time thinking about it…
But aside from the visual implications of seeing a different number symbol for the bookmarks, is there other value in doing this – what the OP has done? I don’t think so, unless there are other commands created which use the numbers to do something.
-
@alan-kilborn said in PythonScript, editor.markerAdd has stopped working:
So there are some nuances here that I haven’t thought about before, or at least not in a long time, so I will expend some more time thinking about it…
But aside from the visual implications of seeing a different number symbol for the bookmarks, is there other value in doing this – what the OP has done? I don’t think so, unless there are other commands created which use the numbers to do something.
This is part of a bookmarking “scheme”. I can set a marker/bookmark w/ the number marker in the column with alt-1,alt-2, etc. The snippet of code above sets the bookmark. What isn’t shown is the portion that saves the marker handle (as a string) to a file named after the bookmark # and the file name (so a separate file for each bookmark for each file).
I have a separate set of scripts which are keyed to ctrl-1, ctrl-2, etc. These look for a file named as above and reads the marker from the file and uses
gotoLine=editor.markerLineFromHandle(int(gotoMarker)) editor.gotoLine(int(gotoLine))
to jump to the line.
It works very well. So I have a set of 9 bookmarks that I can set and jump between. In my programming I will set particular code blocks to always have the same bookmark and it makes jumping between them very easy.
-
@michael-brock said in PythonScript, editor.markerAdd has stopped working:
It works very well.
Ah, okay. It’s always nice to have the “rest of the story” on something that starts out as a tech support question and then takes on a life of its own through discussions. :-)
-
-
The marker ID used for bookmarks changed in Notepad++ 8.4.6 (and later). It is now 20, instead of 24. So, all references to 24 in this thread and/or its script(s), should be changed to 20.