To: vim_dev@googlegroups.com Subject: Patch 8.2.4951 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4951 Problem: Smart indenting done when not enabled. Solution: Check option values before setting can_si. (closes #10420) Files: src/indent.c, src/proto/indent.pro, src/change.c, src/edit.c, src/ops.c, src/testdir/test_smartindent.vim *** ../vim-8.2.4950/src/indent.c 2022-05-09 20:09:19.286641426 +0100 --- src/indent.c 2022-05-14 11:50:09.925281315 +0100 *************** *** 1169,1174 **** --- 1169,1190 ---- #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,1241 **** } // set indent of '#' always to 0 ! if (curwin->w_cursor.col > 0 && can_si && c == '#') { // remember current indent for next line old_indent = get_indent(); --- 1251,1257 ---- } // set indent of '#' always to 0 ! if (curwin->w_cursor.col > 0 && can_si && c == '#' && inindent(0)) { // remember current indent for next line old_indent = get_indent(); *** ../vim-8.2.4950/src/proto/indent.pro 2019-12-12 11:55:25.000000000 +0000 --- src/proto/indent.pro 2022-05-14 11:23:36.658313138 +0100 *************** *** 23,28 **** --- 23,29 ---- 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); *** ../vim-8.2.4950/src/change.c 2022-05-12 18:45:14.778530646 +0100 --- src/change.c 2022-05-14 11:22:36.906358226 +0100 *************** *** 1392,1405 **** 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 no_si = FALSE; // reset did_si afterwards int first_char = NUL; // init for GCC #endif --- 1392,1398 ---- int do_cindent; #endif #ifdef FEAT_SMARTINDENT ! int do_si = may_do_si(); int no_si = FALSE; // reset did_si afterwards int first_char = NUL; // init for GCC #endif *** ../vim-8.2.4950/src/edit.c 2022-05-09 20:09:19.282641427 +0100 --- src/edit.c 2022-05-14 11:42:49.485313440 +0100 *************** *** 1295,1301 **** #endif compl_busy = FALSE; #ifdef FEAT_SMARTINDENT ! can_si = TRUE; // allow smartindenting #endif break; --- 1295,1301 ---- #endif compl_busy = FALSE; #ifdef FEAT_SMARTINDENT ! can_si = may_do_si(); // allow smartindenting #endif break; *** ../vim-8.2.4950/src/ops.c 2022-05-13 21:56:24.589080012 +0100 --- src/ops.c 2022-05-14 11:30:25.565978793 +0100 *************** *** 1718,1729 **** { 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 #endif } --- 1718,1724 ---- { l = 0; #ifdef FEAT_SMARTINDENT ! can_si = may_do_si(); // Like opening a new line, do smart indent #endif } *** ../vim-8.2.4950/src/testdir/test_smartindent.vim 2021-06-16 14:53:13.072696639 +0100 --- src/testdir/test_smartindent.vim 2022-05-14 11:35:15.997724289 +0100 *************** *** 134,137 **** --- 134,154 ---- bw! 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 *** ../vim-8.2.4950/src/version.c 2022-05-13 21:56:24.589080012 +0100 --- src/version.c 2022-05-14 11:36:29.477658565 +0100 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4951, /**/ -- hundred-and-one symptoms of being an internet addict: 191. You rate eating establishments not by the quality of the food, but by the availability of electrical outlets for your PowerBook. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///