mirror of
https://github.com/vim/vim.git
synced 2025-09-27 04:14:06 -04:00
patch 8.2.4951: smart indenting done when not enabled
Problem: Smart indenting done when not enabled. Solution: Check option values before setting can_si. (closes #10420)
This commit is contained in:
@@ -1392,14 +1392,7 @@ open_line(
|
|||||||
int do_cindent;
|
int do_cindent;
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_SMARTINDENT
|
#ifdef FEAT_SMARTINDENT
|
||||||
int do_si = (!p_paste && curbuf->b_p_si
|
int do_si = may_do_si();
|
||||||
# ifdef FEAT_CINDENT
|
|
||||||
&& !curbuf->b_p_cin
|
|
||||||
# endif
|
|
||||||
# ifdef FEAT_EVAL
|
|
||||||
&& *curbuf->b_p_inde == NUL
|
|
||||||
# endif
|
|
||||||
);
|
|
||||||
int no_si = FALSE; // reset did_si afterwards
|
int no_si = FALSE; // reset did_si afterwards
|
||||||
int first_char = NUL; // init for GCC
|
int first_char = NUL; // init for GCC
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1295,7 +1295,7 @@ docomplete:
|
|||||||
#endif
|
#endif
|
||||||
compl_busy = FALSE;
|
compl_busy = FALSE;
|
||||||
#ifdef FEAT_SMARTINDENT
|
#ifdef FEAT_SMARTINDENT
|
||||||
can_si = TRUE; // allow smartindenting
|
can_si = may_do_si(); // allow smartindenting
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
18
src/indent.c
18
src/indent.c
@@ -1168,6 +1168,22 @@ preprocs_left(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEAT_SMARTINDENT
|
#ifdef FEAT_SMARTINDENT
|
||||||
|
/*
|
||||||
|
* Return TRUE if the conditions are OK for smart indenting.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
may_do_si()
|
||||||
|
{
|
||||||
|
return curbuf->b_p_si
|
||||||
|
# ifdef FEAT_CINDENT
|
||||||
|
&& !curbuf->b_p_cin
|
||||||
|
# endif
|
||||||
|
# ifdef FEAT_EVAL
|
||||||
|
&& *curbuf->b_p_inde == NUL
|
||||||
|
# endif
|
||||||
|
&& !p_paste;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try to do some very smart auto-indenting.
|
* Try to do some very smart auto-indenting.
|
||||||
* Used when inserting a "normal" character.
|
* Used when inserting a "normal" character.
|
||||||
@@ -1235,7 +1251,7 @@ ins_try_si(int c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set indent of '#' always to 0
|
// set indent of '#' always to 0
|
||||||
if (curwin->w_cursor.col > 0 && can_si && c == '#')
|
if (curwin->w_cursor.col > 0 && can_si && c == '#' && inindent(0))
|
||||||
{
|
{
|
||||||
// remember current indent for next line
|
// remember current indent for next line
|
||||||
old_indent = get_indent();
|
old_indent = get_indent();
|
||||||
|
@@ -1718,12 +1718,7 @@ op_change(oparg_T *oap)
|
|||||||
{
|
{
|
||||||
l = 0;
|
l = 0;
|
||||||
#ifdef FEAT_SMARTINDENT
|
#ifdef FEAT_SMARTINDENT
|
||||||
if (!p_paste && curbuf->b_p_si
|
can_si = may_do_si(); // Like opening a new line, do smart indent
|
||||||
# ifdef FEAT_CINDENT
|
|
||||||
&& !curbuf->b_p_cin
|
|
||||||
# endif
|
|
||||||
)
|
|
||||||
can_si = TRUE; // It's like opening a new line, do si
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@ int get_breakindent_win(win_T *wp, char_u *line);
|
|||||||
int inindent(int extra);
|
int inindent(int extra);
|
||||||
void op_reindent(oparg_T *oap, int (*how)(void));
|
void op_reindent(oparg_T *oap, int (*how)(void));
|
||||||
int preprocs_left(void);
|
int preprocs_left(void);
|
||||||
|
int may_do_si(void);
|
||||||
void ins_try_si(int c);
|
void ins_try_si(int c);
|
||||||
void change_indent(int type, int amount, int round, int replaced, int call_changed_bytes);
|
void change_indent(int type, int amount, int round, int replaced, int call_changed_bytes);
|
||||||
int copy_indent(int size, char_u *src);
|
int copy_indent(int size, char_u *src);
|
||||||
|
@@ -134,4 +134,21 @@ func Test_si_with_paste()
|
|||||||
bw!
|
bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_si_after_completion()
|
||||||
|
new
|
||||||
|
setlocal ai smartindent indentexpr=
|
||||||
|
call setline(1, 'foo foot')
|
||||||
|
call feedkeys("o f\<C-X>\<C-N>#", 'tx')
|
||||||
|
call assert_equal(' foo#', getline(2))
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_no_si_after_completion()
|
||||||
|
new
|
||||||
|
call setline(1, 'foo foot')
|
||||||
|
call feedkeys("o f\<C-X>\<C-N>#", 'tx')
|
||||||
|
call assert_equal(' foo#', getline(2))
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -746,6 +746,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4951,
|
||||||
/**/
|
/**/
|
||||||
4950,
|
4950,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user