8
votes

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.

4

4 Answers

12
votes

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

1
votes

What you have seems to be very outdated. It's too bad that the more up-to-date version was not hosted somewhere safer, like the Emacs core, EmacsWiki, or Github.

But anyway, you might as well try asking on #emacs (Freenode) and see if someone can send you the more up-to-date file.

0
votes

I made a slight modification to make Tab indent 4 spaces and deal with braces correctly, so now hitting tab on any line "does the right thing" with respect to conventions in Visual Studio.

http://www.updike.org/files/csharp-mode.el

0
votes

The EmacsWiki page for CSharpMode says that the most current version of this package can always be found on github (josteink/csharp-mode).

Maybe you would like to use OmniSharp-Emacs that provides IDE-like features for editing files in C# solutions in Emacs.

See also the article Emacs as a C# development environment.