4

Say I want to create a source code editor for ocaml programming language, where do I start? I am looking to create an editor for the Windows platform as a hobby project. My primary skill is in web development. I have developed windows apps long time ago. I have no clue how it is done with todays available tools. I have visual studio 2008 and C# is my language of choice.

Animesh
  • 4,926
  • 14
  • 68
  • 110
  • A source code editor is just notepad, it's all the extra features like intellisense, code highlighting etc etc that make an IDE (which i'm guessing is really what you want?) – PostMan May 05 '10 at 00:34
  • 1
    Yes, IDE but not really a heavy weight one like eclipse or visual studio. Something that looks like notepad, but can compile and execute the code. – Animesh May 05 '10 at 00:39
  • they cannot compile and execute code. The compiler (like GCC) compiles, your processor executes. The IDE only launches the compiler. –  May 05 '10 at 01:00
  • Yes, yes, I understand that my program will be calling the compiler (ocamlc). A keyboard shortcut would be launching it. I meant notepad like simplicity in the look and feel. – Animesh May 05 '10 at 01:10
  • it sounds like you want vim or emacs... – nlucaroni May 07 '10 at 17:44

4 Answers4

2

If you are most comfortable in Visual Studio, then you can use the Visual Studio Shell to create your own IDE based on that foundation.

Here is a podcast that gives a good overview: http://www.code-magazine.com/codecast/index.aspx?messageid=32b9401a-140d-4acb-95bb-6accd3a3dafc

Also, as a reference, the IronPython Studio was created using the Visual Studio 2008 Shell: http://ironpythonstudio.codeplex.com/

Browsing that source code should give you a good starting point.

Ben Hoffstein
  • 102,129
  • 8
  • 104
  • 120
  • Thanks a lot for answer Ben. I will definitely take a look at the overview of vs shell and also the ironpython studio. – Animesh May 05 '10 at 01:12
2

You need to know:

  • OCAML Syntax, Features, Keywords, Functions etc...
  • C# as this is your native language I guess
  • You need to know what features you wanna implement
  • ...if it's using a GUI or just from a terminal like nano/vim
  • how syntax highlighting works
  • how to open and save files
  • how autocompletion works
  • etc..

You might want to take look at some open source editors like dev-c++ or gedit

Also, as you in person are more web-devvy, you might want to start creating one which runs 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.

  • Thanks Koning. I appreciate your answer. This is what I am exactly looking for. I needed somewhere to start. This is it. Thanks. – Animesh May 05 '10 at 01:13
  • No problem. What most people don't know is that Koning is Dutch for King. Everyone here calls me a king without even knowing. BTW, thx I almost have 2000rep now ^^^ –  May 05 '10 at 01:19
2

a lighter-weight alternative 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);    
    }

}
Cheeso
  • 189,189
  • 101
  • 473
  • 713
1

You could use Scintilla. It has syntax highlighting and some other features. Also, it has a .NET Version available here.

Another good tool is Alsing Syntax Box:

Powerful Syntax Highlight Windows Forms Control for the Microsoft.NET Platform. Written in 100% managed C#. Supports syntax highlighting and code folding for just about any programming language.

With Alsing Syntax Box, you can define a syntax file (just like this one for C#) and later have a intellisense like feature.

You can start with one of them for your editor.

Fernando
  • 4,029
  • 1
  • 26
  • 35
  • SciTE is my second favorite editor. I will look at the both the tools you have mentioned. Thanks! – Animesh May 05 '10 at 01:14