Skip to content

Feature request: editor.rereplace() could return number of replacements made #182

Open
@alankilborn

Description

@alankilborn

This is just a nice-to-have:

For editor.rereplace() there doesn't seem to be a good way to know the number of replacements that were actually made.
Suggestion: It's return value (currently always None) could be an integer with that count.

Workaround # 1 is to run editor.research() first with the same "find" expression, and, like the .research() example in the docs shows, add the matches to a list, and then do a len() on the list, but this is wasteful as the search is done twice this way (once in .research() and once in .rereplace()).

Workaround # 2 is to use a function as the replacement "text" in the .rereplace() call, and add in a custom counter, for example:

replacement_count = 0
def add_1(m):
    global replacement_count
    replacement_count += 1
    return 'Y' + str(int(m.group(1)) + 1)
editor.rereplace('X([0-9]+)', add_1);

Workaround # 2 is fine but again it is extra work that Pythonscript itself could do for me.

Request is also made for editor.replace() and truly even editor.research() and editor.search() could also return match/replacement counts.

Request is made against 1.5.x Pythonscript (and presumably the new 3.x beta as well).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions