// add latest include static S addAlternateStdFunction(S listID) { loading { ret addAlternateStdFunction(listID, findLatestInclude().id, true); } } static S addAlternateStdFunction(S listID, bool realEdit) { ret addAlternateStdFunction(listID, findLatestInclude().id, realEdit); } static S addAlternateStdFunction(S listID, S snippetID, bool realEdit) { snippetID = fsI(snippetID); loading { LS names = findFunctionDefinitions(loadSnippet(snippetID)); printStructure("Functions defined in " + snippetID + ": ", names); if (empty(names)) ret "No functions found in " + snippetID; S name = firstNotStartingWith(names, "_onLoad_"); if (empty(names)) ret "No definable functions found in " + snippetID; S text = loadSnippet(listID); SS map = tok_findStandardFunctionDefinitions(javaTok(text)); S def = map.get(name); S result = ""; if (def == null) { print(result = "Defining " + name + "."); S newText = appendWithNewLine(text, "function " + name + " is in " + snippetID + "."); print(); print(unidiff(text, newText)); if (!realEdit) print(result += " Not editing (test mode)."); else { editSnippet(listID, newText); triggerTranspilerDirty(); print(result += " Edited " + listID + ". Now " + countLines(newText) + " lines!"); } } else { print(result = "Function " + name + " already defined as " + def); if (sameSnippetID(def, snippetID)) print("Exiting."); else print("Will not redefine as " + snippetID + "."); } ret result; } }