Search/replace macro options change, easier way?

  • Sometimes I create search or replace macros by recording them. After that I sometimes need to tweak the options (match case, in-selection, and so on…). It is hard to do this without rerecording the entire macro…by this I mean editing the macro in shortcuts.xml. Well, editing the xml is easy, but what is hard is deciding how to change the decimal number that all the search options are encoded into. Is there an easier way to do this and have some feeling of confidence that it has been done correctly?

  • @Alan-Kilborn

    other then hoping for completeness and relying on the list here - I don’t know.


  • @Claudia-Frank

    Hi Claudia, yes I knew about that list

  • @Alan-Kilborn

    This Pythonscript may help; I call it

    import re
    def decode1702__main():
        options_list = [
        input = '0'
        while True:
            input = notepad.prompt('Enter your 1702 decimal #:', '', input)
            if not input: return
            input = int(input)
            prompt_text = ''
            for (j, v) in enumerate(options_list):
                prompt_text += '[ {} ]{}      '.format('x' if input & (1 << j) else ' ', options_list[j])
                if (j + 1) % 3 == 0: prompt_text = prompt_text.rstrip() + '\r\n'
            prompt_text = prompt_text.rstrip()
            input = notepad.prompt('Set your desired options by putting an x inside the [   ], e.g. [ x ]:', '', prompt_text)
            if not input: return
            new_input = 0
            for (j, v) in enumerate(options_list):
                m ='[([^]]+)]' + options_list[j], input)
                if m and != ' ' * len( new_input |= 1 << j
            input = str(new_input)

    When run, it produces a prompt screen where you can put a 1702 parameter value that one of your macros uses, or you can just leave it set at 0. Pressing OK to that prompt will decode the entered values into the corresponding option values in a second prompt screen; example for an input of 3:

    From this point, changing the options and pressing OK will show you the decimal number associated with those options and you can keep going, changing the value or the options and seeing the effects until you answer Cancel to a prompt.

    Hope this helps you.

  • Nice. I like it. Regarding “downward”, the docs say “upward” but I think I remember reading here (maybe) that this is a bug in the docs…

  • It was discovered due to info in this thread that the . matches newline checkbox was missing from the above script. Simply inserting 'dot-matches-newline', after the line containing 'downward', will fix it, so it looks like this in the script:

    'dot-matches-newline',      # <---- add me!

  • Sorry, noob here.
    Why am I getting:

    C:\Program Files\Notepad++>
    Traceback (most recent call last):
    File “C:\Program Files\Notepad++\”, line 35, in <module>
    File “C:\Program Files\Notepad++\”, line 19, in decode1702__main
    input = notepad.prompt(‘Enter your 1702 decimal #:’, ‘’, input)
    NameError: name ‘notepad’ is not defined

    When I run this script?

  • @hoytpr

    Why am I getting…NameError: name ‘notepad’ is not defined…When I run this script?

    Because I am lazy when testing something I post. :-)

    Add this at the top of the script and I think it will fix it:

    from Npp import notepad

    What I do is have that line (or something similar) in my file–that file runs when Pythonscript starts up, obviously. This keeps me from having to put that line (and others that are similar, e.g., one for the editor object…) in every single Pythonscript file I have–the imports happen at startup and are available for the remainder of the Notepad++ session.

  • Awesome. Thanks. Are you as lazy as the noob who just says “help”? Probably not.
    Good idea to put it in the

Log in to reply