PythonScript icon indicating copy to clipboard operation
PythonScript copied to clipboard

How to obtain NPP bookmark ID

Open jremus opened this issue 3 years ago • 9 comments
trafficstars

I created two small utility scripts. One that exports the bookmarked line numbers of an editor view and another that imports (bookmarks) specified lines in an editor view.

For that purpose I hardcoded the following (from the HideLines.py sample):

NPP_MARK_BOOKMARK = 24
NPP_MARK_BOOKMARK_MASK = 1 << NPP_MARK_BOOKMARK

Which I then use with editor.markerNext(line, NPP_MARK_BOOKMARK_MASK) and editor.markerAdd(line, NPP_MARK_BOOKMARK).

With the latest Notepad++ the value of MARK_BOOKMARK changed from 24 to 20 with Notepad++ commit 9455684 ("Renumber Notepad++ marks for preparing Scintilla 5.3.0's integration").

In the Notepad++ source I found that there is a NPP message NPPM_GETBOOKMARKID to get the bookmark ID. Is there any function in PythonScript to make use of that, so that I can replace the hardcoded bookmark ID with the one provided by the NPP API?

Thanks and regards, Jens

jremus avatar Nov 18 '22 15:11 jremus

Is there any function in PythonScript to make use of that

There isn't, but I think you've just made a feature-request for it. :-)

Comment made current to PS releases 2.0 and 3.0.14

alankilborn avatar Nov 18 '22 15:11 alankilborn

In the meantime I am using the following workaround:

# https://github.com/notepad-plus-plus/notepad-plus-plus/commit/9455684b429449f668c1aedb77ec9dcb1642c244
NPP_MARK_BOOKMARK = 24 if notepad.getVersion() < (8, 4, 6) else 20
NPP_MARK_BOOKMARK_MASK = 1 << NPP_MARK_BOOKMARK

jremus avatar Nov 18 '22 15:11 jremus

Mainly as a curiousity, @Ekopalypse provided some code (hope it is OK to share) that will obtain the bookmark id from Notepad++ 8.4.7 and later, before PythonScript supports a first-class "Notepad" object function for it:

import ctypes
NPP_MARK_BOOKMARK = ctypes.windll.user32.SendMessageW(ctypes.c_size_t(ctypes.windll.user32.FindWindowW(u'Notepad++', None)), ctypes.c_uint32(1024+1000+111), ctypes.c_size_t(0), ctypes.c_ssize_t(0))

alankilborn avatar Dec 23 '22 11:12 alankilborn

getBookMarkID is available now, can this be closed?

Ekopalypse avatar Feb 25 '23 13:02 Ekopalypse

getBookMarkID is available now, can this be closed?

What does "now" mean in this context?

>>> notepad.getBookMarkID()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'Notepad' object has no attribute 'getBookMarkID'

with:

Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)]

alankilborn avatar Feb 25 '23 14:02 alankilborn

Ah, ok - so this is only available with a recent PS3 version, I see ...

Ekopalypse avatar Feb 25 '23 14:02 Ekopalypse

I have no explanation why this would be part of PS3 and not PS2, since PS2 is the currently the non-beta version. Features such as this should be present in both versions, IMO.

alankilborn avatar Feb 25 '23 14:02 alankilborn

... looks like the MS way. Offer a new product with new features to attract users for beta testing :-D

Ekopalypse avatar Feb 25 '23 14:02 Ekopalypse

I don't think our wonderful PS developers are dumb and would use that strategy. :-)

alankilborn avatar Feb 25 '23 16:02 alankilborn