Emacs as the Visual Studio Editor

There is a great little hack that I just found out about here. You can write this quick Visual Studio macro in Visual Basic that allows you to open the current VS file in an external Emacs frame for editing.

This hack works great in Visual Studio 2008 with the latest Emacs build that comes with the EmacsW32 distribution (the version I'm using is 23.0.93.1). You can bind the macro to a keystroke in VS 2008 for ease of use. After you are done editing in Emacs, just close the document and go back to VS and it will notice that the file changed and ask you if you want to reload it. I can't believe I didn't know about this. Here's the code:

Sub OpenInEmacs()
    Dim fn As String
    Dim cmd As String
    Dim lnum As Integer

    fn = DTE.ActiveDocument.FullName
    lnum = DTE.ActiveDocument.Selection.ActivePoint.Line
    cmd = "Tools.Shell ""emacsclientw.exe"" -n +" + lnum.ToString + " " + fn

    DTE.StatusBar.Text = "Opening " + fn + " in Emacs"
    DTE.ToolWindows.CommandWindow.SendInput(cmd, True)
End Sub

Comments

Comments powered by Disqus