

GitHub - emacs-csharp/csharp-mode: A major-mode for editing C# in emacs
source link: https://github.com/emacs-csharp/csharp-mode
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

csharp-mode
This is a mode for editing C# in emacs. It’s using CC mode or tree-sitter for highlighting and indentation.
Main features
- 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.
tree-sitter support
You can enable experimental tree sitter support for indentation and highlighting using
(use-package tree-sitter :ensure t) (use-package tree-sitter-langs :ensure t) (use-package csharp-mode :ensure t :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.
Note that we don’t depend on tree-sitter yet, so you have to manually install the packages involved. The simplest way is to use the provided snippet above.
Using and evolving the tree-sitter functionality.
tree-sitter
introduces a minor mode called tree-sitter-debug-mode
where you can
look at the actual syntax tree it produces. If and when you spot missing or
wrong syntax highlighting, look at how the patterns are written in
csharp-tree-sitter-mode.el
, then submit a pr with a couple new ones added. When
testing and debugging this, it is actually as simple as M-x eval-buffer
on
csharp-tree-sitter-mode.el
, then M-x revert-buffer
in the file you are testing.
It should update and show the correct syntax highlighting.
So the development cycle is:
- Spot missing syntax highlighting
- View AST with
tree-sitter-debug-mode
- Locate offending part
- Add new pattern
M-x eval-buffer
incsharp-tree-sitter-mode.el
M-x revert-buffer
inside yoursome-test-file.cs
Usage
This package is currently available on both ELPA and 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
Attribution
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.
New focus
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.
This package aims to stay as close to mainline emacs as it can. As such, paperwork with the FSF is needed for contributions of significant size.
License
The original project was licensed under GPL v2+, but after a rewrite in September 2020, it was relicensed to GPLv3+
Recommend
-
179
About Improved JavaScript editing mode for GNU Emacs (description here). For some of the latest changes, see
-
203
web-mode.el web-mode.el is an emacs major mode for editing web templates aka HTML files embedding parts (CSS/JavaScript) and blocks (pre rendered by client/server side engines). web-mode.el is compatible with many...
-
107
csharp-mode This is a mode for editing C# in emacs. It’s using CC mode or tree-sitter for highlighting and indentation. Main features f...
-
36
html template editing for emacs web-mode.el About web-mode.el is an autonomous emacs major-mode for editing web templates. HTML documents can embed parts (CSS...
-
15
Files Permalink Latest commit message Commit time
-
18
yard-mode Rudimentary support for fontifying YARD tags and directives in ruby comments. Installation Use MELPA: M-x package-install yard-mode. Ad...
-
18
Files Permalink Latest commit message Commit time
-
8
pip-requirements.el This is a major mode for editing pip requirements files, with the following features: Syntax highlighting Togglable comments Auto completion of package names from PyPI A...
-
6
这篇文章给了简单的讲解和利用方式: https://blog.netwrix.com/2023/04/10/generating-deserialization-payloads-for-mess...
-
12
Emacs: Vile Mode (VIm Like Editing)
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK