PythonScript: editor.setProperty() and editor.getProperty()
-
@Ekopalypse said in PythonScript: editor.setProperty() and editor.getProperty():
this does no longer work due to changes from scintilla
Ah, maybe stopped working when Lexilla split off from Scintilla…
-
I’m not sure, but I have something in my head that was done deliberately.
-
Any other ideas on how to have a custom bit of data “tag along” with each tab?
(I could of course have a Python dict, keyed on “buffer id”, I suppose…)
-
@Alan-Kilborn said in PythonScript: editor.setProperty() and editor.getProperty():
(I could of course have a Python dict, keyed on “buffer id”, I suppose…)
I think that’s the best solution.
-
but if I remember correctly, buffer IDs are reused, so you have to make sure you remove them from the dict once the file is closed. Hmm … but … what happens to cloned documents …?
-
@Ekopalypse said in PythonScript: editor.setProperty() and editor.getProperty():
what happens to cloned documents
Cloned docs share buffer id value, so just more code needed to do things correctly.
-
@Ekopalypse said in PythonScript: editor.setProperty() and editor.getProperty():
but if I remember correctly, buffer IDs are reused, so you have to make sure you remove them from the dict once the file is closed. Hmm … but … what happens to cloned documents …?
I had to deal with that in Columns++ (though in C++, not Python).
Adding to the confusion is that Scintilla notifications have a Scintilla document ID but no Notepad++ buffer ID, and Notepad++ notifications for opening and closing files have a buffer ID but no document ID.
I remember a lot of trial and error working it out, and I’m still not certain that it’s bullet-proof because there is no documentation of how it expected to work, and past a point, I just get lost trying to read Notepad++ code.
I know I wound up with what I consider messy code. I have a map (like a Python dict) from document IDs to structures which contain the buffer ID along with the information I need to keep per document, and some code processing Notepad++ messages that came from just watching messages until I was as sure I was going to get that I had discerned a pattern.
What I wound up with removes the entry in the map if a file is opened with the same buffer ID as an existing file or if a file is closed and the buffer ID can’t be found in either view; skips NPPN_BUFFERACTIVATED processing between NPPN_FILEBEFOREOPEN and NPPN_FILEOPENED; and does new document processing in NPPN_BUFFERACTIVATED if the document ID is not in the map or if the buffer ID in the map for that document ID doesn’t match the one returned by NPPM_GETCURRENTBUFFERID.
-
Yes, cloned documents are a nightmare from a plugin perspective. When developing my LSP client, I also played around with it a lot and found problems such as missing notifications.
I honestly don’t understand the implementation of the concept of a cloned document.
I would assume that this only makes sense if the cloned document is practically the page before or after the original document so that you can see more of the code. Arbitrary view in a cloned document doesn’t seem helpful to me.
Maybe I just didn’t understand the point behind it but honestly I just hope, that nobody who uses my plugins wants to use cloned documents. -
@Ekopalypse said in PythonScript: editor.setProperty() and editor.getProperty():
I honestly don’t understand the implementation of the concept of a cloned document.
It’s pretty much straight lifted from how Scintilla works. Scintilla has documents and controls. Notepad++ uses two visible Scintilla controls, one for each view, and one Scintilla document for each file or new, unsaved file.
Scintilla keeps visible controls containing the same document up to date. The tricky parts come because while the content is associated with the document, many elements of the display are associated only with the control. (So, in my Elastic tabstops implementation, if a document is visible in both views and tab positions change, I must update both views, since custom tab positions are a property of a Scintilla control, not of a Scintilla document.)
You can observe this in vanilla Notepad++ if you open a file, make a multiple selection, open a new tab and then switch back to the first tab. The multiple selection will be gone. That’s because selection is a property of the control, not the document. Notepad++ goes out of its way to save and restore the primary selection or a rectangular selection, but it doesn’t trouble with multiple selections.
problems such as missing notifications
If it’s Scintilla notifications, I’m fairly sure notifications for things associated with the document (like SCN_MODIFIED) will occur once per document, while those associated with the control (like SCN_UPDATEUI) will occur once per view.
Maybe I just didn’t understand the point behind it
It’s helpful if there are multiple sections of a document that should correspond in some way (for example, every item listed in an overview should be addressed, in order, in a later section, using exactly the same wording) but it won’t all fit on a single screen.
Sometimes it makes it easier to move passages from one part of a document to another if you can see both the source and the target at the same time.
-
Maybe I just didn’t understand the meaning behind it.
So that’s right. :-)
It looks like I don’t need to do this kind of work that would benefit from a cloned view, or not often enough. In the cases where I need to jump to different places, I use bookmarks, but I understand that you’d rather have the other area in the second view if you need to do that repeatedly.
As for notifications, I’d have to look in my notes, which I don’t have access to at the moment, but from what I remember it was about both npp and scintilla notifications. I suspect this will be one of the issues that will be addressed when everything else is working and the plugin is officially released.