Welcome, guest | Sign In | My Account | Store | Cart

A Komodo JavaScript macro that can be used to wrap the current word under the cursor position (or current selection) with arbitrary text.

For example, if I'm editing a HTML file and have the selected text "This is my heading", I can quickly use this macro to wrap this text into "<h1>This is my heading</h1>".

JavaScript, 26 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var view = ko.views.manager.currentView;
var scimoz = view.scimoz;
var currentWord = ko.interpolate.getWordUnderCursor(scimoz);
if (currentWord) {
    var snippetText = '[[%tabstop1:"]][[%w]][[%tabstop1]]';
    var langName = view.languageObj.name.toLowerCase();
    if (langName.indexOf("html") >= 0 ||
        langName.indexOf("xml") >= 0) {
        // Add tags around the text.
        snippetText = '<[[%tabstop1:div]]>[[%w]]</[[%tabstop1]]>';
    }
    var fakeSnippet = {
            hasAttribute: function(name) {
                    return name in this;
            },
            getStringAttribute: function(name) {
                    return this[name];
            },
            name: "autowrap snippet",
            indent_relative: "true",
            value: snippetText
    };
    ko.projects.snippetInsert(fakeSnippet);
} else {
    ko.statusBar.AddMessage("Nothing under the cursor to wrap.", "editor", 5000, true);
}

2 comments

David Caro 10 years, 7 months ago  # | flag

HOw I install that Komodo Macro?

Todd Whiteman (author) 10 years, 7 months ago  # | flag