Hello, this is a revised script based on the one discussed at Snippets with macro. It auto-completes a block using a template for each flow control construct. Maybe it will be useful for others.
Also, can anyone can tell me why that parseInt() appears to be necessary? (if I just pass i itself, an empty template is used)
autoblock.js
The corresponding templates:
Also, can anyone can tell me why that parseInt() appears to be necessary? (if I just pass i itself, an empty template is used)
autoblock.js
Code: Select all
// index must match template number
templates = []
templates[0] = 'if'
templates[1] = 'else'
templates[2] = 'elif'
templates[3] = 'for'
templates[4] = 'while'
templates[5] = 'do'
templates[6] = 'switch'
function autoblock()
{
doc = UltraEdit.activeDocument;
col = doc.currentColumnNum;
if (typeof(UltraEdit.activeDocumentIdx) == "undefined") col++;
line = doc.currentLineNum;
doc.key('LEFT ARROW');
doc.selectWord();
keyword = doc.selection;
for(i in templates)
{
if(keyword == templates[i])
{
doc.key('DEL');
doc.gotoLineSelect(0, 1);
doc.insertTemplate(parseInt(i));
return;
}
}
doc.gotoLine(line, col);
UltraEdit.messageBox('No Match!');
}
autoblock()
Code: Select all
[$replace$]if(^)
[$replace$]{
[$replace$]
[$replace$]}
Code: Select all
[$replace$]else
[$replace$]{
[$replace$] ^
[$replace$]}
Code: Select all
[$replace$]else if(^)
[$replace$]{
[$replace$]
[$replace$]}
Code: Select all
[$replace$]for(^)
[$replace$]{
[$replace$]
[$replace$]}
Code: Select all
[$replace$]while(^)
[$replace$]{
[$replace$]
[$replace$]}
Code: Select all
[$replace$]do
[$replace$]{
[$replace$]
[$replace$]} while(^);
Code: Select all
[$replace$]switch(^)
[$replace$]{
[$replace$] case XXX:
[$replace$]
[$replace$] break;
[$replace$]
[$replace$] default:
[$replace$]
[$replace$] break;
[$replace$]}