Skip to content

Instantly share code, notes, and snippets.

@desjarlais
Last active December 6, 2023 18:30
Show Gist options
  • Save desjarlais/dcc5af71d468c4267768cdbb0ff92091 to your computer and use it in GitHub Desktop.
Save desjarlais/dcc5af71d468c4267768cdbb0ff92091 to your computer and use it in GitHub Desktop.
Python Recipe
// Reset the styles
scintilla.StyleResetDefault();
scintilla.Styles[Style.Default].Font = "Consolas";
scintilla.Styles[Style.Default].Size = 10;
scintilla.StyleClearAll(); // i.e. Apply to all
// Set the lexer
scintilla.LexerName = "python";
// Known lexer properties:
// "tab.timmy.whinge.level",
// "lexer.python.literals.binary",
// "lexer.python.strings.u",
// "lexer.python.strings.b",
// "lexer.python.strings.over.newline",
// "lexer.python.keywords2.no.sub.identifiers",
// "fold.quotes.python",
// "fold.compact",
// "fold"
// Some properties we like
scintilla.SetProperty("tab.timmy.whinge.level", "1");
scintilla.SetProperty("fold", "1");
// Use margin 2 for fold markers
scintilla.Margins[2].Type = MarginType.Symbol;
scintilla.Margins[2].Mask = Marker.MaskFolders;
scintilla.Margins[2].Sensitive = true;
scintilla.Margins[2].Width = 20;
// Reset folder markers
for (int i = Marker.FolderEnd; i <= Marker.FolderOpen; i++)
{
scintilla.Markers[i].SetForeColor(SystemColors.ControlLightLight);
scintilla.Markers[i].SetBackColor(SystemColors.ControlDark);
}
// Style the folder markers
scintilla.Markers[Marker.Folder].Symbol = MarkerSymbol.BoxPlus;
scintilla.Markers[Marker.Folder].SetBackColor(SystemColors.ControlText);
scintilla.Markers[Marker.FolderOpen].Symbol = MarkerSymbol.BoxMinus;
scintilla.Markers[Marker.FolderEnd].Symbol = MarkerSymbol.BoxPlusConnected;
scintilla.Markers[Marker.FolderEnd].SetBackColor(SystemColors.ControlText);
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);
// Set the styles
scintilla.Styles[Style.Python.Default].ForeColor = Color.FromArgb(0x80, 0x80, 0x80);
scintilla.Styles[Style.Python.CommentLine].ForeColor = Color.FromArgb(0x00, 0x7F, 0x00);
scintilla.Styles[Style.Python.CommentLine].Italic = true;
scintilla.Styles[Style.Python.Number].ForeColor = Color.FromArgb(0x00, 0x7F, 0x7F);
scintilla.Styles[Style.Python.String].ForeColor = Color.FromArgb(0x7F, 0x00, 0x7F);
scintilla.Styles[Style.Python.Character].ForeColor = Color.FromArgb(0x7F, 0x00, 0x7F);
scintilla.Styles[Style.Python.Word].ForeColor = Color.FromArgb(0x00, 0x00, 0x7F);
scintilla.Styles[Style.Python.Word].Bold = true;
scintilla.Styles[Style.Python.Triple].ForeColor = Color.FromArgb(0x7F, 0x00, 0x00);
scintilla.Styles[Style.Python.TripleDouble].ForeColor = Color.FromArgb(0x7F, 0x00, 0x00);
scintilla.Styles[Style.Python.ClassName].ForeColor = Color.FromArgb(0x00, 0x00, 0xFF);
scintilla.Styles[Style.Python.ClassName].Bold = true;
scintilla.Styles[Style.Python.DefName].ForeColor = Color.FromArgb(0x00, 0x7F, 0x7F);
scintilla.Styles[Style.Python.DefName].Bold = true;
scintilla.Styles[Style.Python.Operator].Bold = true;
// scintilla.Styles[Style.Python.Identifier] ... your keywords styled here
scintilla.Styles[Style.Python.CommentBlock].ForeColor = Color.FromArgb(0x7F, 0x7F, 0x7F);
scintilla.Styles[Style.Python.CommentBlock].Italic = true;
scintilla.Styles[Style.Python.StringEol].ForeColor = Color.FromArgb(0x00, 0x00, 0x00);
scintilla.Styles[Style.Python.StringEol].BackColor = Color.FromArgb(0xE0, 0xC0, 0xE0);
scintilla.Styles[Style.Python.StringEol].FillLine = true;
scintilla.Styles[Style.Python.Word2].ForeColor = Color.FromArgb(0x40, 0x70, 0x90);
scintilla.Styles[Style.Python.Decorator].ForeColor = Color.FromArgb(0x80, 0x50, 0x00);
// Important for Python
scintilla.ViewWhitespace = WhitespaceMode.VisibleAlways;
// Keyword lists:
// 0 "Keywords",
// 1 "Highlighted identifiers"
var python2 = "and as assert break class continue def del elif else except exec finally for from global if import in is lambda not or pass print raise return try while with yield";
var python3 = "False None True and as assert break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield";
var cython = "cdef cimport cpdef";
scintilla.SetKeywords(0, python2 + " " + cython);
// scintilla.SetKeywords(1, "add your own keywords here");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment