Question

In many other editors, when you record a macro you can run that macro repeatedly. However, in Komodo Edit there is not an option to do so. In Komodo Edit, how do you repeat a macro X times, or repeat a macro to the end of a file?

NotePad++ lets you repeat a macro

NotePad++ lets you repeat a macro

Komodo Edit doesn't have that option in the menu

Komodo Edit doesn't have that option in the menu

Was it helpful?

Solution 2

Here's how to do it in a macro (I call mine "Run current macro to end of file"):

var currentMacro = ko.macros.recorder.currentMacro;
if (!currentMacro || !currentMacro.length) {
    alert("There is no current macro to execute");
    return;
}
var view = ko.views.manager.currentView;
var scimoz = view.scimoz;
var startingLine = scimoz.lineFromPosition(scimoz.currentPos);
var i = 1;
scimoz.beginUndoAction();
try {
    while (true) {
        ko.macros.recorder.executeLastMacro();
        let newPos = scimoz.currentPos;
        let newLine = scimoz.lineFromPosition(newPos);
        if (newLine <= startingLine) {
            newLine = startingLine + 1;
        }
        startingLine = newLine;
        if (startingLine >= scimoz.lineCount) {
            break;
        }
        scimoz.gotoPos(scimoz.positionFromLine(startingLine));
    }
} finally {
    scimoz.endUndoAction();
}

You can also have macros invoke other macros, but that's a bit more complicated.

OTHER TIPS

You can repeat a macro X amount of times by using the "Code > Repeat Next Keystroke N Times" menu item. There is no option to repeat the current macro until the end of the file, however an enhancement request has been logged for this (which I've just bumped and hope to see in our next major release): http://bugs.activestate.com/show_bug.cgi?id=76022

First record a macro. (with single action).
Edit the source code of macro (using JavaScript or Python) Example: Text File
abc
abc
abc
abc
abc
abc
abc
abc
abc

Recorded macro code:

komodo.assertMacroVersion(3);
if (komodo.view) {
    komodo.view.setFocus();
}
    ko.commands.doCommand('cmd_home')
    ko.commands.doCommand('cmd_right')
    ko.commands.doCommand('cmd_right')
    komodo.view.selection = ' - ';
    ko.commands.doCommand('cmd_lineNext')
    ko.commands.doCommand('cmd_home')  

Now we can loop (9 times in this case) or run till the end of file as shown by Eric, by editing code as follows:

komodo.assertMacroVersion(3);
if (komodo.view) {
    komodo.view.setFocus();
}

for (i = 0; i < 9; i++) {
    ko.commands.doCommand('cmd_home')
    ko.commands.doCommand('cmd_right')
    ko.commands.doCommand('cmd_right')
    komodo.view.selection = ' - ';
    ko.commands.doCommand('cmd_lineNext')
    ko.commands.doCommand('cmd_home')    
}

For reference: http://docs.activestate.com/komodo/4.4/macroapi.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top