This is a mode for editing C# in emacs. It’s using tree-sitter for highlighting and indentation.
- font-lock and indent of C# syntax including:
- all c# keywords and major syntax
- attributes that decorate methods, classes, fields, properties
- enum types
- #if/#endif #region/#endregion
- instance initializers
- anonymous functions and methods
- verbatim literal strings (those that begin with @)
- generics
- intelligent insertion of matched pairs of curly braces.
- compilation-mode support for msbuild, devenv and xbuild.
You can enable experimental tree sitter support for indentation and highlighting using
(use-package tree-sitter)
(use-package tree-sitter-langs)
(use-package csharp-mode
:config
(add-to-list 'auto-mode-alist '("\\.cs\\'" . csharp-tree-sitter-mode)))If you are using this, clearly state so if you find any issues.
This package is currently available on MELPA. Install using M-x
package-install<RET>csharp-mode.
Once installed the package should be automatically used for files with a ‘.cs’-extension.
Note: This package is also available on MELPA-stable for those who don’t want or need bleeding edge development-versions.
For a better experience you may want to enable electric-pair-mode when editing C#-files. To do so, add the following to your .emacs-file:
(defun my-csharp-mode-hook ()
;; enable the stuff you want for C# here
(electric-pair-mode 1) ;; Emacs 24
(electric-pair-local-mode 1) ;; Emacs 25
)
(add-hook 'csharp-mode-hook 'my-csharp-mode-hook)For further mode-specific customization, M-x customize-group RET csharp RET will show available settings with documentation.
For more advanced and IDE-like functionality we recommend using csharp-mode together with lsp-mode or eglot
This repo was a fork of the code originally developed by Dylan R. E. Moonfire and further maintained by Dino Chiesa as hosted on Google code.
The original csharp-mode repo contained lots of different code for lots of different purposes, some finished, some not, some experimental, some not. Basiaclly things like ASPX-mode, TFS-mode, code completion backends, etc.
All this original code can still be found in the extras-branch, but we have decided to go for a more focused approach and to throw out all dead or unused code, code we wont be maintaining.
The goal: That what we package in csharp-mode actually works and works well.
The original project was licensed under GPL v2, but after rewrite in September 2020, it is relicensed to GPLv3