Looking for tips/directions on how to best approach creating a custom plugin for Notepad++
-
Hello,
there is a lot backstory to my question, but I will try to keep is as brief and to the point as possible. I have no education in computer sciences/IT/anything of the sort, but my job led me to having to learn XML structure, how to edit MathML in XML, and a few similar, still very basic things. I liked it a lot, so I delved a bit deeper into it, learned NPP regex syntax, created some more advanced find/find and replace macros for XML files I’m working with. Now I would like to take it a step further, and transform the multitude of searches (gathered in a single macro) into a plugin for NPP, that would also have additional functions.
I’m working mostly with text/text + math files written in XML (using the JATS tag library). I would like to create a plugin that performs the searches already written in the form of XML macro, but to add on top of it the following:
(1) naming each search with a custom name (right now NPP represents it simply as the regex formula, which does not tell anything to anyone who is not familiar with it)
(2) make the plugin communicate with editor, having him confirm if a change should be made or not, confirm data types (for future transformation) of various elements in the file I work with, transform sequences of characters into other sequences based on provided transformation rules, compare if two (or more) sequences of found characters are identical, provide tooltip information based on data found in particular searches, and similar, text-oriented needs.
I researched on the NPP forums how to get about creating a plugin using Visual Studio, but that alone did not help much. Obviously I do not except anyone to explain it to me in 5 simple steps and be done with it. I’m ready to put in hundreds of hours of learning/work, since I find the subject interesting on its own. What I would be very grateful for is just some guidance on how to approach this project:
(A) what programming language would be best suited for this task;
(B) Should I learn how to use Visual Studio as well, or some other IDE, or an entirely different approach;
© are there any online courses worth recommending, that might help me as stepping stones to reach the target?;
I would be very grateful for any help with this.
-
@slusher59 said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
I’m ready to put in hundreds of hours of learning/work, since I find the subject interesting on its own. What I would be very grateful for is just some guidance on how to approach this project:
First off you mention XML - have you installed the XML Tools plugin - available in Plugin Admin?
Second, you mention REGEX - have you looked at RegExTractor Plugin - available in Plugin Admin? Sounds like it could be related to what you’re trying to do.
If those don’t help and you still want to create a plugin, I would suggest PythonScript (if you’re comfortable with Python) or NppExec to “mock” the features first. These scripting plugins give you access to all the Notepad++ and Scintilla (underlying editor component) APIs that you get from a “real” plugin and they’re much quicker to test if something will work as expected.
For a “real” plugin, I prefer C++, but there is a C# template floating about. For C++, there is a template linked off the “getting started docs” and the Scintilla reference (to interface with the document text and editor components) .
Good luck! Check back in on this thread with questions as you go along.
Cheers.
-
@michael-vincent said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
For C++, there is a template linked off the “getting started docs”
For what it’s worth, the C++ template is ancient and I would discourage anyone who knows modern C++ from using. It’s even still got code to support ASCII builds, which Notepad++ hasn’t supported in years. I have over time essentially rewritten the entire thing, and I’d encourage anyone else to do the same. The only thing you need from the template is the header files (except PluginDefinition.h, ignore that).
However more broadly I think C++ would be too much for OP with minimal programming experience to dive into. I second the Python suggestion, it’s an easy language to learn and performance shouldn’t be a concern for OP’s usecase.
-
This might be worth mentioning as a C++ plugin kickstarter:
https://github.com/dail8859/cookiecutter-npp-cpp-plugin -
Should I add dail’s c++ cookie cutter to the user manual? Or replace the link to the old plugin? Does the cookie-cutter give docking instructions? (IIRC, the old template did, and I wouldn’t want to remove the old completely if the new does not.)
-
@peterjones said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
Should I add dail’s c++ cookie cutter to the user manual? Or replace the link to the old plugin? Does the cookie-cutter give docking instructions? (IIRC, the old template did, and I wouldn’t want to remove the old completely if the new does not.)
Sell it, @dail !!
I’ve never actually had an occasion to use dail’s work. PythonScript is powerful enough for me, so I’ve never delved into the world of making a true plugin.
-
@peterjones said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
Or replace the link to the old plugin?
Oops, the official template is Don’s, so I won’t replace it completely. But I will see if I can add it in, at least
-
@alan-kilborn said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
@peterjones said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
Should I add dail’s c++ cookie cutter to the user manual? Or replace the link to the old plugin? Does the cookie-cutter give docking instructions? (IIRC, the old template did, and I wouldn’t want to remove the old completely if the new does not.)
Sell it, @dail !!
I’ve never actually had an occasion to use dail’s work. PythonScript is powerful enough for me, so I’ve never delved into the world of making a true plugin.
To be honest, I haven’t used this template much in quite a while. I know the goal was to give a ‘ready-to-go’ template for people to use. I’ve created numerous plugins over the years and it got tedious anytime I wanted to start a new plugin.
The unfortunate part is that it does require python to generate the project but for what I was doing at the time that was fine with me (I even looked at Visual Studio’s templating capabilities). Even if users are interested in a bit newer template, this could be the start of a cleaner setup (even if the cookiecutter part isn’t used).
It probably does need a bit of attention because it needs some of Notepad++'s headers and source code files, but there’s a script in the repo to sync those, but it has been a little while since that was done so not sure if updating things would break things.
@peterjones said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
Does the cookie-cutter give docking instructions?
It looks like it doesn’t include the docking feature…can’t really remember why I didn’t include it, but it is something that could always be added back in by someone that is interested.
-
Hey Guys,
Thanks a ton the the answers and guidance.
I installed XML Tools plugin and used the validator and a few other functions of it, but the other ones did not correspond to my needs. Still for the things that they do it’s great.Thank you for the Regex plugin, I was not using it before, but testing if my regexes work on some external websites before implementing them.
I installed both NppExec and PythonScript, and from a quick look, it appears that PythonScript will be a way to go. I will try to first implement already existing functions into it and see how it can be expanded upon. Thanks for this. I got around to PyCharm for creating Python Scripts, and will get down to learning Python itself. If you got any tips on any software/learning courses that would be awesome.
I will try to document any progress with it as I go along. Thank again for the replies!
-
@michael-vincent said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
…have you looked at RegExTractor Plugin - available in Plugin Admin? Sounds like it could be related to what you’re trying to do.
Did you mean “Regex Trainer”?
“RegExTractor” seems to be something unrelated, but I could be wrong, especially since it does tie-in to XML… -
@alan-kilborn said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
“RegExTractor” seems to be something unrelated, but I could be wrong, especially since it does tie-in to XML…
to be honest, I was thinking RegEx Trainer, but couldn’t remember the name and saw RegExTractor in the Plugins Admin which sounded a lot more like what OP was trying to do - i.e., store / run multiple RegEx, tie to XML …
Happy coincidence.
Cheers.
-
@alan-kilborn said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
This might be worth mentioning as a C++ plugin kickstarter:
https://github.com/dail8859/cookiecutter-npp-cpp-pluginYeah, this looks like a much better foundation for a plugin. I see he even wrapped the Scintilla messages in a class to provide a decent interface, just like I did.
-
Hey Guys,
week 1 update. I’ve started learning pythons, watched a bunch of tutorials, tried writing the code in PyCharm, fix errors, see how it works, tie some things together. So far it’s a blast, tho I know it’s just the very beggining, not even a tip of the iceberg.
I’ve also rewritten some of the regexes I already had in python and run those searches on an example file. Most of them work as intended (for the ones that dont I will write a post tomorrow). I also tried exporting this script into PythonScript plugin in notepad and use it there, with miserable results so far. Been getting some errors (more info on what kind tomorrow).
The plan for now is to learn Python more, to be more comfortable with writing code, but the next step is to try and make the script work in PythonScript Notepad Plugin (even if it would be as simple as searching for numbers in the file and returning a list of results).@derek-brown said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
@alan-kilborn said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
This might be worth mentioning as a C++ plugin kickstarter:
https://github.com/dail8859/cookiecutter-npp-cpp-pluginYeah, this looks like a much better foundation for a plugin. I see he even wrapped the Scintilla messages in a class to provide a decent interface, just like I did.
Thanks for this! I will get my head around it tomorrow and try to see what it’s all about and if I can make it work with what I’m currently trying to do.
Thanks for all the help guys, you’ve given me a boost in what I feel like a right direction. Please keep the suggestions coming. If you know any resources that you think might benefit the project, please share, I would be forever grateful.
-
@slusher59 said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
the next step is to try and make the script work in PythonScript Notepad Plugin
@Alan-Kilborn provided a nice simple template to start from.
I’m not a Python expert, prefer to mock my Scintilla testing in NppExec, but I’m becoming more comfortable with Python and thus PythonScript in N++. I also used Alan’s class-based approach when creating PythonScripts for N++ so that I can start, stop and get status from the PythonScript console.
Cheers.
-
Hey Guys,
sorry for late response. I continue to learn python and I tried to use PythonScript to write some code of my own to do the desired searches. However, no luck. One of the problem that I encounter is that PythonScript requires somewhat different commands than regular Python code (please correct me if I’m wrong, still a newb here!). For example, I never saw this function “editor” in Python, but it seems like it’s related to Notepad/Scintilla. Many of my code lines does not work, because I don’t understand how python language and PythonScript plugin are related to each other.
Here is an example:
I found in PythonScript documentation some guidelines to help me write some elementary code to just test how things work. And while the second line works fine and does what it’s supposed to, I could not get the first one to work at all, was getting errors constantly (that either it’s a syntax error, something is not defined, and a whole bunch of others).
I then started reading about plugin templates for NP++, and (please, again correct me if I’m wrong) that they have to be written at least in part in C++ or with the use of cython. I like learning python and will continue to, but I do not feel that I can handle learning C++ at this point, seeing how python gives me trouble.
I would also not want to lose on the great functionality of the search result window from Notepad++, that it provides on it’s own.
Here is what I mean. This is a pic of some of the regex searches I wrote and store in shortcuts.xml:
and here is how the regexes look as stored in shortcuts.xml:
I got a whole bunch of these saved regex searches, but when the search results in NPP look like in the screen above, where next to the number of hits the regex formula itself is displayed, it does not tell anything to colleagues who don’t know the regex syntax. And this in turn makes it very hard for them to understand what the searches are actually searching for.
So the idea behind the plugin was the be able to “name” those searches with custom names, like “These numbers appear to be abnormal, please check them with documents”, and so on. I thought that this would the first functionality of the plugin, and using python would allow for greater control over searching and replacing. But maybe I’m mistaken and trying to develop a plugin is not the best way to go about making this tool (regex compilation) more accessible to others. Is it even possible to name the searches (like in the last screen) with some custom names, so that instead of “[0-9]{4} > [0-9]{4} .*{5}” the search name is displayed like “number of items above required stock” (to just give an ad hoc example) ? -
@slusher59 said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
For example, I never saw this function “editor” in Python, but it seems like it’s related to Notepad/Scintilla.
It is. At the top of your Npp PythonScript scripts, add the line:
from Npp import *
and that should be good enough to get past that “error” you’re now seeing.
Cheers.
-
@slusher59 said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
I got a whole bunch of these saved regex searches, but when the search results in NPP look like in the screen above, where next to the number of hits the regex formula itself is displayed, it does not tell anything to colleagues who don’t know the regex syntax. And this in turn makes it very hard for them to understand what the searches are actually searching for.
Workaround. Not pretty, but may be useful. Create your RegEx with the
(?x)
modifier to allow inline comments and free space. So here’s an example in my ‘shortcuts.xml’:<Macro name="Mike Test" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="3" message="1700" wParam="0" lParam="0" sParam="" /> <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?x) # Find Header (?m)(?'PACKAGE_HEADER'^(?-i:package\b))(?s:.*?)(?=\s*(?:(?&PACKAGE_HEADER)|\Z))" /> <Action type="3" message="1625" wParam="0" lParam="2" sParam="" /> <Action type="3" message="1702" wParam="0" lParam="3" sParam="" /> <Action type="3" message="1701" wParam="0" lParam="1636" sParam="" /> </Macro>
Notice I use the
(?x)
modifier followed by a#
to introduce the comment describing what the RegEx does. Then a line break and the actual RegEx.Running that macro in N++ produces:
which of course still shows the complex RegEx in the search results, but notice the line “before” it is the nice comment.
Does that help a little?
Cheers.
-
@michael-vincent said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
Does that help a little?
This helps a ton!! Thank you! I will add these comments/descriptions to all current regexes and this will give me plenty of time to work on the actual plugin in python and taking my time to understand it all properly, without worrying that my colleagues are losing out on some of the functionalities of our tools!
This will be a game changer and a first step in a new direction. Thank you again! -
One more question, while I still remember it. Is it possible, in any way, even a crude one at the moment (due to my lack of skills), that if one of the search regex finds a string, NPP would prompt a user with a pop up window/message in any other form, that “hey, this has been found in your file, you might want to take a look at it”?
-
@slusher59 said in Looking for tips/directions on how to best approach creating a custom plugin for Notepad++:
One more question, while I still remember it. Is it possible, in any way, even a crude one at the moment (due to my lack of skills), that if one of the search regex finds a string, NPP would prompt a user with a pop up window/message in any other form, that “hey, this has been found in your file, you might want to take a look at it”?
I don’t think so with just the Macro approach. If you implement the searches in PythonScript, then yes absolutely possible as with any other scripting solution (NppExec for example) and certainly with a proper plugin.
Cheers.