mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
This commit is contained in:
parent
9028b10dfe
commit
3acfc30409
@ -430,6 +430,24 @@ assume a 'shiftwidth' of 4.
|
|||||||
do_something();
|
do_something();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
<
|
||||||
|
*javascript-cinoptions* *javascript-indenting*
|
||||||
|
JN Indent JavaScript object declarations correctly by not confusing
|
||||||
|
them with labels. The value 'N' is currently unused but must be
|
||||||
|
non-zero (e.g. 'J1'). >
|
||||||
|
|
||||||
|
var bar = {
|
||||||
|
foo: {
|
||||||
|
that: this,
|
||||||
|
some: ok,
|
||||||
|
},
|
||||||
|
"bar":{
|
||||||
|
a : 2,
|
||||||
|
b: "123abc",
|
||||||
|
x: 4,
|
||||||
|
"y": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
<
|
<
|
||||||
)N Vim searches for unclosed parentheses at most N lines away.
|
)N Vim searches for unclosed parentheses at most N lines away.
|
||||||
This limits the time needed to search for parentheses. (default
|
This limits the time needed to search for parentheses. (default
|
||||||
|
@ -1089,11 +1089,10 @@ Patch to support horizontal scroll wheel in GTK. Untested. (Bjorn Winckler,
|
|||||||
|
|
||||||
|
|
||||||
Vim 7.3:
|
Vim 7.3:
|
||||||
- soon: remove UF_VERSION_CRYPT_PREV and UF_VERSION_PREV.
|
- Soon: remove UF_VERSION_CRYPT_PREV and UF_VERSION_PREV.
|
||||||
- Conceal feature: no update when moving to another window. (Dominique Pelle,
|
- Conceal feature: no update when moving to another window. (Dominique Pelle,
|
||||||
2010 Jul 5) Vince will look into it.
|
2010 Jul 5) Vince will look into it.
|
||||||
Patches to possibly include:
|
Patches to possibly include:
|
||||||
- Patch to support :browse for more commands. (Lech Lorens, 2009 Jul 18)
|
|
||||||
- Patch to improve javascript indenting. (Hari Kumar G, 2010 May 22)
|
- Patch to improve javascript indenting. (Hari Kumar G, 2010 May 22)
|
||||||
- Patch to use return value of 'formatexpr'. (James Vega, 2010 Jun 16)
|
- Patch to use return value of 'formatexpr'. (James Vega, 2010 Jun 16)
|
||||||
- Patch for gtk main_loop() to enable GtkFileChooser. (James Vega, 2010 Jun 28)
|
- Patch for gtk main_loop() to enable GtkFileChooser. (James Vega, 2010 Jun 28)
|
||||||
|
@ -11,5 +11,6 @@ let b:did_indent = 1
|
|||||||
|
|
||||||
" C indenting is not too bad.
|
" C indenting is not too bad.
|
||||||
setlocal cindent
|
setlocal cindent
|
||||||
|
setlocal cinoptions+=j1,J1
|
||||||
|
|
||||||
let b:undo_indent = "setl cin<"
|
let b:undo_indent = "setl cin<"
|
||||||
|
@ -7545,7 +7545,8 @@ in_cinkeys(keytyped, when, line_is_empty)
|
|||||||
if (try_match && keytyped == ':')
|
if (try_match && keytyped == ':')
|
||||||
{
|
{
|
||||||
p = ml_get_curline();
|
p = ml_get_curline();
|
||||||
if (cin_iscase(p) || cin_isscopedecl(p) || cin_islabel(30))
|
if (cin_iscase(p, FALSE) || cin_isscopedecl(p)
|
||||||
|
|| cin_islabel(30))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
/* Need to get the line again after cin_islabel(). */
|
/* Need to get the line again after cin_islabel(). */
|
||||||
p = ml_get_curline();
|
p = ml_get_curline();
|
||||||
@ -7554,7 +7555,7 @@ in_cinkeys(keytyped, when, line_is_empty)
|
|||||||
&& p[curwin->w_cursor.col - 2] == ':')
|
&& p[curwin->w_cursor.col - 2] == ':')
|
||||||
{
|
{
|
||||||
p[curwin->w_cursor.col - 1] = ' ';
|
p[curwin->w_cursor.col - 1] = ' ';
|
||||||
i = (cin_iscase(p) || cin_isscopedecl(p)
|
i = (cin_iscase(p, FALSE) || cin_isscopedecl(p)
|
||||||
|| cin_islabel(30));
|
|| cin_islabel(30));
|
||||||
p = ml_get_curline();
|
p = ml_get_curline();
|
||||||
p[curwin->w_cursor.col - 1] = ':';
|
p[curwin->w_cursor.col - 1] = ':';
|
||||||
|
57
src/misc1.c
57
src/misc1.c
@ -5050,7 +5050,7 @@ cin_islabel(ind_maxcomment) /* XXX */
|
|||||||
curwin->w_cursor = cursor_save;
|
curwin->w_cursor = cursor_save;
|
||||||
if (cin_isterminated(line, TRUE, FALSE)
|
if (cin_isterminated(line, TRUE, FALSE)
|
||||||
|| cin_isscopedecl(line)
|
|| cin_isscopedecl(line)
|
||||||
|| cin_iscase(line)
|
|| cin_iscase(line, TRUE)
|
||||||
|| (cin_islabel_skip(&line) && cin_nocode(line)))
|
|| (cin_islabel_skip(&line) && cin_nocode(line)))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -5089,8 +5089,9 @@ cin_isinit(void)
|
|||||||
* Recognize a switch label: "case .*:" or "default:".
|
* Recognize a switch label: "case .*:" or "default:".
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
cin_iscase(s)
|
cin_iscase(s, strict)
|
||||||
char_u *s;
|
char_u *s;
|
||||||
|
int strict; /* Allow relaxed check of case statement for JS */
|
||||||
{
|
{
|
||||||
s = cin_skipcomment(s);
|
s = cin_skipcomment(s);
|
||||||
if (STRNCMP(s, "case", 4) == 0 && !vim_isIDc(s[4]))
|
if (STRNCMP(s, "case", 4) == 0 && !vim_isIDc(s[4]))
|
||||||
@ -5106,11 +5107,17 @@ cin_iscase(s)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (*s == '\'' && s[1] && s[2] == '\'')
|
if (*s == '\'' && s[1] && s[2] == '\'')
|
||||||
s += 2; /* skip over '.' */
|
s += 2; /* skip over ':' */
|
||||||
else if (*s == '/' && (s[1] == '*' || s[1] == '/'))
|
else if (*s == '/' && (s[1] == '*' || s[1] == '/'))
|
||||||
return FALSE; /* stop at comment */
|
return FALSE; /* stop at comment */
|
||||||
else if (*s == '"')
|
else if (*s == '"')
|
||||||
return FALSE; /* stop at string */
|
{
|
||||||
|
/* JS etc. */
|
||||||
|
if (strict)
|
||||||
|
return FALSE; /* stop at string */
|
||||||
|
else
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -5169,7 +5176,7 @@ after_label(l)
|
|||||||
{
|
{
|
||||||
if (l[1] == ':') /* skip over "::" for C++ */
|
if (l[1] == ':') /* skip over "::" for C++ */
|
||||||
++l;
|
++l;
|
||||||
else if (!cin_iscase(l + 1))
|
else if (!cin_iscase(l + 1, FALSE))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (*l == '\'' && l[1] && l[2] == '\'')
|
else if (*l == '\'' && l[1] && l[2] == '\'')
|
||||||
@ -5227,7 +5234,8 @@ skip_label(lnum, pp, ind_maxcomment)
|
|||||||
curwin->w_cursor.lnum = lnum;
|
curwin->w_cursor.lnum = lnum;
|
||||||
l = ml_get_curline();
|
l = ml_get_curline();
|
||||||
/* XXX */
|
/* XXX */
|
||||||
if (cin_iscase(l) || cin_isscopedecl(l) || cin_islabel(ind_maxcomment))
|
if (cin_iscase(l, FALSE) || cin_isscopedecl(l)
|
||||||
|
|| cin_islabel(ind_maxcomment))
|
||||||
{
|
{
|
||||||
amount = get_indent_nolabel(lnum);
|
amount = get_indent_nolabel(lnum);
|
||||||
l = after_label(ml_get_curline());
|
l = after_label(ml_get_curline());
|
||||||
@ -6173,6 +6181,11 @@ get_c_indent()
|
|||||||
*/
|
*/
|
||||||
int ind_java = 0;
|
int ind_java = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* not to confuse JS object properties with labels
|
||||||
|
*/
|
||||||
|
int ind_js = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* handle blocked cases correctly
|
* handle blocked cases correctly
|
||||||
*/
|
*/
|
||||||
@ -6286,6 +6299,7 @@ get_c_indent()
|
|||||||
case 'g': ind_scopedecl = n; break;
|
case 'g': ind_scopedecl = n; break;
|
||||||
case 'h': ind_scopedecl_code = n; break;
|
case 'h': ind_scopedecl_code = n; break;
|
||||||
case 'j': ind_java = n; break;
|
case 'j': ind_java = n; break;
|
||||||
|
case 'J': ind_js = n; break;
|
||||||
case 'l': ind_keep_case_label = n; break;
|
case 'l': ind_keep_case_label = n; break;
|
||||||
case '#': ind_hash_comment = n; break;
|
case '#': ind_hash_comment = n; break;
|
||||||
}
|
}
|
||||||
@ -6296,6 +6310,10 @@ get_c_indent()
|
|||||||
/* remember where the cursor was when we started */
|
/* remember where the cursor was when we started */
|
||||||
cur_curpos = curwin->w_cursor;
|
cur_curpos = curwin->w_cursor;
|
||||||
|
|
||||||
|
/* if we are at line 1 0 is fine, right? */
|
||||||
|
if (cur_curpos.lnum == 1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* Get a copy of the current contents of the line.
|
/* Get a copy of the current contents of the line.
|
||||||
* This is required, because only the most recent line obtained with
|
* This is required, because only the most recent line obtained with
|
||||||
* ml_get is valid! */
|
* ml_get is valid! */
|
||||||
@ -6330,9 +6348,9 @@ get_c_indent()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Is it a non-case label? Then that goes at the left margin too.
|
* Is it a non-case label? Then that goes at the left margin too unless JS flag is set.
|
||||||
*/
|
*/
|
||||||
else if (cin_islabel(ind_maxcomment)) /* XXX */
|
else if (!ind_js && cin_islabel(ind_maxcomment)) /* XXX */
|
||||||
{
|
{
|
||||||
amount = 0;
|
amount = 0;
|
||||||
}
|
}
|
||||||
@ -6783,7 +6801,8 @@ get_c_indent()
|
|||||||
* ldfd) {
|
* ldfd) {
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
if (ind_keep_case_label && cin_iscase(skipwhite(ml_get_curline())))
|
if ((ind_keep_case_label
|
||||||
|
&& cin_iscase(skipwhite(ml_get_curline()), FALSE)))
|
||||||
amount = get_indent();
|
amount = get_indent();
|
||||||
else
|
else
|
||||||
amount = skip_label(lnum, &l, ind_maxcomment);
|
amount = skip_label(lnum, &l, ind_maxcomment);
|
||||||
@ -6861,7 +6880,7 @@ get_c_indent()
|
|||||||
|
|
||||||
lookfor_break = FALSE;
|
lookfor_break = FALSE;
|
||||||
|
|
||||||
if (cin_iscase(theline)) /* it's a switch() label */
|
if (cin_iscase(theline, FALSE)) /* it's a switch() label */
|
||||||
{
|
{
|
||||||
lookfor = LOOKFOR_CASE; /* find a previous switch() label */
|
lookfor = LOOKFOR_CASE; /* find a previous switch() label */
|
||||||
amount += ind_case;
|
amount += ind_case;
|
||||||
@ -6922,7 +6941,7 @@ get_c_indent()
|
|||||||
* initialization) */
|
* initialization) */
|
||||||
if (cont_amount > 0)
|
if (cont_amount > 0)
|
||||||
amount = cont_amount;
|
amount = cont_amount;
|
||||||
else
|
else if (!ind_js)
|
||||||
amount += ind_continuation;
|
amount += ind_continuation;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -7046,7 +7065,7 @@ get_c_indent()
|
|||||||
* If this is a switch() label, may line up relative to that.
|
* If this is a switch() label, may line up relative to that.
|
||||||
* If this is a C++ scope declaration, do the same.
|
* If this is a C++ scope declaration, do the same.
|
||||||
*/
|
*/
|
||||||
iscase = cin_iscase(l);
|
iscase = cin_iscase(l, FALSE);
|
||||||
if (iscase || cin_isscopedecl(l))
|
if (iscase || cin_isscopedecl(l))
|
||||||
{
|
{
|
||||||
/* we are only looking for cpp base class
|
/* we are only looking for cpp base class
|
||||||
@ -7170,7 +7189,7 @@ get_c_indent()
|
|||||||
/*
|
/*
|
||||||
* Ignore jump labels with nothing after them.
|
* Ignore jump labels with nothing after them.
|
||||||
*/
|
*/
|
||||||
if (cin_islabel(ind_maxcomment))
|
if (!ind_js && cin_islabel(ind_maxcomment))
|
||||||
{
|
{
|
||||||
l = after_label(ml_get_curline());
|
l = after_label(ml_get_curline());
|
||||||
if (l == NULL || cin_nocode(l))
|
if (l == NULL || cin_nocode(l))
|
||||||
@ -7281,7 +7300,7 @@ get_c_indent()
|
|||||||
*/
|
*/
|
||||||
curwin->w_cursor = *trypos;
|
curwin->w_cursor = *trypos;
|
||||||
l = ml_get_curline();
|
l = ml_get_curline();
|
||||||
if (cin_iscase(l) || cin_isscopedecl(l))
|
if (cin_iscase(l, FALSE) || cin_isscopedecl(l))
|
||||||
{
|
{
|
||||||
++curwin->w_cursor.lnum;
|
++curwin->w_cursor.lnum;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
@ -7312,9 +7331,11 @@ get_c_indent()
|
|||||||
* Get indent and pointer to text for current line,
|
* Get indent and pointer to text for current line,
|
||||||
* ignoring any jump label. XXX
|
* ignoring any jump label. XXX
|
||||||
*/
|
*/
|
||||||
cur_amount = skip_label(curwin->w_cursor.lnum,
|
if (!ind_js)
|
||||||
|
cur_amount = skip_label(curwin->w_cursor.lnum,
|
||||||
&l, ind_maxcomment);
|
&l, ind_maxcomment);
|
||||||
|
else
|
||||||
|
cur_amount = get_indent();
|
||||||
/*
|
/*
|
||||||
* If this is just above the line we are indenting, and it
|
* If this is just above the line we are indenting, and it
|
||||||
* starts with a '{', line it up with this line.
|
* starts with a '{', line it up with this line.
|
||||||
@ -7640,7 +7661,7 @@ term_again:
|
|||||||
*/
|
*/
|
||||||
curwin->w_cursor = *trypos;
|
curwin->w_cursor = *trypos;
|
||||||
l = ml_get_curline();
|
l = ml_get_curline();
|
||||||
if (cin_iscase(l) || cin_isscopedecl(l))
|
if (cin_iscase(l, FALSE) || cin_isscopedecl(l))
|
||||||
{
|
{
|
||||||
++curwin->w_cursor.lnum;
|
++curwin->w_cursor.lnum;
|
||||||
curwin->w_cursor.col = 0;
|
curwin->w_cursor.col = 0;
|
||||||
@ -7657,7 +7678,7 @@ term_again:
|
|||||||
* stat;
|
* stat;
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
iscase = (ind_keep_case_label && cin_iscase(l));
|
iscase = (ind_keep_case_label && cin_iscase(l, FALSE));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get indent and pointer to text for current line,
|
* Get indent and pointer to text for current line,
|
||||||
|
@ -76,7 +76,7 @@ char_u *FullName_save __ARGS((char_u *fname, int force));
|
|||||||
pos_T *find_start_comment __ARGS((int ind_maxcomment));
|
pos_T *find_start_comment __ARGS((int ind_maxcomment));
|
||||||
void do_c_expr_indent __ARGS((void));
|
void do_c_expr_indent __ARGS((void));
|
||||||
int cin_islabel __ARGS((int ind_maxcomment));
|
int cin_islabel __ARGS((int ind_maxcomment));
|
||||||
int cin_iscase __ARGS((char_u *s));
|
int cin_iscase __ARGS((char_u *s, int strict));
|
||||||
int cin_isscopedecl __ARGS((char_u *s));
|
int cin_isscopedecl __ARGS((char_u *s));
|
||||||
int get_c_indent __ARGS((void));
|
int get_c_indent __ARGS((void));
|
||||||
int get_expr_indent __ARGS((void));
|
int get_expr_indent __ARGS((void));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user