• Login
Community
  • Login

python script: additional chars and smarthighlight

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
9 Posts 3 Posters 4.1k 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.
  • G
    Gytis Mikuciunas
    last edited by Gytis Mikuciunas Nov 7, 2016, 9:42 AM Nov 7, 2016, 9:42 AM

    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

    S 1 Reply Last reply Nov 7, 2016, 4:57 PM Reply Quote 0
    • S
      Scott Sumner @Gytis Mikuciunas
      last edited by Nov 7, 2016, 4:57 PM

      @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
      • G
        Gytis Mikuciunas
        last edited by Nov 8, 2016, 5:38 AM

        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.

        S 1 Reply Last reply Nov 8, 2016, 1:02 PM Reply Quote 0
        • C
          cmeriaux
          last edited by Nov 8, 2016, 6:19 AM

          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
          • G
            Gytis Mikuciunas
            last edited by Nov 8, 2016, 12:25 PM

            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 :)

            S 1 Reply Last reply Nov 8, 2016, 1:12 PM Reply Quote 0
            • C
              cmeriaux
              last edited by Nov 8, 2016, 12:55 PM

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

              1 Reply Last reply Reply Quote 0
              • S
                Scott Sumner @Gytis Mikuciunas
                last edited by Nov 8, 2016, 1:02 PM

                @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
                • S
                  Scott Sumner @Gytis Mikuciunas
                  last edited by Nov 8, 2016, 1:12 PM

                  @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
                  • G
                    Gytis Mikuciunas
                    last edited by Nov 8, 2016, 1:22 PM

                    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
                    4 out of 9
                    • First post
                      4/9
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors