One of the few areas where UE is sub-par (IMHO) is the lack of automatic language-specific templates. This has already been discussed somewhere else (see http://www.ultraedit.com/forums/viewtopic.php?t=1412), so there's no need to go into that.
Anyway, given UE's scripting capabilities I should be able to DIY this. I have duly written a small script that expands stuff nicely (though it's more a proof of concept). I have put this on the space key as hotkey which means it's called every time I press space. The script itself is fast enough not to make a nuisance of itself but of course now this annoying box to cancel the script flashes up all the time. Does anyone know of a way how to disable this box? (I know I can do that for macros so it seems not too far-fetched an idea to have this for scripts as well.)
I am having a second, more fundamental problem with that script. The template to be expanded is written with UltraEdit.activeDocument.write(). Unfortunately, this function, if handed a multi-line string, will not perform any auto-indenting. Any hints how to achieve this?
Here's my attempt (pared-down to the bare minimum) so far. (The spaces written in various places are there because I have put the script on the space key as hotkey, so whenever no template is expanded a space is written instead.)
I am not a JavaScript guy, so general hints as to how to make this better/faster are welcome as well.
Anyway, given UE's scripting capabilities I should be able to DIY this. I have duly written a small script that expands stuff nicely (though it's more a proof of concept). I have put this on the space key as hotkey which means it's called every time I press space. The script itself is fast enough not to make a nuisance of itself but of course now this annoying box to cancel the script flashes up all the time. Does anyone know of a way how to disable this box? (I know I can do that for macros so it seems not too far-fetched an idea to have this for scripts as well.)
I am having a second, more fundamental problem with that script. The template to be expanded is written with UltraEdit.activeDocument.write(). Unfortunately, this function, if handed a multi-line string, will not perform any auto-indenting. Any hints how to achieve this?
Here's my attempt (pared-down to the bare minimum) so far. (The spaces written in various places are there because I have put the script on the space key as hotkey, so whenever no template is expanded a space is written instead.)
I am not a JavaScript guy, so general hints as to how to make this better/faster are welcome as well.
Code: Select all
var d=UltraEdit.activeDocument,
exp_C={
'if':'if (!!) {\n}\nelse {\n}',
'for':'for (!!;;) {\n}'
};
function writeExp(exp,l,c) {
if (typeof(exp)==='undefined') { // no template, write space
d.gotoLine(l,c);
d.write(' ');
}
else { // template, write it
d.write(exp);
d.gotoLine(l,c);
d.findReplace.find("!!");
}
}
function getWordLeft() {
d.startSelect();
d.key('CTRL+LEFT ARROW');
d.endSelect();
return d.selection;
}
function isCFile() {
return d.isExt('c')||d.isExt('cpp')||d.isExt('h');
}
var l=d.currentLineNum,c=d.currentColumnNum;
if (typeof(UltraEdit.activeDocumentIdx) == "undefined") c++;
if (d.isSel()||c===1||d.isChar(' ')) d.write(' '); // can't be a template
else if (isCFile()) writeExp(exp_C[getWordLeft()],l,c);
//else if (isPerlFile()) writeExp(exp_Perl[getWordLeft()],l,c)
else d.write(' '); // no source file, no template