Skip to content

Instantly share code, notes, and snippets.

@Naatan
Created November 20, 2013 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Naatan/7570727 to your computer and use it in GitHub Desktop.
Save Naatan/7570727 to your computer and use it in GitHub Desktop.
Komodo Macro - Execute (selection) as JavaScript Quick and dirty, will probably break in many use-cases
komodo.assertMacroVersion(3);
if (komodo.view) { komodo.view.setFocus() };
// Get text to execute
var ke = komodo.editor;
if(!ke.selText)
{
// Use all text in file
var text = ko.views.manager.currentView.scimoz.text.trim()
}
else
{
// Use selected text
var text = komodo.interpolate('%s').trim();
}
var _eval_pre = "var _logged = ''; var console = {log: function(val) { _logged += val + \"\\n\\n\"; return val; }}; "
var _eval_post = " if (_logged != '') _logged;";
var result = eval(_eval_pre + text + _eval_post);
ko.run.runEncodedCommand(window, "printf \"" + result + "\\n\"");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment