Created
March 6, 2021 17:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "synext", | |
"description": "", | |
"scripts": ["synext.js"], | |
"stylesheets": [] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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