rcook:
--------------------------------------------------------------------------------
I am a computer programmer, expert in a  couple of languages and competent in a
few more.  I cannot figure out how to write and execute scripts for PSPad.

I want to write a simple script and execute it with a keystroke.  To start with,
I'd like a keystroke to delete the line where the cursor currently is.

I have been searching for a couple of hours now and still have not found how to
do basic steps.  I've found some example scripts, and some reference material on
available commands, but still don't know how to use them.  I'm expecting to do
something like:

1. write the script (I have examples for that, though instruction would be
better)
2. put the script somewhere (I gather there are directories for each script
language,
is that the only place such things can be stored?)
3. compile the script
4. run the script
5. attach the running of the script to the desired key somehow.

Where do I find these basic instructions?
--------------------------------------------------------------------------------


Hi,
you can check a sample script (JavaScript) posted some time ago in a similar
context
(at the end of the post:
http://forum.pspad.com/read.php?2,63362,63363#msg-63363
also copied below:

note, that the actual "working logic" isn't all that useful - the respective
functionality is built in pspad itself, as has been mentioned already, but you
can see the basic parts of the script:

cite:
--------------------------------------------------------------------------------
var module_name = "test_js_3"; // neccessary unique script identifiers
var module_ver = "0.1";

function cut_line(){ // custom function definition (without parameters)
if (editorsCount()<1){return;} // quit if no text window is open 
var actEd = newEditor(); // editor object for use with scripting
actEd.assignActiveEditor(); // assigning to the active editor

// script logic ...
actEd.command('ecLineStart'); // e.g. some predefined editor commands
actEd.command('ecLineStart'); //repeated call in case smart "Home" feature ist
active (disregarding starting whitespace)
actEd.command('ecSelLineEnd'); // select the line including the line ending
actEd.command('ecCut');
actEd.command('ecDeleteChar');//delete the immediately following line ending (if
present)
// ... editor functions as listed in the scripting readme doc 
// or general javascript computations etc. are also available ... 

}

function Init(){ // special function for creating the menu labels and assigning
the keyboard shortcuts to the defined functions 
addMenuItem("cut current line to clipboard", "", "cut_line", "Ctrl+Alt+A");//
labels and shortcuts can be modified
}
--------------------------------------------------------------------------------


This script file should be saved in the respective folder, e.g. as
...\PSPad\Script\JScript\test_js.js
you can call the function from the Scripts menu (the second parameter of
addMenuItem is an optional submenu name) or with the defined shortcuts (they
must not be used elsewhere in PSPad - globsally or in the program itself or in
file templates or other scripts).   

All scripts are compiled internally on each startup of PSPad or manually after
calling Scripts: Recompile scripts

Hth,
   vbr

-- 
<http://forum.pspad.com/read.php?2,65639,65648>
PSPad freeware editor http://www.pspad.com

Odpovedet emailem