Subject: bug#43559: 28.0.50; [PATCH] Add csharp support to cc-mode

From: Theodor Thornhill <[email-masked]>
Date: Mon, 28 Sep 2020 21:52:00 +0200

Hello, Alan!

Alan Mackenzie <[email-masked]> writes:

[...]

>
> I don't see a reason why there shouldn't be a C# Mode directly in Emacs.
>

The current csharp mode is now rewritten, and I've gotten almost
everything to work nicely apart from one issue, and I was hoping that
you could help me figure it out, or point me in the right direction.

I described it here:
https://lists.gnu.org/archive/html/emacs-devel/2020-09/msg01975.html

However, The lambda case is now fixed, but with a patch to emacs
itself:

--------------------------------------------------------------------------------
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 4e336c0a06..b415e4b821 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -12011,7 +12011,8 @@ c-looking-at-inexpr-block
 			 (> (point) closest-lim))
 		  (not (bobp))
 		  (progn (backward-char)
-			 (looking-at "[]).]\\|\\w\\|\\s_"))
+			 (or (looking-at "[\]\).]\\|\w\\|\\s_")
+                             (looking-at ">")))
 		  (c-safe (forward-char)
 			  (goto-char (scan-sexps (point) -1))))
 
@@ -12085,7 +12086,11 @@ c-looking-at-inexpr-block
 			  (setq passed-bracket-pairs 1)
 			  (setq bracket-pos (point))))
 		      'maybe)
-		  'maybe))))
+		  'maybe)
+		(if (or (looking-at "([[:alnum:][:space:]_,]*)[ \t\n]*=>[ \t\n]*{")
+			(looking-at "[[:alnum:]_]+[ \t\n]*=>[ \t\n]*{"))
+		    ;; If we are at a C# lambda header
+		    (cons 'inexpr (point))))))
 
       (if (eq res 'maybe)
 	  (cond
--------------------------------------------------------------------------------

This patch lets CC Mode detect the lambda case for C#. I know this is a
patch specific to C#, but I could not find anywhere or anyhow this would
work without these lines.  With them, the indentation in case 1 in the
mentioned link works perfectly.

Maybe this (or something similar) could be eligible for inclusion in CC
Mode, to account for that lambda syntax. I know many other C-like
languages uses similar syntax, so I believe it could be useful for
someone else as well.

Have a nice evening!

--
Theodor Thornhill