summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-05-14 11:52:23 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-14 11:52:23 +0100
commitde5cf287812510d2c8ffe66b99cf33c4e1a6e6f1 (patch)
tree1da7638f0773297167182c800faa03b20f7acdb3 /src
parent4b93674159d60c985de906c30f45dbaf2b64056f (diff)
patch 8.2.4951: smart indenting done when not enabledv8.2.4951
Problem: Smart indenting done when not enabled. Solution: Check option values before setting can_si. (closes #10420)
Diffstat (limited to 'src')
-rw-r--r--src/change.c9
-rw-r--r--src/edit.c2
-rw-r--r--src/indent.c18
-rw-r--r--src/ops.c7
-rw-r--r--src/proto/indent.pro1
-rw-r--r--src/testdir/test_smartindent.vim17
-rw-r--r--src/version.c2
7 files changed, 40 insertions, 16 deletions
diff --git a/src/change.c b/src/change.c
index 8ba0a54f4a..b7618c5ba8 100644
--- a/src/change.c
+++ b/src/change.c
@@ -1392,14 +1392,7 @@ open_line(
int do_cindent;
#endif
#ifdef FEAT_SMARTINDENT
- int do_si = (!p_paste && curbuf->b_p_si
-# ifdef FEAT_CINDENT
- && !curbuf->b_p_cin
-# endif
-# ifdef FEAT_EVAL
- && *curbuf->b_p_inde == NUL
-# endif
- );
+ int do_si = may_do_si();
int no_si = FALSE; // reset did_si afterwards
int first_char = NUL; // init for GCC
#endif
diff --git a/src/edit.c b/src/edit.c
index 3da3db67b7..5b06131f96 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -1295,7 +1295,7 @@ docomplete:
#endif
compl_busy = FALSE;
#ifdef FEAT_SMARTINDENT
- can_si = TRUE; // allow smartindenting
+ can_si = may_do_si(); // allow smartindenting
#endif
break;
diff --git a/src/indent.c b/src/indent.c
index 06d98f92ec..dfc481a785 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -1169,6 +1169,22 @@ preprocs_left(void)
#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.
* Used when inserting a "normal" character.
*/
@@ -1235,7 +1251,7 @@ ins_try_si(int c)
}
// 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
old_indent = get_indent();
diff --git a/src/ops.c b/src/ops.c
index 4adeb09453..b11cbf5416 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -1718,12 +1718,7 @@ op_change(oparg_T *oap)
{
l = 0;
#ifdef FEAT_SMARTINDENT
- if (!p_paste && curbuf->b_p_si
-# ifdef FEAT_CINDENT
- && !curbuf->b_p_cin
-# endif
- )
- can_si = TRUE; // It's like opening a new line, do si
+ can_si = may_do_si(); // Like opening a new line, do smart indent
#endif
}
diff --git a/src/proto/indent.pro b/src/proto/indent.pro
index a42f20f0d6..2702f40ab7 100644
--- a/src/proto/indent.pro
+++ b/src/proto/indent.pro
@@ -23,6 +23,7 @@ int get_breakindent_win(win_T *wp, char_u *line);
int inindent(int extra);
void op_reindent(oparg_T *oap, int (*how)(void));
int preprocs_left(void);
+int may_do_si(void);
void ins_try_si(int c);
void change_indent(int type, int amount, int round, int replaced, int call_changed_bytes);
int copy_indent(int size, char_u *src);
diff --git a/src/testdir/test_smartindent.vim b/src/testdir/test_smartindent.vim
index 7b58af2491..edfec9a809 100644
--- a/src/testdir/test_smartindent.vim
+++ b/src/testdir/test_smartindent.vim
@@ -134,4 +134,21 @@ func Test_si_with_paste()
bw!
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
diff --git a/src/version.c b/src/version.c
index 8d3f2e76f1..c9ec30111b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4951,
+/**/
4950,
/**/
4949,