直到上周,csharp-mode 中还存在同样的问题。我修复它的方法是在 csharp 语言的 c-basic-matchers-after 设置中添加一个新的匹配器。新的匹配器如下所示:
;; Case 2: declaration of enum with or without an explicit base type
,@(when t
`((,(byte-compile
`(lambda (limit)
(let ((parse-sexp-lookup-properties
(cc-eval-when-compile
(boundp 'parse-sexp-lookup-properties))))
(while (re-search-forward
,(concat csharp-enum-decl-re
"[ \t\n\r\f\v]*"
"{")
limit t)
(unless
(progn
(goto-char (match-beginning 0))
(c-skip-comments-and-strings limit))
(progn
(save-match-data
(goto-char (match-end 0))
(c-put-char-property (1- (point))
'c-type
'c-decl-id-start)
(c-forward-syntactic-ws))
(save-match-data
(c-font-lock-declarators limit t nil))
(goto-char (match-end 0))
)
)))
nil))
)))
csharp-enum-decl-re 定义为
(defconst csharp-enum-decl-re
(concat
"\\<enum[ \t\n\r\f\v]+"
"\\([[:alpha:]_][[:alnum:]_]*\\)"
"[ \t\n\r\f\v]*"
"\\(:[ \t\n\r\f\v]*"
"\\("
(c-make-keywords-re nil
(list "sbyte" "byte" "short" "ushort" "int" "uint" "long" "ulong"))
"\\)"
"\\)?")
"Regex that captures an enum declaration in C#"
)
它的作用是在枚举声明行之后的大括号打开上设置一个文本属性。该文本属性告诉 cc-mode 以不同的方式缩进大括号列表的内容。作为“大括号列表”。设置该属性会在下一行获得brace-list-open。
也许类似的东西对你有用。
您可以自己为 java 自定义匹配器,类似这样,如果您打开一个错误,您可以提交它作为建议的修复。
在 C# 中,枚举可以派生自任何整数类型。所以,
public enum MyEnumType : uint
{
ONE = 1,
TWO,
THREE,
}
我认为在 Java 中没有这种可能性。如果是这样,Java 正则表达式将比我用于 C# 的正则表达式简单得多。
哎呀! 我突然想到,使用 Java 更简单的语法,您还可以打开大括号列表,只需在正确的语言常量中设置 enum 关键字即可。如果是这样,那么您的解决方案可能很简单:
(c-lang-defconst c-inexpr-brace-list-kwds
java '("enum"))
这不适用于 C#,因为它的语法更复杂。
编辑 - 不,那没有用。比这更复杂。