Emums enum indentation

I have a problem with Emacs nesting Java enumerations. Although he backs away from the first member of OK, he wants to provide all the other members of the static member of the enumeration with an extra level of indentation. It looks like this:

class MyClass { public enum MyEnum { ONE(1), //good TWO(2), // not good! THREE(3), FOUR(4); private final int value; } } 

When I run Cc Cs on a line that opens an enumeration, it gives me ((inclass 1) (topmost-intro 1)) , which seems not quite right - it seems like it should give brace-list-open . When I run it in the first member of the enum, it gives me ((defun-block-intro 21)) , which is definitely not the case. Each subsequent member gives (statement-cont 50) .

I am in java mode and I am using java indentation style. Does anyone know what the problem is?

+4
source share
4 answers

The problem is that Emacs does not support Java features added in version 1.5 or later. For example, you will also have problems with generics.

EDIT: Surprisingly, a Google search for java enum: debbugs.gnu.org does not return any results. I suggest giving an error.

+4
source

The same problem existed in csharp mode until the last week. The way I fixed this was to add new matches in the c-basic-matchers-after setting for csharp. The new match is as follows:

 ;; 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)) ))) 

where csharp-enum-decl-re is defined as

 (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#" ) 

In this case, the text property is set in parenthesis after the enum declaration line. This text property tells cc-mode to put the contents of the brackets list differently. Like a โ€œbrackets listโ€. Setting this property gets brace-list-open on the next line.

Perhaps something like this will work for you.

You can configure the java helpers yourself, with something like this, and if you open an error, you can send this as a recommended fix.

In C #, enums can be inferred from any integer type. so

 public enum MyEnumType : uint { ONE = 1, TWO, THREE, } 

I think that in Java there is no such possibility. If so, the Java regular expression will be much simpler than the regular expression I used for C #.


Whoops! It just occurred to me that with the simpler Java syntax, there is also the possibility of including parenthesis lists by simply setting the enum keyword in the correct language constant. If so, then the solution for you may be as simple as:

 (c-lang-defconst c-inexpr-brace-list-kwds java '("enum")) 

This did not work for C # due to its more complex syntax.


EDIT - No, that didn't work. It is harder than that.

+1
source

The CVS CC-mode version does indeed contain the necessary fixes, as Nathaniel Flat mentioned earlier. It is easy to install. Just check it from here (say, in ~ / .emacs.d / cc-mode), byte compilation, as explained in readme, and add the download path by adding (add to the list "load-path" ~ / .emacs. d / cc-mode ") to your ~ / .emacs.d / init.el. Then the listing enumeration works like a charm!

+1
source

You can try using JDEE - I heard that they planned to include support for Java 6. Or, if you are more adventurous, you can try malabar-mode , which claims to be better than JDEE. It is funny that the last command in malabar (from a day ago) has the following message: "Fix permanent indent enum" :-)

0
source

Source: https://habr.com/ru/post/1308490/


All Articles