From 24eb1af4754b3061d0968112342ca5389b68d4f6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 14 May 2022 18:55:50 +0800 Subject: vim-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 vim/vim#10420) https://github.com/vim/vim/commit/de5cf287812510d2c8ffe66b99cf33c4e1a6e6f1 --- src/nvim/change.c | 3 +-- src/nvim/edit.c | 4 ++-- src/nvim/indent.c | 5 +++++ src/nvim/ops.c | 5 +---- src/nvim/testdir/test_smartindent.vim | 17 +++++++++++++++++ 5 files changed, 26 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nvim/change.c b/src/nvim/change.c index b15e90e0bc..091e9b2830 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -963,8 +963,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) char_u *p; char_u saved_char = NUL; // init for GCC pos_T *pos; - bool do_si = (!p_paste && curbuf->b_p_si && !curbuf->b_p_cin - && *curbuf->b_p_inde == NUL); + bool do_si = may_do_si(); bool do_cindent; bool no_si = false; // reset did_si afterwards int first_char = NUL; // init for GCC diff --git a/src/nvim/edit.c b/src/nvim/edit.c index c2e61271c7..f2982aa187 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -1396,7 +1396,7 @@ static void insert_do_complete(InsertState *s) compl_cont_status = 0; } compl_busy = false; - can_si = true; // allow smartindenting + can_si = may_do_si(); // allow smartindenting } static void insert_do_cindent(InsertState *s) @@ -9403,7 +9403,7 @@ static void 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(); (void)set_indent(0, SIN_CHANGED); diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 1c4486b67d..faf6f2dc8f 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -522,6 +522,11 @@ int inindent(int extra) } } +/// @return true if the conditions are OK for smart indenting. +bool may_do_si(void) +{ + return curbuf->b_p_si && !curbuf->b_p_cin && *curbuf->b_p_inde == NUL && !p_paste; +} // Get indent level from 'indentexpr'. int get_expr_indent(void) diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 7b3895333b..1342b10bf8 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2507,10 +2507,7 @@ int op_change(oparg_T *oap) l = oap->start.col; if (oap->motion_type == kMTLineWise) { l = 0; - if (!p_paste && curbuf->b_p_si - && !curbuf->b_p_cin) { - 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 } // First delete the text in the region. In an empty buffer only need to diff --git a/src/nvim/testdir/test_smartindent.vim b/src/nvim/testdir/test_smartindent.vim index dc0f99e93f..3d685eb2fe 100644 --- a/src/nvim/testdir/test_smartindent.vim +++ b/src/nvim/testdir/test_smartindent.vim @@ -61,4 +61,21 @@ func Test_smartindent_braces() close! endfunc +func Test_si_after_completion() + new + setlocal ai smartindent indentexpr= + call setline(1, 'foo foot') + call feedkeys("o f\\#", '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\\#", 'tx') + call assert_equal(' foo#', getline(2)) + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab -- cgit