Community
    • Login

    Old Pythonscript stopped working

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 411 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.
    • Bérci RóbertB
      Bérci Róbert
      last edited by

      Hello
      I had an old script from here for Pythonscript(1.3.0.0) witch was working fine till Notepad++ reached 7.7.
      I’m in need of this function once more and can’t get it to work.
      I’m not a huge Python guru so pls help.

      The original source of the script:
      https://community.notepad-plus-plus.org/topic/14992/show-count-of-occurrences-of-a-selected-string

      Cheers

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Bérci Róbert
        last edited by

        @Bérci-Róbert

        I don’t know about the script that stopped working, but I’d be inclined to do it this way instead; make it an on-demand thing (tied to a keycombo to run it):

        # -*- coding: utf-8 -*-
        
        from Npp import editor, notepad
        
        def main():
            matches = []
            if editor.getSelections() == 1 and not editor.getSelectionEmpty():
                try:
                    editor.research(r'\Q' + editor.getSelText() + r'\E', lambda m: matches.append(1))
                except:
                    matches = []
                notepad.messageBox('{} occurrence(s) of selected text'.format(len(matches)), '')
        
        main()
        

        Note: Definitely borrows heavily from the linked-to posting’s script.

        1 Reply Last reply Reply Quote 1
        • Bérci RóbertB
          Bérci Róbert
          last edited by

          @Alan-Kilborn
          I really liked that I only needed to double tap the variable names and see if it was used or just declared.
          Your’s works but can you work it with the double click highlights and no extra commands needed?

          1 Reply Last reply Reply Quote 0
          • EkopalypseE
            Ekopalypse
            last edited by

            If you are using a newer npp version you need to update the python
            script plugin version as well as the newer npp version did introduce
            a newer and changed scintilla version which affected the notification structure.
            Depending on your currently used version of npp the installation procedure is different but if you are using the most recent version,
            you should be able to reinstall PS via the plugin admin.

            a47d2550-424d-4edb-b102-1a4476c7b5a4-image.png

            1 Reply Last reply Reply Quote 2
            • Bérci RóbertB
              Bérci Róbert
              last edited by

              @Ekopalypse
              Thanks. That did the trick.

              1 Reply Last reply Reply Quote 2
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors