Skip to content

Instantly share code, notes, and snippets.

@YellowAfterlife
Created March 6, 2021 17:49
Show Gist options
  • Save YellowAfterlife/fff396d21094b3f3bb87e665cbdd53cb to your computer and use it in GitHub Desktop.
Save YellowAfterlife/fff396d21094b3f3bb87e665cbdd53cb to your computer and use it in GitHub Desktop.
An example of making custom syntax extensions for GMEdit. This collapses `//hello` in a file to `//hi` in editor and back.
{
"name": "synext",
"description": "",
"scripts": ["synext.js"],
"stylesheets": []
}
(function() {
const SyntaxExtension = $gmedit["synext.SyntaxExtension"];
function MySynExt() {
SyntaxExtension.call(this, "mySynExt", "My syntax extension");
}
MySynExt.prototype = GMEdit.extend(SyntaxExtension.prototype, {
preproc: function(codeEditor, gmlCode) {
return gmlCode.split("//hello").join("//hi");
},
postproc: function(codeEditor, gmlCode) {
return gmlCode.split("//hi").join("//hello");
},
});
function init() {
$gmedit["file.kind.KGml"].syntaxExtensions.push(new MySynExt());
}
//
GMEdit.register("synext", { init: init });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment