1

Virtually all the text editors let you do search-and-replace, some even support regular expressions, some let you extend their functionality with macros that are quite a job to write and to learn to (you have to study the editor API and often to write the code in a relatively esoteric language).

What I want is an editor that would let you just paste a Python function in a dialogue or a panel the way you paste search and replace samples and run it, passing the entire text edited or selected as a string (or a list of strings) argument to the function and replacing it with what it returns.

0

You can run a Python script against the entire text by configuring the 'Build' menu selection in the Geany editor. See https://wiki.geany.org/howtos/configurebuildmenu

This will not allow you to run a script on just a text selection, however.

0

CudaText is free and cross-platform, it supports this.

  • Configure Python engine if you use Linux (see info about option "pylib" in CudaText Wiki)
  • call menu Plugins / Make Plugin; confirm to create new plugin
  • new plugin created, its __init__ python file is opened
  • change there method run like the following:
    def run(self):
        ALL_TEXT = False
        if ALL_TEXT:
            s = ed.get_text_all()
            s = '['+s+']' # any function here!!
            ed.set_text_all(s)
            msg_status('all text replaced')
        else:
            x1, y1, x2, y2 = ed.get_carets()[0]
            if (y1, x1)>(y2, x2):
                x1,y1,x2,y2 = x2,y2,x1,y1
            if y2<0: return
            s = ed.get_text_substr(x1, y1, x2, y2)
            s = '['+s+']' # any function here!!
            ed.replace(x1, y1, x2, y2, s)
            msg_status('sel replaced')
  • change ALL_TEXT to use all text or only selection
  • call new plugin (restart CudaText) via Plugins / MySample

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.