Emacs flycheck for C#

I use emacs, have done so for a long time. Also a longtime fan of C#.
I wrote csharp-mode for emacs, to sort of cross the streams on those two interests.

I recently found Flycheck – which is a turn-of-the-crank on the fantastic idea that was flymake. If you don’t know flymake, it is a tool that runs a syntax check on your file, after every change. For C#, it will compile the file. For JavaScript, it runs JSHint. For CSS, it runs CSS lint. And so on for python, PHP, Java and whatever else. Flymake is part of emacs.

Flymake is a great idea, but it has some flaws. For one thing, it runs too aggressively, even on buffers you cannot see. If you have lots of buffers open, it can kill your CPU. There are a couple other warts too. Over the years, people have learned to live with them.

Flycheck is the same idea, but with improvements.

  1. it’s more efficient.
  2. the syntax highlighting is better. You get red squigglies, just like in Visual Studio.

Red Squigglies

I love open source innovation and community-driven advances!

Supposedly, with flycheck it is also easier to add in new “checkers” for various syntaxi. I don’t know if that’s true. I just built a C# checker for flycheck, and I had previously built checkers for C# (and for numerous other languages and tools) for flymake. It wasn’t so difficult in either case.

Anyway, here’s what you need to get flycheck to work with C# in emacs:

Add this to your init.el or .emacs or whatever:

And here’s how you use it:

Note the comment near the top of the file. This tells flycheck what to use for the checker command. You can specify anything there, including csc.exe on Windows.

I am now using a Mac as my main laptop, and yes, you can do C# on Mac with Mono. And this flycheck thing works there, too, natcherully.

Giving Back?

Flycheck “encourages” contributions, but the requirements are a bit too onerous for me. This potential enhancement won’t be accepted without unit tests and a bunch of other stuff. I’m not bothering with all that. So I’m just publishing this, thinking people might find it to be useful. For now, anyone can use this; it just works.

ps: you will need to have, on your path, the directory that contains the gmcs tool and the pkg-config tool, if you use mono. On MacOS this is /Library/Frameworks/Mono.framework/Versions/Current/bin . You can do this in emacs, this way:

emacs dired fixups

For the geeks and dinosaurs among us**, A quick post on dired fixups I use for emacs. I like to sort by name, size, date, and extension. Dired sorts by name and time I think, by default. For other options you need to manually enter the ls sorting options. This elisp teaches dired to sort by size and extension as well.


In action:

Thanks to isagalaev and jamesward for highlight.js and github-files.js respectively.

**Someone today told me that emacs is a throwback and I am a dinosaur for continuing to use it. He said he used emacs in the past, but now he uses “more modern” tools. I’m a little suspicious because his first excuse for not using emacs was, “I run Windows”.