Hi All,
The attachment is a patch to add an 'cinoption' to correctly indent enum for
Java code.
Currently enum for C could be indent correctly:
enum {
MON,
TUE,
WED
};
But for Java code, the indentation would be incorrect:
public enum {
MON,
TUE,
}
The attachment adds an option 'E' to 'cinoptions' to solve this problem. The
patch also includes the modification to the help file.
Thanks!
Hong
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff -r ad7bbe9ea65b runtime/doc/indent.txt
--- a/runtime/doc/indent.txt Tue Feb 26 22:54:11 2013 +0100
+++ b/runtime/doc/indent.txt Tue Mar 05 01:11:31 2013 -0800
@@ -513,6 +513,19 @@
}
});
<
+ *cino-E*
+ EN Indent Java enumerations correctly. Also works well for C#. The
+ value 'N' is currently unused but must be non-zero (e.g. 'E1').
+ 'E1' will indent for example the following code snippet
+ correctly: >
+
+ public enum {
+ MON,
+ TUE,
+ WED
+ };
+<
+
*javascript-cinoptions* *javascript-indenting* *cino-J*
JN Indent JavaScript object declarations correctly by not confusing
them with labels. The value 'N' is currently unused but must be
diff -r ad7bbe9ea65b src/misc1.c
--- a/src/misc1.c Tue Feb 26 22:54:11 2013 +0100
+++ b/src/misc1.c Tue Mar 05 01:11:31 2013 -0800
@@ -5263,7 +5263,7 @@
static int cin_iscomment __ARGS((char_u *));
static int cin_islinecomment __ARGS((char_u *));
static int cin_isterminated __ARGS((char_u *, int, int));
-static int cin_isinit __ARGS((void));
+static int cin_isinit __ARGS((int));
static int cin_isfuncdecl __ARGS((char_u **, linenr_T, linenr_T, int, int));
static int cin_isif __ARGS((char_u *));
static int cin_iselse __ARGS((char_u *));
@@ -5451,7 +5451,8 @@
* check for "=" at end or "[typedef] enum" at beginning of line.
*/
static int
-cin_isinit(void)
+cin_isinit(ind_javaenum)
+ int ind_javaenum;
{
char_u *s;
@@ -5463,6 +5464,38 @@
if (STRNCMP(s, "static", 6) == 0 && !vim_isIDc(s[6]))
s = cin_skipcomment(s + 6);
+ if (ind_javaenum)
+ {
+ for (;;)
+ {
+ if (STRNCMP(s, "static", 6) == 0 && !vim_isIDc(s[6]))
+ {
+ s = cin_skipcomment(s + 6);
+ continue;
+ }
+
+ if (STRNCMP(s, "public", 6) == 0 && !vim_isIDc(s[6]))
+ {
+ s = cin_skipcomment(s + 6);
+ continue;
+ }
+
+ if (STRNCMP(s, "protected", 9) == 0 && !vim_isIDc(s[9]))
+ {
+ s = cin_skipcomment(s + 9);
+ continue;
+ }
+
+ if (STRNCMP(s, "private", 7) == 0 && !vim_isIDc(s[7]))
+ {
+ s = cin_skipcomment(s + 7);
+ continue;
+ }
+
+ break;
+ }
+ }
+
if (STRNCMP(s, "enum", 4) == 0 && !vim_isIDc(s[4]))
return TRUE;
@@ -6726,6 +6759,11 @@
int ind_java = 0;
/*
+ * handle enums for java code
+ */
+ int ind_javaenum = 0;
+
+ /*
* not to confuse JS object properties with labels
*/
int ind_js = 0;
@@ -6860,6 +6898,7 @@
case 'g': ind_scopedecl = n; break;
case 'h': ind_scopedecl_code = n; break;
case 'j': ind_java = n; break;
+ case 'E': ind_javaenum = n; break;
case 'J': ind_js = n; break;
case 'l': ind_keep_case_label = n; break;
case '#': ind_hash_comment = n; break;
@@ -7607,7 +7646,7 @@
/* if it es a enum declaration or an assignment,
* we are done.
*/
- if (terminated != ';' && cin_isinit())
+ if (terminated != ';' && cin_isinit(ind_javaenum))
break;
/* nothing useful found */