Skip to content

Instantly share code, notes, and snippets.

@jacobslusser
Created March 20, 2017 15:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jacobslusser/91a3a00ec8eb52ea238ee7c18c8cdf99 to your computer and use it in GitHub Desktop.
Save jacobslusser/91a3a00ec8eb52ea238ee7c18c8cdf99 to your computer and use it in GitHub Desktop.
ScintillaNET Lua Automatic Syntax Highlighting and Folding
// Extracted from the Lua Scintilla lexer and SciTE .properties file
var alphaChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var numericChars = "0123456789";
var accentedChars = "ŠšŒœŸÿÀàÁáÂâÃãÄäÅåÆæÇçÈèÉéÊêËëÌìÍíÎîÏïÐðÑñÒòÓóÔôÕõÖØøÙùÚúÛûÜüÝýÞþßö";
// Configuring the default style with properties
// we have common to every lexer style saves time.
scintilla.StyleResetDefault();
scintilla.Styles[Style.Default].Font = "Consolas";
scintilla.Styles[Style.Default].Size = 10;
scintilla.StyleClearAll();
// Configure the Lua lexer styles
scintilla.Styles[Style.Lua.Default].ForeColor = Color.Silver;
scintilla.Styles[Style.Lua.Comment].ForeColor = Color.Green;
scintilla.Styles[Style.Lua.CommentLine].ForeColor = Color.Green;
scintilla.Styles[Style.Lua.Number].ForeColor = Color.Olive;
scintilla.Styles[Style.Lua.Word].ForeColor = Color.Blue;
scintilla.Styles[Style.Lua.Word2].ForeColor = Color.BlueViolet;
scintilla.Styles[Style.Lua.Word3].ForeColor = Color.DarkSlateBlue;
scintilla.Styles[Style.Lua.Word4].ForeColor = Color.DarkSlateBlue;
scintilla.Styles[Style.Lua.String].ForeColor = Color.Red;
scintilla.Styles[Style.Lua.Character].ForeColor = Color.Red;
scintilla.Styles[Style.Lua.LiteralString].ForeColor = Color.Red;
scintilla.Styles[Style.Lua.StringEol].BackColor = Color.Pink;
scintilla.Styles[Style.Lua.Operator].ForeColor = Color.Purple;
scintilla.Styles[Style.Lua.Preprocessor].ForeColor = Color.Maroon;
scintilla.Lexer = Lexer.Lua;
scintilla.WordChars = alphaChars + numericChars + accentedChars;
// Console.WriteLine(scintilla.DescribeKeywordSets());
// Keywords
scintilla.SetKeywords(0, "and break do else elseif end for function if in local nil not or repeat return then until while" + " false true" + " goto");
// Basic Functions
scintilla.SetKeywords(1, "assert collectgarbage dofile error _G getmetatable ipairs loadfile next pairs pcall print rawequal rawget rawset setmetatable tonumber tostring type _VERSION xpcall string table math coroutine io os debug" + " getfenv gcinfo load loadlib loadstring require select setfenv unpack _LOADED LUA_PATH _REQUIREDNAME package rawlen package bit32 utf8 _ENV");
// String Manipulation & Mathematical
scintilla.SetKeywords(2, "string.byte string.char string.dump string.find string.format string.gsub string.len string.lower string.rep string.sub string.upper table.concat table.insert table.remove table.sort math.abs math.acos math.asin math.atan math.atan2 math.ceil math.cos math.deg math.exp math.floor math.frexp math.ldexp math.log math.max math.min math.pi math.pow math.rad math.random math.randomseed math.sin math.sqrt math.tan" + " string.gfind string.gmatch string.match string.reverse string.pack string.packsize string.unpack table.foreach table.foreachi table.getn table.setn table.maxn table.pack table.unpack table.move math.cosh math.fmod math.huge math.log10 math.modf math.mod math.sinh math.tanh math.maxinteger math.mininteger math.tointeger math.type math.ult" + " bit32.arshift bit32.band bit32.bnot bit32.bor bit32.btest bit32.bxor bit32.extract bit32.replace bit32.lrotate bit32.lshift bit32.rrotate bit32.rshift" + " utf8.char utf8.charpattern utf8.codes utf8.codepoint utf8.len utf8.offset");
// Input and Output Facilities and System Facilities
scintilla.SetKeywords(3, "coroutine.create coroutine.resume coroutine.status coroutine.wrap coroutine.yield io.close io.flush io.input io.lines io.open io.output io.read io.tmpfile io.type io.write io.stdin io.stdout io.stderr os.clock os.date os.difftime os.execute os.exit os.getenv os.remove os.rename os.setlocale os.time os.tmpname" + " coroutine.isyieldable coroutine.running io.popen module package.loaders package.seeall package.config package.searchers package.searchpath" + " require package.cpath package.loaded package.loadlib package.path package.preload");
// Instruct the lexer to calculate folding
scintilla.SetProperty("fold", "1");
scintilla.SetProperty("fold.compact", "1");
// Configure a margin to display folding symbols
scintilla.Margins[2].Type = MarginType.Symbol;
scintilla.Margins[2].Mask = Marker.MaskFolders;
scintilla.Margins[2].Sensitive = true;
scintilla.Margins[2].Width = 20;
// Set colors for all folding markers
for (int i = 25; i <= 31; i++)
{
scintilla.Markers[i].SetForeColor(SystemColors.ControlLightLight);
scintilla.Markers[i].SetBackColor(SystemColors.ControlDark);
}
// Configure folding markers with respective symbols
scintilla.Markers[Marker.Folder].Symbol = MarkerSymbol.BoxPlus;
scintilla.Markers[Marker.FolderOpen].Symbol = MarkerSymbol.BoxMinus;
scintilla.Markers[Marker.FolderEnd].Symbol = MarkerSymbol.BoxPlusConnected;
scintilla.Markers[Marker.FolderMidTail].Symbol = MarkerSymbol.TCorner;
scintilla.Markers[Marker.FolderOpenMid].Symbol = MarkerSymbol.BoxMinusConnected;
scintilla.Markers[Marker.FolderSub].Symbol = MarkerSymbol.VLine;
scintilla.Markers[Marker.FolderTail].Symbol = MarkerSymbol.LCorner;
// Enable automatic folding
scintilla.AutomaticFold = (AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment