Gorlash:
--------------------------------------------------------------------------------
I want a "delete line" function which copies the deleted line to clipboard, so
I can paste it elsewhere using Ctrl-V.
I tried copying Serge Balance's "del_end_best" script, and changing it to my
requirements, which I'll show below... I created a JScript directory under
pspad/scripts, and copied my script there, but it does not seem to be attached
to Ctrl-K as it should be.
Obviously I'm missing a key step in this process; any guidance (including
pointers to a relevant doc for doing this) are welcome!
My new script/extension:
// JavaScript Document
//*****************************************************************************
// filename : clip_line.js
// description: Delete line to clipboard
// created : 10/01/14 14:35:44
// author : Daniel D Miller
//
// You may distribute this script freely, but please keep this header
intact.
//*****************************************************************************
var MODULE_NAME = "clip line";
var MODULE_VER = "0.1";
var MODULE_TITLE = "Delete line to clipboard";
function Init() {
menuName = "&" + MODULE_NAME;
subMenu = "&" + "Edit";
addMenuItem(menuName, subMenu, "main", "CTRL+K");
}
function main() {
var ed = neweditor();
ed.assignActiveEditor();
ed.command('ecLineStart');
ed.command('aCopyLine');
ed.command('ecDeleteLine');
}
--------------------------------------------------------------------------------
Hi,
there are several problem areas to look into:
I believe, MODULE_NAME and MODULE_VER should be all lowercase now (maybe there
were some differences in older versions).
neweditor() should be newEditor()
I am not sure, whether prepending the ampersand like "&" + "Edit" ... has any
effect, scripts are probably designed to be accessed via menu shortcuts rather
than menu accelerators, but I may be wrong.
Only commands starting with "ec..." can be called as Editor Commands
ed.command('ecLineStart');
those with "a..." are aplication wide commands of PSPad and are run using the
global function:
runPSPadAction('aCopyLine')
howewer, in this case it won't work as intended - "copy line" is a function
which duplicates the current line directly in the editor and doesn't use the
clipboard.
The shortcut keys should be tested for possible collisions with some already
assigned functions - this part is rather tricky - generally, if your script
works ok, if you call it from the menu, but not if using the shortcut - there is
most likely some colliding functionality with the same shortcut.
There are several places to look - windows-wide shortcuts (like F1), program
shortcuts (these can be seen in the menus and in the setting: key map), clip
definition files (like Ctrl+I) in HTML clip (the currently active file format is
relevant) and finally the scripts themselves which assign the shortcuts in the
Init() function.
Furthermore, it is generally useful to check for a cornercase, when the script
is called with no editor windows open (ed.assignActiveEditor() will cause an
error in this case).
I ended up with the following basic code, which might satisfy your requirements
(there are possible differences in handling the trailing newline - this version
doesn't include it in the selection, but deletes it afterwards (of course it can
be tweaked for a different way and special-case the last line of the text):
cite:
--------------------------------------------------------------------------------
var module_name = "test_js_3";
var module_ver = "0.1";
function cut_line(){
if (editorsCount()<1){return;} // quit if no text window is open
var actEd = newEditor();
actEd.assignActiveEditor();
actEd.command('ecLineStart');
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)
}
function Init(){
addMenuItem("cut current line to clipboard", "", "cut_line", "Ctrl+Alt+A");//
labels and shortcuts can be modified
}
--------------------------------------------------------------------------------
hth,
vbr
--
<http://forum.pspad.com/read.php?2,63362,63363>
PSPad freeware editor http://www.pspad.com