PHP PORTABLE IDE: NppExec Configuration

From The Uniform Server Wiki
Revision as of 11:30, 2 December 2010 by Ric (talk | contribs) (New page: {{Uc nav PHP PORTABLE 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 comm...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

 

MPG UniCenter

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

  • The NppExec plugin installs an integrated console. Clicking Show console dialog toggles this console window.
  • From the console window you type in commands. or example Help is such a command.
  • To display all commands available type Help and press return .
  • To clear Console screen type cls and press return

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.

Top

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:

  • cls
  • echo $(FULL_CURRENT_PATH)
  • echo $(NPP_DIRECTORY)

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 ================

Top

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 ================

Top

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++

Top

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
- Clear console window
- Run currently displayed PHP script

Top

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:

  • Plugins>NppExec>Execute or Press key F6

  • Step A) Enter list of command to execute
  • Step B) Click Save button

  • Step C) Enter a name for command script eg run_php_cli
  • Step D) Click Save button
  • Click OK

Top

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

  • Open execute window Plugins>NppExec>Execute or Press key F6
  • Step E) From the drop-down menu select command script to run
  • Step F) Click OK to run script


Note: You can edit the command list, clicking OK will save any edits.

Top

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.

Create a menu item

  • Plugins>NppExec>Advanced Options..
  • Step A) From the drop-down menu select command script to run run_php_cli
  • Step B) Item name is automatically inserted. Changes this to Run as PHP CLI.
  • Step C) Click Add/Modify
  • Menu Items are automatically inserted.
  • Step D)Click OK


Note 1:

Restart Notepad++ check a new menu item Run as PHP CLI
is listed under Plugins>NppExec

You can click this item and run it.

Assign a menu item to a shortcut key

Final part is to assign a shortcut key to the command script run_php using the key mapper as follows:

Run Shortcut mapper

  • Settings>Shortcut Mapper opens a new window
  • Step A) Click Plugin commands
  • Step B) Navigate to Run as PHP CLI click to highlight
  • Step C) Click Modify button opens Shortcut pop-up window

Shortcut pop-up window

From this you can select various combination of keys.

  • Step D) I have selected Right All check boxes unchecked.
  • Step E) Click OK Saves settings and returns to Shortcut mapper.
  • Step F) Click Close .

Quick test:

Press the right arrow key check it runs the displayed PHP script.

Top

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

  • Plugins>NppExec>Console Output Filters>Highlight
    (or press SHIFT+F6)
  • Step A) Click HighLight tab
  • Step B) Check box enable filter
  • Step C) Enter mask %ABSFILE% on line %LINE%
  • Step D) Set Red: 00
  • Step E) Set Green: 00
  • Step F) Set Blue: 99
  • Step G) Check bold: B
  • Step H) Click OK

Quick check

  • Introduce an error in your script (or use test2.bat).
  • Click first line of test script
  • Run script (press right arrow key)
  • Double click highlighted line in console window
  • Script in edit window will now display error line highlighted.

Top

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


Top