C# – Getting csharp-mode Emacs syntax highlighting working

celispemacsmono

Googling "csharp mode emacs" yields the page

http://www.emacswiki.org/emacs/CSharpMode

which includes a few links to various downloadable emacs lisp files. The 2005 link (DylanMoonfire) is broken, so I downloaded:

http://lists.ximian.com/pipermail/mono-list/2002-May/006182.html

as ~/.emacslib/csharp-mode.el

and added:

(autoload 'csharp-mode "csharp-mode"
  "Major mode for editing C# code." t)
(setq auto-mode-alist (cons '( "\\.cs\\'" . csharp-mode ) auto-mode-alist ))

to my .emacs file (anywhere, beginning, middle or end). I attempt to edit a new text file called "t.cs" and I get the error:

File mode specification error: (error "Buffer t.cs is not a CC Mode buffer (c-set-style)")

and no syntax highlighting. I'm not well versed in emacs-lisp but I know enough to install support for loads of language modes and csharp-mode is just not playing nice compared to every other language mode I've installed.

I was getting excited to play with Mono on my Mac and ran into this ridiculous barrier! Anyone out there know how to get decent support for C# syntax highlighting in emacs?

Note: I'm using a MacBook Pro running Emacs 22.1.1 on OS X Leopard.

Best Answer

I found a more recent version of csharp-mode 0.7.0, go to the end of the page and download as plain text. Haven't tried loading the mode however.

Just uploaded the code to emacswiki as well: charp-mode.el

Related Topic