Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.