PHP PORTABLE IDE: NppExec Configuration
US PHP IDE : Introduction | Notepad++ | Install PHP | NppExec Config | PHP extensions | Run Menu | XDebug 1 | Debugging 1 | XDebug 2 | Debugging 2
|
|
Uniform Server Portable PHP IDE. |
NppExec plugin configuration
The NppExec plugin executes either a single command or list of commands. Commands are similar to that typed in at a command line prompt. Each list of commands may be stored with a unique name for later use.
This page covers commands required to run PHP CLI scripts and how to assign a shortcut key to run a stored list of commands.
Background
Overview
If you have followed this tutorial from the beginning run the test script test.php by typing the following into the console window: C:\us_portable_ide\unicode\php\php.exe -n C:\us_notepad\php_scripts\test.php Result similar to this is displayed in the console window C:\us_portable_ide\unicode\php\php.exe -n C:\us_notepad\php_scripts\test.php C:\us_portable_ide\unicode\php\php.exe -n C:\us_notepad\php_scripts\test.php Process started >>> Test 123 <<< Process finished. ================ READY ================ |
Note: The NppExec plugin runs external programs directly and displays any output. Notice there is no need to open and display a file.
Copy and Paste (console window)
A console window does not allow copying and pasting using a mouse instead you use key combinations as follows.
- Copy – In the console window mark text to be copied using the mouse left button. Press Ctrl and C keys together text is coped to clipboard. This can be pasted as normal to another application or in text edit window.
- Paste – Text copied to the clipboard from another application or the text window is copied to the console window by pressing Ctrl and v keys together.
Environment variables
Running scripts directly is a tedious process in particular you need to enter a full path for both the executable and script. To the rescue, Environment variables we use the following variables and substitute as appropriate.
- $(FULL_CURRENT_PATH) - Path of currently displayed text file
- $(NPP_DIRECTORY) - The full path of Notepad++'s directory
To see these in action first open test.php in Notepad++
Enter the following commands in the console window:
Results as shown on right: |
echo $(FULL_CURRENT_PATH) C:\us_portable_ide\php_scripts\test.php ================ READY ================ echo $(NPP_DIRECTORY) C:\us_portable_ide\unicode ================ READY ================ |
Run Script Displayed
Using the above Environment variables we can run the script currently displayed in Notepad++
Substitute the absolute paths as shown below:
Original code:
C:\us_portable_ide\unicode\php\php.exe -n C:\us_notepad\php_scripts\test.php
Becomes:
$(NPP_DIRECTORY)\php\php.exe -n $(FULL_CURRENT_PATH)
Type the above line into console window result as shown:
$(NPP_DIRECTORY)\php\php.exe -n $(FULL_CURRENT_PATH) C:\us_portable_ide\unicode\php\php.exe -n C:\us_portable_ide\php_scripts\test.php Process started >>> Test 123 <<< Process finished. ================ READY ================
One more command
We want to automate the process ideally if the script has changed we want to automatically save any changes. This is accomplished using the following command:
- npp_save - save current file in Notepad++
Generic NppExec command script
The following sequence of commands is required to run a PHP script currently displayed in Notepad++:
NPP_SAVE cls $(NPP_DIRECTORY)\php\php.exe -n $(FULL_CURRENT_PATH) |
- Save current file |
Save NppExec command script
Typing above lines every time you want to run a script can be tiresome. NppExec allows you to save a list of commands and run them with a few key clicks. You can save a list of commands with a unique name allowing you to have several named command scripts.
Further automate the process by assigning a shortcut key to run a named command script.
The following shows how to create a command script, name it and assign a shortcut key. It allows you to run a PHP script currently displayed in Notepad++.
Create and Save a command script
Open Execute Window 1 Open execute script window as follows:
|
|
|
|
|
Run a command script
You can save any number of command scripts the following shows how to select and run a script.
Run Command script
|
Assign shortcut key
In order to assign a shortcut key a command script must first be assigned to a menu item. This menu item is then assigned to a shortcut key using the mapper.
Restart Notepad++ check a new menu item Run as PHP CLI You can click this item and run it. |
Final part is to assign a shortcut key to the command script run_php using the key mapper as follows:
Run Shortcut mapper
|
|
Shortcut pop-up window From this you can select various combination of keys.
Quick test: Press the right arrow key check it runs the displayed PHP script. |
NppExec Console Filters
Nppexec provides three Console Filters filter, replace and highlight.
The highlight filter is of particular interest. It scans console output for string matches and highlights that text.
Double clicking on highlighted text takes you to that line in a script.
For example this line is a reported error from a PHP script:
Fatal error: Call to undefined function phpinfo_zzz() in C:\us_portable_ide\php_scripts\test2.php on line 5
Setting a highlight mask with the following format
%ABSFILE% on line %LINE%
Will highlight lines that match.
Highlight filter configuration
Open filter window
Quick check
|
Summary
At this stage we have a working PHP CLI IDE it runs scripts, highlights errors and provides the ability to jump to that error line in the edit window.
Currently it is configured to run with no PHP extensions enabling these are covered on the next page.
This IDE allows you to run a displayed PHP script in one of three ways as follows:
- Press right arrow key
- Press F6 select Run as PHP CLI click OK
- Plugins>NppExec>Run as PHP CLI