Is there a way to customize the status bar to display more helpful information?



  • when I select a text, I want to see the count of instances of this text to appear in the status bar, currently it just shows the number of selected characters and number of selected lines. Please point me to the resource which can help me customize the status bar.



  • @Haseeb-Afzal-Mohammed

    If you have the ability to program in Python (or possibly Lua?) then the answer is Yes, it is possible (via the PythonScript/LuaScript plugins). I show an example of how it can be done here, with Pythonscript: https://notepad-plus-plus.org/community/topic/13087/sel-in-status-bar-is-off-by-1-on-line-count/8

    A “count of instances of selected text” could cause a problem in really large files, as it would involve searching the entire file fairly often, which could take a great deal of TIME. If the files you deal with are relatively small, however, I would think this is very doable.



  • @Haseeb-Afzal-Mohammed

    If you are willing to use the Pythonscript plug-in (currently on 32-bit Notepad++ only), here’s a script that will enact your desired behavior. Running the script once will make it continue to work for the rest of the the Notepad++ session.

    Here’s SelectedTextOccurrenceCountInStatusBar.py:

    def SBROSMC(_):  # (S)tatus(B)ar(R)eporting(O)f(S)election(M)atch(C)ount
        if editor.getTextLength() < 10000:  # <---- limit functionality to files of this size or less!
            if editor.getSelections() == 1 and not editor.getSelectionEmpty():
                SBROSMC.match_count = 0
                def match_found(m): SBROSMC.match_count += 1
                def escape(s):
                    chars_to_escape = r'][.^$*+?(){}\\|-'
                    literal_backslash = '\\'
                    search_str = '([' + chars_to_escape + '])'
                    repl_str = literal_backslash * 3 + '1'
                    return re.sub(search_str, repl_str, s)
                editor.research(escape(editor.getSelText()), match_found)
                notepad.setStatusBar(STATUSBARSECTION.DOCTYPE, 'Count of selection matches: {}'.format(SBROSMC.match_count))
    
    editor.callback(SBROSMC, [SCINTILLANOTIFICATION.UPDATEUI])  # register callback
    

    and here’s what it looks like running:

    Note that due to what I mentioned before about how long this script could take to run for really large files, I limited it to file sizes of 10000 characters or less (totally arbitrary size selection, customize it at will to your situation).

    Also note that the light-blue highlighting in the sample screenshot is something else of my own devising and will NOT be done by the provided script. :-D

    If this (or ANY) posting was useful, don’t post a “thanks”, just upvote ( click the ^ in the ^ 0 v area on the right ).



  • Minor edit to the above:

    Here’s SelectedTextOccurrenceCountInStatusBar.py:

    should have been:

    Here’s StatusBarReportingOfSelectionMatchCount.py:


Log in to reply