Community
    • Login

    Select variables with dollar sign ($) in PHP scripts

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    12 Posts 6 Posters 8.0k 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.
    • Claudia FrankC
      Claudia Frank @Максим Милостивый
      last edited by

      @Максим-Милостивый

      php lexer doesn’t define dollar sign to be a word character.
      You can manipulate it, with e.g. python script plugin, lua script, nppexec
      if you have one of them already installed.
      What you need to do is would be something like (python example)

      c = editor.getWordChars()
      editor.setWordChars(c + '$')
      

      Cheers
      Claudia

      1 Reply Last reply Reply Quote 1
      • Максим МилостивыйМ
        Максим Милостивый
        last edited by Максим Милостивый

        I’m install python script plugin (by msi, not plugin manager), make python script with your two lines, try to run it, but nothing happing

        in console see
        Python 2.7.6-notepad++ r2 (default, Apr 21 2014, 19:26:54) [MSC v.1600 32 bit (Intel)]
        Initialisation took 78ms
        Ready.

        It’s look like script not running.
        In configuration set ATTSTARTUP, put startup.py in NPP direcory. And add this script on tool bar, try to push icon. Restart NPP some times.
        But always can’t select variables with $
        Maybe I make something wrong?

        Claudia FrankC 1 Reply Last reply Reply Quote 0
        • Scott SumnerS
          Scott Sumner
          last edited by

          Claudia’s suggestion works for me. I did it and tested with help and $help
          Double-clicking each selected the complete text of each…however, when I double-clicked “help” N++ highlighted it in greeen, and when I double-clicked “$help” it became highlighted in grey…why the difference?

          dailD 1 Reply Last reply Reply Quote 0
          • dailD
            dail @Scott Sumner
            last edited by

            @Scott-Sumner What version of N++ are you using? v6.9.2 works fine for me when I used LuaScript to do:

            editor.WordChars = editor.WordChars .. '$'
            

            Which is equivalent to what Claudia posted.

            1 Reply Last reply Reply Quote 0
            • Scott SumnerS
              Scott Sumner
              last edited by

              Ah, I’m a bit out-of-date…I’ll try again with 6.9.2…

              1 Reply Last reply Reply Quote 0
              • dailD
                dail
                last edited by

                I think you’ll need a version > 6.8.3. It looks like there was an issue with the smart highlighter not respecting plugins setting a custom list of word chars. See this commit.

                1 Reply Last reply Reply Quote 0
                • Claudia FrankC
                  Claudia Frank @Максим Милостивый
                  last edited by Claudia Frank

                  @Максим-Милостивый

                  first let’s see if the installation was successful.

                  Open the python script console (Plugins->Python Script->Show Console)
                  Type the following command into the textbox next to the Run button in the console

                  dir(editor)
                  

                  Does it return a list of properties and functions? (one line)

                  ['WHOLEDOC', '__class__', '__delattr__', ...]
                  

                  If so, then installation seems to be ok.

                  Next, don’t move startup.py leave it where it is/was.
                  The changes you made are useful and should take place after npp restart.

                  In regards to the script, you need to execute it after you have opened the php file.
                  If you open another php script you need to run it again.
                  One possible solution to overcome this flaw is to register a callback for BUFFERACTIVATED notification.
                  A script could look like this

                  def extendWordChar():
                      additionalChars = '$'
                      chars = editor.getWordChars()
                      if additionalChars not in chars:
                          editor.setWordChars(chars + additionalChars)
                  
                      
                  def callback_BUFFERACTIVATED(args):
                      extendWordChar()
                  
                  notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED ])
                  notepad.callback(callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED ])
                  

                  Whenever you switch a document, regardless if it is a php or any other type of file, it gets executed,
                  checks if the additional char is already part of the word chars and if not adds it to it.

                  Don’t know if you know something about python language already, but make sure your
                  code looks the same as posted - indention is important.

                  Cheers
                  Claudia

                  1 Reply Last reply Reply Quote 0
                  • Максим МилостивыйМ
                    Максим Милостивый
                    last edited by

                    Thank’s very much!!! All works good now!!!
                    I know that indention so important in python )) Many years ago try to make several scripts ))
                    Trouble was in directory, where I create startup.py. First I create file from menu “File->New” and save as .py. in Notepad++ directory
                    That why Python can not find and run my script (it so strange that python don’t give errors or warnings)
                    When I create file from python plugin menu it save automaticaly in “…\Notepad++\plugins\PythonScript\scripts”
                    After that python can see this script and can run it.

                    PS Sorry for my English, I’m from Russia

                    1 Reply Last reply Reply Quote 0
                    • Алексей МилостивыйА
                      Алексей Милостивый
                      last edited by

                      Good News! It’s no need now to download and install python from internet.

                      You can download NPP, then from plugin manager download Python script
                      In python configuration set ATTSTARTUP
                      Find startup.py (“C:\Program Files (x86)\Notepad++\plugins\PythonScript\scripts\startup.py” )
                      add at the end
                      print “hello”
                      restart NPP - you’ll see in editor hello - it’s mean startup.py works.
                      Then replace all in startup.py on :

                      import sys
                      from Npp import *

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

                      def callback_BUFFERACTIVATED(args):
                      extendWordChar()

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

                      #sys.stdout = editor
                      #print “Hello”

                      Two lines at the end need only for checking how script works.
                      Restart NPP, open any file (it’s important, only in opened files will work selecting) and try to select something with sign $

                      Claudia FrankC 1 Reply Last reply Reply Quote 0
                      • Claudia FrankC
                        Claudia Frank @Алексей Милостивый
                        last edited by

                        @Алексей-Милостивый

                        be careful - there were too many posts that it doesn’t work when installing from plugin manager.
                        I would still prefer the installation via msi package.

                        And instead of overwriting the standard startup.py file I would create a user startup.py script.
                        It gets executed after the standard one.

                        Cheers
                        Claudia

                        1 Reply Last reply Reply Quote 0
                        • Carlo CampinotiC
                          Carlo Campinoti
                          last edited by

                          now there’s an option for that in Settings -> Preferences -> Delimiter, credits: http://stackoverflow.com/a/42545984/2006698

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          The Community of users of the Notepad++ text editor.
                          Powered by NodeBB | Contributors