Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

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

    Help wanted · · · – – – · · ·
    status bar customize
    2
    4
    2601
    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.
    • Haseeb Afzal Mohammed
      Haseeb Afzal Mohammed last edited by Haseeb Afzal Mohammed

      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.

      Scott Sumner 2 Replies Last reply Reply Quote 0
      • Scott Sumner
        Scott Sumner @Haseeb Afzal Mohammed last edited by Scott Sumner

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

        1 Reply Last reply Reply Quote 0
        • Scott Sumner
          Scott Sumner @Haseeb Afzal Mohammed last edited by

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

          Scott Sumner 1 Reply Last reply Reply Quote 3
          • Scott Sumner
            Scott Sumner @Scott Sumner last edited by

            Minor edit to the above:

            Here’s SelectedTextOccurrenceCountInStatusBar.py:

            should have been:

            Here’s StatusBarReportingOfSelectionMatchCount.py:

            1 Reply Last reply Reply Quote 0
            • Referenced by  sharkwsk sharkwsk 
            • Referenced by  Dimitri Sudomoin Dimitri Sudomoin 
            • First post
              Last post
            Copyright © 2014 NodeBB Forums | Contributors