Old Pythonscript stopped working



  • 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



  • @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.



  • @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?



  • 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



  • @Ekopalypse
    Thanks. That did the trick.


Log in to reply