1

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

4

3 回答 3

2

您可以使用“代码 > 重复下一个按键 N 次”菜单项重复宏 X 次。在文件末尾之前没有重复当前宏的选项,但是已经为此记录了一个增强请求(我刚刚碰到过,希望在我们的下一个主要版本中看到):http://bugs.activestate .com/show_bug.cgi?id=76022

于 2013-11-07T16:58:32.717 回答
1

首先录制一个宏。(单一动作)。
编辑宏的源代码(使用 JavaScript 或 Python) 示例:文本文件
abc
abc
abc
abc
abc
abc
abc
abc
abc

录制的宏代码:

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')  

现在我们可以循环(在这种情况下为 9 次)或运行到文件末尾,如 Eric 所示,通过编辑代码如下:

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')    
}

供参考http ://docs.activestate.com/komodo/4.4/macroapi.html

于 2015-03-26T11:24:57.113 回答
1

以下是如何在宏中执行此操作(我称我为“将当前宏运行到文件末尾”):

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();
}

您也可以让宏调用其他宏,但这有点复杂。

于 2013-11-07T18:22:39.737 回答