• Login
Community
  • Login

Search/replace macro options change, easier way?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
9 Posts 4 Posters 5.0k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A
    Alan Kilborn
    last edited by Dec 16, 2017, 4:57 PM

    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?

    C S 2 Replies Last reply Dec 16, 2017, 5:02 PM Reply Quote 0
    • C
      Claudia Frank @Alan Kilborn
      last edited by Dec 16, 2017, 5:02 PM

      @Alan-Kilborn

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

      Cheers
      Claudia

      A 1 Reply Last reply Dec 16, 2017, 5:32 PM Reply Quote 0
      • A
        Alan Kilborn @Claudia Frank
        last edited by Dec 16, 2017, 5:32 PM

        @Claudia-Frank

        Hi Claudia, yes I knew about that list

        1 Reply Last reply Reply Quote 0
        • S
          Scott Sumner @Alan Kilborn
          last edited by Dec 17, 2017, 4:03 AM

          @Alan-Kilborn

          This Pythonscript may help; I call it 1702decoder.py:

          import re
          
          def decode1702__main():
              options_list = [
                  'whole-word',
                  'case-match',
                  'clear-red-presearch',
                  'UNUSED',
                  'bookmark-line',
                  'subfolders',
                  'hidden',
                  'in-sel',
                  'wrap',
                  'downward'
                  ]
              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 = re.search(r'\[([^]]+)\]' + options_list[j], input)
                      if m and m.group(1) != ' ' * len(m.group(1)): new_input |= 1 << j
                  input = str(new_input)
          
          decode1702__main()
          

          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.

          1 Reply Last reply Reply Quote 2
          • A
            Alan Kilborn
            last edited by Dec 19, 2017, 11:34 PM

            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…

            1 Reply Last reply Reply Quote 0
            • S
              Scott Sumner
              last edited by May 4, 2018, 8:31 PM

              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:

              'downward',
              'dot-matches-newline',      # <---- add me!
              ]
              
              1 Reply Last reply Reply Quote 1
              • H
                hoytpr
                last edited by Jun 25, 2018, 2:48 PM

                Sorry, noob here.
                Why am I getting:

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

                When I run this script?

                S 1 Reply Last reply Jun 25, 2018, 4:06 PM Reply Quote 1
                • S
                  Scott Sumner @hoytpr
                  last edited by Scott Sumner Jun 25, 2018, 4:07 PM Jun 25, 2018, 4:06 PM

                  @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 startup.py 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.

                  1 Reply Last reply Reply Quote 2
                  • H
                    hoytpr
                    last edited by Jun 25, 2018, 6:35 PM

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

                    1 Reply Last reply Reply Quote 1
                    • A Alan Kilborn referenced this topic on Jan 11, 2023, 2:56 PM
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors