Select variables with dollar sign ($) in PHP scripts
How can I select variables with dollar sign ($) in PHP scripts by double mouse click?
I saw in differnet blogs solutions about using macros or soft like Autohotkey, but all of them not so good for us :)
Can developers add this feature in NPP (for exaple like additional parameter in settings)?
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 + '$')
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
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’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?
@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.
Ah, I’m a bit out-of-date…I’ll try again with 6.9.2…
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.
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
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.
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
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
restart NPP - you’ll see in editor hello - it’s mean startup.py works.
Then replace all in startup.py on :
from Npp import *
additionalChars = ‘$’
chars = editor.getWordChars()
if additionalChars not in chars:
editor.setWordChars(chars + additionalChars)
notepad.callback(callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED ])
#sys.stdout = editor
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 $
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.
now there’s an option for that in Settings -> Preferences -> Delimiter, credits: http://stackoverflow.com/a/42545984/2006698