Add custom snippets to Snippets.SnippetList

Topics: Developer Forum, User Forum
Jul 9, 2014 at 12:31 PM
I have been using ScintillaNET both personally and professionally for some time now but find the snippet functionality a little limited. I am trying to add my own snippets to the predefined snippet list. I'm aware that you can create a snippet on the fly with this line:
_frm.codeEditor.Snippets.InsertSnippet(new Snippet("header", _snip.HDR));
But I'd like to be able to add my own snippets to the list so that when calling:
My own snippets are displayed and accessible. I have looked through several threads on here and through the source of ScintillaNET but haven't been able to see where the list is being generated or how to easily add to it. Ideally, I'd like to point it to a different path that contains my own snippet XML files.

Any advice or guidance will be very appreciated.
Jul 9, 2014 at 1:01 PM
_frm.codeEditor.Snippets.List has all the methods for adding and removing snippets. You can use the configuration with custom path to do this from an XML file but that's probably a lot more work. The configuration system was written in a dark time when overly complex XML configs were all the rage. I kicked the complexity up a few notches by introducing an inheritance system.
Jul 9, 2014 at 1:13 PM
Thanks for the quick reply. Can you tell me the method to redirect the list to load already created snippets; default .NET snippets for example? I can only see methods for adding individual snippets.
Jul 9, 2014 at 2:23 PM
I'm honestly not trying to be pedantic but there are no .NET snippets. Things like snippets, autocompletes and keywords are loaded from the configuration system which is bound to the language you're working with.

ScintillaNet ships with builtin configurations for a small subset of the languages (native) Scintilla is able to handle. There is a c# language configuration that you can set with
_frm.codeEditor.ConfigurationManager.Language = "cs";
or by the WinForms designer.

Once you do this all the aforementioned items along with the builtin syntax highlight color scheme and other stuff will be loaded. See here for everything you get. It's not nearly as comprehensive as what you get with say Visual Studio and it hasn't been updated since I originally wrote it back in the c# 2.0 days. But it is a good starting point.

After setting the language you can invoke the Snippet APIs to add your own set on top of that.
Jul 9, 2014 at 2:39 PM
And XLinq can make adding your own list of snippets super easy. Assume you have an XML file with a flat list of snippets in the same format as the config file...
    var snippets = XDocument.Load(somePath)
        .Select(el => new Snippet((string)el.Attribute("Shortcut"), (string)el.Attribute("code"))
            IsSurroundsWith = bool.Parse((string)el.Attribute("IsSurroundsWith"))