Skip to content

Instantly share code, notes, and snippets.

@dtjohnso
Created August 27, 2009 15:46
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 dtjohnso/176391 to your computer and use it in GitHub Desktop.
Save dtjohnso/176391 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
names: ["check parentheses"],
icon: "http://www.mozilla.com/favicon.ico",
description: "Does a simple arithmetic check to see if a selected line of code has enough parentheses.",
//help: "How to use your command.",
author: {name: "Duncan Johnson", email: "duncan@duncanandmeg.org"},
license: "GPL",
homepage: "http://andyanglea.com/blog/2009/08/if-problems/",
arguments: [{role: 'object', nountype: noun_arb_text}],
preview: function preview(pblock, args) {
pblock.innerHTML = "Your input is <b>" + args.object.html + "</b>.";
},
execute: function execute(args) {
var charArray = args.object.text.split("");
var test1Integer = 0;
for (var item in charArray) {
if (charArray[item] == "(") {
test1Integer = test1Integer + 1;
} else if (charArray[item] == ")") {
test1Integer = test1Integer - 1;
}
}
if (test1Integer !== 0) {
displayMessage ("There is an error in the selected line");
} else { displayMessage ("No error detected \(but you still might have bad code, this is no guarantee\)");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment