View Single Post
Old 03-23-2022, 11:35 AM   #64
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,957
Karma: 6361444
Join Date: Nov 2009
Device: many
I think there may be a way to do this using Sigil's embedded python bridge code, passing in a hit number, a string list of the capture strings. If we make the replacement call its own class, then storage between calls would also be doable.

My real questions are more due to the gui elements and how to shoehorn them into Sigil:

1. how to indicate and select a function name in the already over crowded Find and Replace dialog? Perhaps a separate dialog similar to Saved-Searches dialog may be the only way?

2. where to capture the print output and how best to display any print output from the replacement function? Again perhaps in a separate Saved-Search-like dialog with its own Find and Replace buttons?

3. how to allow debugging of the python replacement code?

4. how to handle python errors during a replace all?

In fact, much of this python infrastructure already exists in the plugin runner.

Maybe ... we implement this functionality all in its own plugin, "FunctionReplacer", that just implements python replacement inside a python based search regex search and replace.

That would prevent current Find and Replace from getting any more bloated while allowing users who need it access to this feature via the FunctionReplacer plugin. Since plugins are already python based and python has both regex and re modules and can easily access all css, all html files and if needed the set of selected resources, adding this feature request using a plugin makes the most sense.

Imagine a plugin gui that asks for your Find, target, direction, and provides a pull-down of existing replacement functions by module name stored in that plugin preferences folder.

And given Plugins use a copy on write approach, then all changes can be previewed first and aborted if needed with no harm done.

Thoughts?

Last edited by KevinH; 03-23-2022 at 12:58 PM.
KevinH is offline   Reply With Quote