ActiveState Community

Snippets: problem with TabStops

Posted by nat on 2007-08-14 14:10

Hello, I noticed a problem with TabStops with this kind of snippet :

connect([[%tabstop:toggled]], [[%tabstop:test]])

If I select this section : [[%tabstop:toggled]] and choose to maintain cursor position, when I insert the snippet, the good section will be selected, however, pressing tab will delete the text instead of keeping the default text and jumping to the next Tabstop.

So basically I have not been able to setup the snippet so that the first TabStop is selected upon insertion and maintain the normal behavior of TabStop.

Thanks,

Nat

jeffg | Tue, 2007-08-14 14:43

The 'initial selection' behavior you want isn't quite possible with tabstops in the current version. My advice instead would be to:

- *not* select any text in the snippet
- get used to hitting TAB once after inserting the snippet

--
JeffG

nat | Tue, 2007-08-14 18:08

Thanks for your answer.
As a workaround I added the tab command in the Trigger macro instead, it works though it adds a tab to snippets without tabstops. Any way I can detect from a macro if a snippet contains tabstops ?

Thanks,

Nat

toddw | Tue, 2007-08-14 16:22

Note: There is a request to have the tabstops auto-select the first tabstop feature within Komodo:
http://bugs.activestate.com/show_bug.cgi?id=71330

jeffg | Wed, 2007-08-15 09:11

In trigger I get a handle on the Snippet as the variable 'tmpl'. The snippet has the property 'value' IIRC which contains the string of the snippet itself. You could do something like:

var rx = /«/g;
if(rx.test(tmpl.value)) {
    // we have a tabstop
}
var rx = /«/g;
if(rx.test(tmpl.value)) {
    // we have a tabstop
}

That *might* work, I'll dig more into this when I get into the office this morning. Cool idea!

--
JeffG

jeffg | Wed, 2007-08-15 10:43

So the code I came up with is:

komodo.view.setFocus();
try {
    komodo.editor.wordLeftExtend();
    var name = komodo.interpolate('%s');
    var snippet = komodo.findPart("snippet", name, "container");
    if(snippet) {
        Snippet_insert(snippet);
        var rx = /(«|\%tabstop\:)/g; if (rx.test(snippet.value)) {
            ko.commands.doCommand('cmd_indent');
        }
    } else {
        var msg = "no snippet found named " + snippet;
        StatusBar_AddMessage(msg,"debugger",5000,true);
    }
} catch(e) {
    alert(e);
}
komodo.view.setFocus();
try {
    komodo.editor.wordLeftExtend();
    var name = komodo.interpolate('%s');
    var snippet = komodo.findPart("snippet", name, "container");
    if(snippet) {
        Snippet_insert(snippet);
        var rx = /(«|\%tabstop\:)/g; if (rx.test(snippet.value)) {
            ko.commands.doCommand('cmd_indent');
        }
    } else {
        var msg = "no snippet found named " + snippet;
        StatusBar_AddMessage(msg,"debugger",5000,true);
    }
} catch(e) {
    alert(e);
}

I was slightly worried that JS's regular expressions would have problems with the '«' chevron character, but it seems to work quite well (in UTF-8, anyway);

Note: I've posted a toolbox package for this here:

http://community.activestate.com/forum-topic/trigger-now-tabstop-support

--
JeffG

nat | Wed, 2007-08-15 11:03

Hello Jeff, thanks for the update.
I just tried this on my Linux machine and it doesn't seem to add the tab, I still need to manually tab. That's with python code and the following snippet :
connect([[%tabstop:toggled]], [[%tabstop:test]])

thanks,

Nat

jeffg | Wed, 2007-08-15 14:10

Sorry, I was using an old snippet to test, it should work now with any snippet that uses tabstops. I've corrected the original code, above, and replaced the toolbox package in the other post.

--
JeffG

nat | Wed, 2007-08-15 14:20

Thanks a lot !!