komodo.view.setFocus();
var ke = komodo.editor;
try {
var savePos = ke.currentPos;

if( ke.getColumn(savePos) == 0 ) {
return;
}

komodo.editor.wordLeftExtend();
var snippet = komodo.interpolate('%s');

var tmpl = komodo.findPart("snippet", snippet, "container");
if(tmpl) {

Snippet_insert(tmpl);


} else {
if( !AdvancedSnippet(snippet) ) {
ke.gotoPos(savePos);
var msg = "no snippet found named " + snippet;
StatusBar_AddMessage(msg,"debugger",5000,true);
}
}
} catch(e) {
alert(e);
}

function keywords(word) {
var m = word.match(/^sub(.*)/);

if( m ) {
return ['sub',m[1]];
}

m = word.match(/^ht(.*)/);
if( m ) {
return ['ht',m[1]];
}
}

function AdvancedSnippet(snippet) {

var keys = keywords(snippet);
var text = "";

if( keys ) {
snippet = keys[0];
text = keys[1];
} else {
return 0;
}

var tmpl = komodo.findPart("snippet", snippet, "container");
if(tmpl) {

Snippet_insert(tmpl);

if( text ) {
Find_ReplaceAllInMacro(window, 0, '<ReplaceMe>', text, false, 0, 1, false, false);

// Search for the cursor block
Find_FindNextInMacro(window, 0, '<Sel>.*</Sel>', 2, 1, false, false, find, false, true);
var block = komodo.interpolate('%s');

ke.clear();
var pos = ke.currentPos;
block=block.replace(/^<Sel>/,'').replace(/<\/Sel>$/,'');
ke.insertText(pos,block);
ke.setSel(pos, pos+block.length);
}
return 1;
}
return 0;
}