ActiveState Powered by ActiveState

ActiveState Community


Run the current macro

Posted by jeffg on 2008-04-02 12:56
OS: All / Any

Here's a quick macro that I wrote the other day and greatly helps speed up testing/writing macros:

/*
 * a quick macro that tries to run the current macro open in the buffer
 * should be *not a macro*
*/

try {
  var view = ko.views.manager.currentView;
  var scimoz = view.scimoz;
  var uri = view.document.displayPath;
  var self = ko.macros.current;
 
  if(/^macro:\/\//.test(uri) && uri !== self.url) { // we don't want to run ourself
    var partName = (view.document.baseName.split('.').shift());
    var project = ko.projects.manager.currentProject;
    var part = ko.projects.findPart('macro', partName, '*', project);
    part.invoke();
  } else {
    ko.statusBar.AddMessage('Not a macro buffer, nothing to do...');
  }
} catch(e) {
  ko.dialogs.internalError(e, 'Error: '+e);
}

/*
 * a quick macro that tries to run the current macro open in the buffer
 * should be *not a macro*
*/

try {
  var view = ko.views.manager.currentView;
  var scimoz = view.scimoz;
  var uri = view.document.displayPath;
  var self = ko.macros.current;
  
  if(/^macro:\/\//.test(uri) && uri !== self.url) { // we don't want to run ourself
    var partName = (view.document.baseName.split('.').shift());
    var project = ko.projects.manager.currentProject; 
    var part = ko.projects.findPart('macro', partName, '*', project);
    part.invoke();
  } else {
    ko.statusBar.AddMessage('Not a macro buffer, nothing to do...');
  }
} catch(e) {
  ko.dialogs.internalError(e, 'Error: '+e);
}

Just assign a key binding to this guy, and BLAMMO! you can run whatever the current macro open in the editor is using the keybinding. The code *should* be immune against trying to run itself, otherwise this could easily go into an infinite loop if you invoked it on itself.

-->