You are here: PSPad forum > English discussion forum > basic scripting instructions

basic scripting instructions

#1 basic scripting instructions

Posted by: rcook | Date: 2015-08-07 00:19 | IP: IP Logged

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?

Options: Reply | Quote | Up ^


#2 Re: basic scripting instructions

Posted by: pspad | Date: 2015-08-07 04:22 | IP: IP Logged

If you want to delete current line, press Ctrl+Y (for more shortcuts press F1 and look into help)

In the script call PSPad command ecDeleteLine. Somthing like for VBScript:

set obj = NewEditor()
obj.assignActiveEditor()
obj.command("ecDeleteLine")

Options: Reply | Quote | Up ^


#3 Re: basic scripting instructions

Posted by: vbr | Date: 2015-08-07 10:53 | IP: IP Logged

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:
forum.pspad.com
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:

Quote:
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

Options: Reply | Quote | Up ^


#4 Re: basic scripting instructions

Posted by: pspad | Date: 2015-08-07 11:18 | IP: IP Logged

VBR, why didn't you use the ecDeleteLine command instead of your complicated code?

Options: Reply | Quote | Up ^


#5 Re: basic scripting instructions

Posted by: vbr | Date: 2015-08-07 12:12 | IP: IP Logged

pspad:
VBR, why didn't you use the ecDeleteLine command instead of your complicated code?

Hi, at the time I wrote the original answer some time ago, I thought, to "cut the line" was meant for "cut to the clipboard" - I am not sure this was needed, but in the current post I just reused the code to show some parts of the script.
vbr

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR