View Single Post
Old 03-24-2022, 03:01 PM   #74
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,958
Karma: 6361444
Join Date: Nov 2009
Device: many
Another possible approach for function replacement

I have been thinking about how to implement python function replacement without having to jam even more into the F&R dialog and *not* use a plugin.

Since in replacements \F has no special meaning as a capture group, we could start any python replacement function name with that.

So to use function replacement from a replace function in a module named 'mymod.py' **without any gui changes** the replace field in the F&R dialog could be set by the user to:

Code:
\F<mymod>

Then the current ReplaceBuilder code would detect that and invoke the replace() function in mymod.py which would be stored in the Sigil Preferences folder in a replacement_ functions folder.

Then all a user would have to do is fill that folder with whatever python modules with replace functions they want.

Yes this is more than a bit esoteric and cryptic but so are python replacement functions and regex and this would only be used by very advanced users.

If we went this approach, we could easily add this capability to Sigil itself (no plugin needed) and it would not bloat or otherwise interfere with the current F&R for 99.9% of the users.

Any printing output from a replacement function would need to be written to a log file by the user, and no function edit and remove interface would be added. The user him/herself would be responsible for creating, editing, storing, and removing their own python code.

It would also work "as is" with Saved Searches.

Thoughts?

Last edited by KevinH; 03-24-2022 at 03:16 PM.
KevinH is offline   Reply With Quote