Community
    • Login

    python script: additional chars and smarthighlight

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    9 Posts 3 Posters 5.0k Views 2 Watching
    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.
    • Gytis MikuciunasG Offline
      Gytis Mikuciunas
      last edited by Gytis Mikuciunas

      Hi,

      I’m using python script plugin and it works quite well for my basic usage.

      What I want to do, is to highlight word/string with the mouse double click and use smart highlighter to colorize all the same words/strings in text on the same tab.

      As I’m using additional chars and this script, smart highlighter doesn’t work for words with additional chars:

      def extendWordChar():
      additionalChars = ‘:._-’
      chars = editor.getWordChars()
      if additionalChars not in chars:
      editor.setWordChars(chars + additionalChars)

      def callback_READY(args):
      extendWordChar()

      def callback_BUFFERACTIVATED(args):
      extendWordChar()

      notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED ])
      notepad.callback(callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED ])
      notepad.callback(callback_READY, [NOTIFICATION.READY ])

      thx in advance

      Scott SumnerS 1 Reply Last reply Reply Quote 0
      • Scott SumnerS Offline
        Scott Sumner @Gytis Mikuciunas
        last edited by

        @Gytis-Mikuciunas

        I find that if I execute the following code, then double-clicking anywhere in the comment line smart-highlights everything between the first ‘a’ and the final ‘e’…so it appears to work for me:

        new_word_chars = '-:.'
        for c in new_word_chars:
            if c not in editor.getWordChars(): editor.setWordChars(editor.getWordChars() + c)
        # abc-def-ghi.aaaa:eeeee
        
        1 Reply Last reply Reply Quote 0
        • Gytis MikuciunasG Offline
          Gytis Mikuciunas
          last edited by

          Hi Scott,

          Script that I’m using and your script highlights word/string.

          But notepad++'s feature “smart highlighter” highlights (green color by default) all the same words/strings in current tab. And it doesn’t work for words/strings with my additional chars.
          So I need to force it somehow via python script I guess.

          Scott SumnerS 1 Reply Last reply Reply Quote 0
          • cmeriauxC Offline
            cmeriaux
            last edited by

            hello @Gytis-Mikuciunas
            have you try the function “Search”/“mark all”/“using 1st style” (or other style) or through the contextual menu “style token”/“using 1st style” (could be map to a shortcut)
            It’s highlight whatever you want including your extended word chars

            1 Reply Last reply Reply Quote 0
            • Gytis MikuciunasG Offline
              Gytis Mikuciunas
              last edited by

              This is not a solution for me to use shortcuts etc.

              If it’s working by default why I need to do manual searching, marking.
              very handy when you double-click on some word or string and can see immediately if it repeats somewhere.

              I hope that Claudia Frank will look into my posts :) She always has good script related ideas and solutions :)

              Scott SumnerS 1 Reply Last reply Reply Quote 0
              • cmeriauxC Offline
                cmeriaux
                last edited by

                You can mention Claudi Franck directly so that he’ll get a notification
                @Claudia-Frank

                1 Reply Last reply Reply Quote 0
                • Scott SumnerS Offline
                  Scott Sumner @Gytis Mikuciunas
                  last edited by

                  @Gytis-Mikuciunas

                  Adding more copies of the pseudo-word from my little test script to the editor window and then getting the smart highlighter to invoke…turns bright green ALL copies of the same pseudo-word string.

                  I seem to recall some problem/issue with setting the word characters with an earlier version of N++; I think it was @dail that pointed this out to me in a posting that I can’t find at the moment. I’m currently running N++ 7.1 x86 and this type of word-character change in combination with the Smart Highlighting works there.

                  1 Reply Last reply Reply Quote 0
                  • Scott SumnerS Offline
                    Scott Sumner @Gytis Mikuciunas
                    last edited by

                    @Gytis-Mikuciunas

                    I found the posting I mentioned: https://notepad-plus-plus.org/community/topic/12186/select-variables-with-dollar-sign-in-php-scripts

                    @dail indicated there that the version must be > 6.8.3
                    As that is quite old, I’ll presume that you are running something newer and that there is some other reason for your trouble…I just don’t know what it is.

                    1 Reply Last reply Reply Quote 2
                    • Gytis MikuciunasG Offline
                      Gytis Mikuciunas
                      last edited by

                      Scott, you’re right.
                      I have updated my noteped++ to the newest version and now it works as expected.

                      thx a lot!!!

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • First post
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors