What do I need to know to create a source editor?
Let's say I want to create a source code editor for the ocaml programming language, where do I start? I want to create an editor for Windows platform as a hobby project. My main skill is in web development. I have developed Windows apps for a long time. I have no idea how this is done with today's available tools. I have visual studio 2008 and C # is my language of choice.
a source to share
You need to know:
- OCAML syntax, functions, keywords, functions, etc.
- C # as it is your native language. I think,
- You need to know what functionality you want to implement.
- ... if it is using a GUI or only from a terminal like nano / vim
- how syntax highlighting works
- how to open and save files
- how autocomplete works
- etc..
Maybe you should take a look at some open source editors like dev-c ++ or gedit
Also, since you are personally more of a web devvy, you can start building one that works in a web browser. This is often easier and helps you understand the basics of creating a code editor. Later, you can always write one for desktops.
If you're more comfortable with Visual Studio, you can use the Visual Studio Shell to build your own IDE based on this foundation.
Here's a podcast that gives a good overview: http://www.code-magazine.com/codecast/index.aspx?messageid=32b9401a-140d-4acb-95bb-6accd3a3dafc
Also, as a link, IronPython Studio was built using the Visual Studio 2008 shell: http://ironpythonstudio.codeplex.com/
Browsing the source should give you a good starting point.
a source to share
an alternative with a lighter weight is to use the RichEdit control
Example:
http://www.codeproject.com/Messages/3401956/NET-Richedit-Control.aspx
// http://www.codeproject.com/Messages/3401956/NET-Richedit-Control.aspx
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace RichEditor
{
public class RichTextBoxEx : RichTextBox
{
IntPtr mHandle = IntPtr.Zero;
protected override CreateParams CreateParams
{
get
{
// Prevent module being loaded multiple times.
if (this.mHandle == IntPtr.Zero)
{
// load the library to obtain an instance of the RichEdit50 class.
this.mHandle = LoadLibrary("msftedit.dll");
}
// If module loaded, reset ClassName.
if (this.mHandle != IntPtr.Zero)
{
CreateParams cParams = base.CreateParams;
// Check Unicode or ANSI system and set appropriate ClassName.
if (Marshal.SystemDefaultCharSize == 1)
{
cParams.ClassName = "RichEdit50A";
}
else
{
cParams.ClassName = "RichEdit50W";
}
return cParams;
}
else // Module wasnt loaded, return default .NET RichEdit20 CreateParams.
{
return base.CreateParams;
}
}
}
~RichTextBoxEx()
{
//Free loaded Library.
if (mHandle != IntPtr.Zero)
{
FreeLibrary(mHandle);
}
}
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr LoadLibrary(String lpFileName);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool FreeLibrary(IntPtr hModule);
}
}
a source to share
You can use Scintilla . It has syntax highlighting and some other features. Also, it has a .NET version available here .
Another good tool is the Alsing Syntax Block :
Powerful Highlight Windows Syntax Form Control for Microsoft .NET Platform. Written in 100% managed C #. Support for syntax highlighting and code folding for almost any programming language.
With the Alsing syntax block, you can define a syntax file (like this one for C # ) and then an intellisense function .
You can start with one of these for your editor.
a source to share