Unless you did some assembly programming, you are left in the dark about what enormous performance your PC can put on display (loading 80 Text files < 0.5sec). With that in mind, I intended to replace edit classes I have used in projects since these edits dragged the speed of applications to an unacceptable level, were hardly complete and did not provide standard facilities either. I happened to remembered that some years ago, I came along Scintilla. Scintilla is a code editor component with source for the event, another exotic extension is desired. The editor is written in C/C++ and can be built with VS 2010 or preferably Gcc. I got way more than I was begging for! The “component” exists since 1999, has over 200 contributors and is used in at least as many projects, some you likely came across already. The license permits use in any free project or commercial product.
Since Scintilla is intended for cross platform use, there are compilations for several platforms and plenty of wrappers for God knows what available. Considering Windows, there is a GTK+ and a genuine version. Pictures below show Scintilla in action, projects where the Scintilla component were built in.
The wrapped Scintilla showing some facilities after reimplementation:
Well, true, you don’t see much of the source code here. This was not the aim. From up to down: The Code Snippet manager with an opened Snippet list followed by annotations which can be colored character by character. Sizable Arrow boxes in any desired color and size, with or without closure, movable or fixed, pointing up or down, filled with information and a title if indicated. Further right a Message Tree shows up. You are familiar with that as you debug in Visual Studio. Just the handling has improved a bit. Several multicolored small triangles are dropmarkers which can be used for any purpose. Further down call tips with or without arrows and highlight facility to display messages as an additional possibility. Support for regular expressions is activated in the Find Replace Mark dialog. It can be changed, as other modes too through clicking one of the multifunction buttons in the dialog. Found text is marked in the editor if a marker (32 are available) is set and if not then the whole line gets highlighted. Margins to the left of the editor, 5 are available, each configurable in any way, display line numbers, arrow symbols for text found at locations, bookmarks and much more. Last but not least, code folding. The bluish and light green vertical lines are used here as a bar to indicate parts of the code colorable freely for all sort of purposes. That is not all yet, this displays just a subset of what is available in the editor class. Certainly, the implemented printing support is rich in facilities too and about 98 command keys (shortcuts) are assigned to functions. All together, a very rich set of facilities, really fast and easy to use. The code for all these examples, merely a couple of lines each, can be found in the project.
As this project is built upon C/C++ and C# sources, terms from all these languages are used interchangeably.
As already mentioned, there are a whole variety of implementations ready for download. The ones I have found for C# are either built against Framework 2, which becomes obvious after following some confusing error messages and or lack updating. Since the completion of the last C# wrapper, 274 changes (mainly functions & parameters) took place in the editor. So it is probably time for an update since the wrapper seems not to be maintained any longer. That is understandable by its size. The aim is to have a class which can be used in the form designer, can make use of direct access to the edit itself, supports single instance besides multiple edit instances, is built against framework 4 and is quick, full of facilities and appealing. The user interface needed a complete work over. It is questionable, perhaps not even desired, if a complete implementation with reasonable overhead is ever possible since the possibilities are next to endless. The edit class is stable despite various extensions which were added over time, what can be expected after such a long time developing. This might not hold true for the wrappers. It is not exaggerated that this class leaves the most similar projects simply in the dust.
There is hardly enough space here do list the many commands that are built in. These can be found in the documentation but at least sections where commands are available.
- Auto completion
- Background loading and saving
- Brace highlighting
- Call tips
- Caret, selection, and hotspot styles
- Cut, copy and paste
- Direct access
- Error handling
- Key bindings
- Keyboard commands
- Lexer for syntax coloring
- Line endings
- Line wrapping
- Long lines
- Macro recording
- Mouse capture
- Multiple Selection and Virtual Space
- Multiple views
- Other settings
- Popup edit menu
- Scrolling and automatic scrolling
- Selection and information
- Tabs and Indentation Guides
- Text retrieval and modification
- Undo and Redo
- User lists
- White space
There are not many formats which are not supported yet. Did you hear of Hugo? Here you do! An implementation from CodeMax. It makes a lot of sense for the time being only to implement code for desired formats and thus strip some of the lexers built in.
MainLexers are available or foreseen for:
Abaqus, Ada, Apdl, Asm, Asn1, Asp, Asymptote, Au3, Avenue, Baan, Bash, Batch, Bullant, Caml, Clarion, Cmake, Conf, Cpp, CSound, Css, D, Diff, Eiffel, EiffelKW, Erlang, ErrorList, EScript, F77, Flagship, Forth, Fortran, Haskell, Html, Inno, Kix, Latex, Lisp, Lot, Lout, Lua, Magik, MakeFile, Matlab, MetaPost, Mmixal, MSSql, NNCronTab, Nsis, Octave, Opal, Pascal, Perl, Php, Pov, PowerBasic, PowerShell, Properties, PS, Python, R, Rebol, Ruby, Smalltalk, Sol, SpecMan, Spice, Sql, Tads3, Tcl, Tex, VB, VBScript, Verilog, Vhdl, Xml and Yaml.
This list has temporary value only as work on lexers is in constant progress.
Furthermore, an extension called SimpleLexers has been built in. The purpose of it is mainly coloring of code and autocomplete where terms are stored in word lists besides support for remarking. Over 300 colorizers for different languages are available. Sure this needs remarking of the ones which are not intended for use as the wrapper would get bulky avoiding it. Ok, so it’s there!
The compilation of Scintilla under Visual Studio 2010 was complaining about several issues and did finally quit, (me too). I switched over to Gcc. A single change in the make file was needed, because I had an older version of Gcc, and there were two DLL files created in no time. Gcc version 4.7 will do. Luckily, I found the compiler already installed in an application folder on the system.
Managed versus Unmanaged Code
The Scintilla text editor is certainly unmanaged code. There is no point creating this component in managed code for various reasons. Besides .NET deals with structures in some particular ways and marshalling them is still not free of errors in every case either.
The C# source for the wrapper only is well above 30’000 lines besides all forms, the editor, the lexer info and several additional files. One can get lost easily. So did the initial author of the old wrapper, me and Visual Studio on occasion. Due to the size of the project, methods and classes from ScintillaNet were reorganized, cleaned out and newly implemented. The whole low level interface for the API and user interface was composed anew or at least underwent large changes. Extensive verification of the low level interface with the C source was a necessity and thus took place. The term wrapper here is not used in the meaning of a complete encapsulation of the API, it is rather enriching the basic functionality with additional classes for comfort and reduction of code in the final project. Direct access to the whole API is kept open! This project is not for the beginner but don’t feel pushed out, go ahead! Just expect some complexity.
- Wrapping all Scintilla function calls as of version 10/22/2012 in C#
- Creating additional properties using Scintilla editor variables
- Building additional classes using editor functions
- Rebuilding classes which shall be supported in the form designer
- Build the classes under framework 4 with compatibility for further frameworks
- Restyling of the user interface dialogs like Find, Replace, Mark and Goto
- Extending existing user interface classes and build new ones
The Scintilla Edit can now be accessed through:
- Standard Windows messaging using provided constants (hard to remember)
- Direct messaging using provided constants (hard to remember)
- Direct call of
public functions and assignments of
public variables (overhead to trace code)
- The easier readable C# wrapper function which is also displayed as a hint (popup, intellisense)
Circumventing messaging and
switch statements through direct accessing properties and classes (functions and variables), thus increasing the speed of the main class, looks very attractive especially as many functions just get or set values from fields in the editor directly. On a second thought, this might not be such a brilliant idea.
- First, if the code is updated such changes will be lost.
- Second, there are not many functions in this class which truly need speed, since the user is still by far the slowest in the game.
- Third, .NET is fast enough for this class.
- Fourth, if speeding up is desired, then direct accessing can be done in the target project.
- Fifth, direct messaging, circumventing windows messaging with its slow response is implemented already and the whole editor functionality is tuned for speed.
The wordlist limit for lexers has been pushed up, from 8 to 30, in SimpleLexer. There is a maximum of 256 styles which can be defined in Scintilla and wordlists make use of styles. This posh number has some limits in praxis. The number of entered wordlists in the SimpleLexer must not exceed 30 since wordlists use styles[wordlists.n] and style 31 is used as comment style. Having 30 wordlist available is still very extraordinary! Make sure not to enter the same definition as line or stream comment and in the wordlists as comments will dominate any styling. Define colors and attributes for styles in the lexerInfo for each info in use or globally in the
init method of the simplelexer “see Classes.cs”. SimpleLexers.cs contains a description of the structure and use of simplelexer.
Scintilla edit return values for color are of type
long and cast to
For every Scintilla function which has a return value, used or not, a dominant
return statement is copied from the C source into the C# wrapper function as comment. This allows verification of
return values easier and faster. Direct calls of the editor in the wrapper class will return mainly integer values anyway.
- SciLexer.dll should be copied in the Windows\System32 directory to avoid error messages. In case an error message pops up saying that the SciLexer cannot be loaded into memory, then the SciLexer.dll is not copied in this directory.
- Perhaps having MinGW and Gcc available to recompile Scintilla sources.
- Having the complete Scintilla documentation present is mandatory!
- Of course having the .NET framework 4 installed.
- A bit elbow grease. Do not expect that this project in every detail is perfect.
The project took several weeks, day and night, for its reimplementation only. At the current state, last updates (changes from error reports) are not implemented yet. Having a close look at the screenshot reveals (keyboard) that a spell checker is not built in yet. Just in case you don’t feel too comfy with this or that detail, the entire source can be downloaded and altered if changing available settings don’t meet your taste.
Several lexers and highlighters exist from free projects like Notepad++ and others which can be implemented. Consider remarking or deleting lexers you do not intend to use in the class, in that case
Enums.Lexer should be modified too. It is a lot easier to implement new lexers by writing or translating them in/to XML code or even entering them in the
SimpleLexer. Samples can be found in the directory Configuration.Builtin or in the Scintilla documentation. The simplelexer is well documented in the source. The project contains a Documentation.txt file with much info to be aware of. Look up also any bulletin board of Scintilla or SourceForge for further info. Because of the fast number of available options, writing a configuration file for the editor to set your personal style might prove valuable.
Alterations, Extensions and Comments
In this project, hundreds of contributors were involved over time and all of them did bring up enormous resources and gusto to give you an outstanding class and its source for free. Understanding this, please do only report errors to the appropriate person after you put up an effort to solve the issue yourself, also skip other comments gracefully. Any Scintilla message board certainly will lend you a hand. Neil Hodgson, the author of Scintilla, is surprisingly quick in responding to inquiries, supportive and eager to implement valuable suggestions in the editor.
Downloading the complete project certainly holds an edge. It has some size even when packed.
There is absolute no warranty whatsoever implied or assumed. Use it at your own risk. It does a marvelous job for the authors. Copyrights and Trademarks shall belong to their respective owners. I am not going to fight over that!
This article, along with any associated source code and files, is licensed under COPL, not included are sources of Scintilla which are copyrighted by Neil Hodgson firstname.lastname@example.org and carry their own license. Various previous contributors might have a claim for several different licenses which all due to my knowledge are open source. The whole project has changed so massively that licensing under COPL seems to be valid and/or supports the aim of every contributor.
- 9th March, 2013: Initial version
Grew up in a metal processing company and did industrial HW/SW development since the birth of Intel’s 8080. Lectured IT since 1986 at several levels. Hobbies, sidesteps: Woodworking and deep sea diving. Background: ASM, C, C++. Platforms: Win, Novel, CP/M, MP/M, DOS, (Linux).
It’s not the developer’s duty to pay up for the engineer’s ignorance.