+;;;----- C# programming configuration ---------------------------------------
+
+;; --- Make indentation nice ---
+
+(defun mdw-csharp-style ()
+ (c-add-style "[mdw] C# style"
+ '((c-basic-offset . 2)
+ (c-tab-always-indent . nil)
+ (c-offsets-alist (substatement-open . 0)
+ (label . 0)
+ (case-label . +)
+ (access-label . 0)
+ (inclass . +)
+ (statement-case-intro . +)))
+ t))
+
+;; --- Declare C# fontification style ---
+
+(defun mdw-fontify-csharp ()
+
+ ;; --- Other stuff ---
+
+ (mdw-csharp-style)
+ (modify-syntax-entry ?_ "w")
+ (setq c-hanging-comment-ender-p nil)
+ (setq c-backslash-column 72)
+ (setq comment-start "/* ")
+ (setq comment-end " */")
+ (setq mdw-fill-prefix
+ `((,(concat "\\([ \t]*/?\\)"
+ "\\([\*/][ \t]*\\)"
+ "\\([A-Za-z]+:[ \t]*\\)?"
+ mdw-hanging-indents)
+ (pad . 1) (match . 2) (pad . 3) (pad . 4))))
+
+ ;; --- Now define things to be fontified ---
+
+ (make-local-variable 'font-lock-keywords)
+ (let ((csharp-keywords
+ (make-regexp '("abstract" "as" "base" "bool" "break"
+ "byte" "case" "catch" "char" "checked"
+ "class" "const" "continue" "decimal" "default"
+ "delegate" "do" "double" "else" "enum"
+ "event" "explicit" "extern" "false" "finally"
+ "fixed" "float" "for" "foreach" "goto"
+ "if" "implicit" "in" "int" "interface"
+ "internal" "is" "lock" "long" "namespace"
+ "new" "null" "object" "operator" "out"
+ "override" "params" "private" "protected" "public"
+ "readonly" "ref" "return" "sbyte" "sealed"
+ "short" "sizeof" "stackalloc" "static" "string"
+ "struct" "switch" "this" "throw" "true"
+ "try" "typeof" "uint" "ulong" "unchecked"
+ "unsafe" "ushort" "using" "virtual" "void"
+ "volatile" "while" "yield"))))
+
+ (setq font-lock-keywords
+ (list
+ 't
+
+ ;; --- Handle the keywords defined above ---
+
+ (list (concat "\\<\\(" csharp-keywords "\\)\\>")
+ '(0 font-lock-keyword-face))
+
+ ;; --- Handle numbers too ---
+ ;;
+ ;; The following isn't quite right, but it's close enough.
+
+ (list (concat "\\<\\("
+ "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
+ "[0-9]+\\(\\.[0-9]*\\|\\)"
+ "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
+ "[lLfFdD]?")
+ '(0 mdw-number-face))
+
+ ;; --- And anything else is punctuation ---
+
+ (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
+ '(0 mdw-punct-face))))))
+
+(defun csharp-mode ()
+ (interactive)
+ (java-mode)
+ (setq major-mode 'csharp-mode)
+ (setq mode-name "C#")
+ (mdw-fontify-csharp)
+ (run-hooks 'csharp-mode-hook))
+