To: vim_dev@googlegroups.com Subject: Patch 9.0.0841 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0841 Problem: deletebufline() does not always return 1 on failure. Solution: Refactor the code to make it work more predictable. (closes #11511) Files: src/evalbuffer.c, src/testdir/test_bufline.vim *** ../vim-9.0.0840/src/evalbuffer.c 2022-11-05 23:46:30.720146269 +0000 --- src/evalbuffer.c 2022-11-06 22:25:28.819970489 +0000 *************** *** 535,540 **** --- 535,541 ---- || first > buf->b_ml.ml_line_count || last < first) return; + // After this don't use "return", goto "cleanup"! if (!is_curbuf) { VIsual_active = FALSE; *************** *** 556,593 **** } if (u_save(first - 1, last + 1) == FAIL) ! { ! rettv->vval.v_number = 1; // FAIL ! } ! else ! { ! for (lnum = first; lnum <= last; ++lnum) ! ml_delete_flags(first, ML_DEL_MESSAGE); ! FOR_ALL_TAB_WINDOWS(tp, wp) ! if (wp->w_buffer == buf) ! { ! if (wp->w_cursor.lnum > last) ! wp->w_cursor.lnum -= count; ! else if (wp->w_cursor.lnum > first) ! wp->w_cursor.lnum = first; ! if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) ! wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count; ! wp->w_valid = 0; ! if (wp->w_cursor.lnum <= wp->w_topline) ! wp->w_topline = 1; ! } ! check_cursor_col(); ! deleted_lines_mark(first, count); ! } if (!is_curbuf) { curbuf = curbuf_save; curwin = curwin_save; VIsual_active = save_VIsual_active; } - rettv->vval.v_number = 0; // OK } /* --- 557,591 ---- } if (u_save(first - 1, last + 1) == FAIL) ! goto cleanup; ! for (lnum = first; lnum <= last; ++lnum) ! ml_delete_flags(first, ML_DEL_MESSAGE); + FOR_ALL_TAB_WINDOWS(tp, wp) + if (wp->w_buffer == buf) + { + if (wp->w_cursor.lnum > last) + wp->w_cursor.lnum -= count; + else if (wp->w_cursor.lnum > first) + wp->w_cursor.lnum = first; + if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) + wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count; + wp->w_valid = 0; + if (wp->w_cursor.lnum <= wp->w_topline) + wp->w_topline = 1; + } + check_cursor_col(); + deleted_lines_mark(first, count); + rettv->vval.v_number = 0; // OK + + cleanup: if (!is_curbuf) { curbuf = curbuf_save; curwin = curwin_save; VIsual_active = save_VIsual_active; } } /* *** ../vim-9.0.0840/src/testdir/test_bufline.vim 2022-11-05 23:46:30.720146269 +0000 --- src/testdir/test_bufline.vim 2022-11-06 22:17:25.107880312 +0000 *************** *** 279,282 **** --- 279,298 ---- call delete('Xresult') endfunc + " Test that setbufline(), appendbufline() and deletebufline() should fail and + " return 1 when "textlock" is active. + func Test_change_bufline_with_textlock() + new + inoremap setbufline('', 1, '') + call assert_fails("normal a\", 'E565:') + call assert_equal('1', getline(1)) + inoremap appendbufline('', 1, '') + call assert_fails("normal a\", 'E565:') + call assert_equal('11', getline(1)) + inoremap deletebufline('', 1) + call assert_fails("normal a\", 'E565:') + call assert_equal('111', getline(1)) + bwipe! + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-9.0.0840/src/version.c 2022-11-06 18:27:09.363922860 +0000 --- src/version.c 2022-11-06 22:20:24.971907239 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 841, /**/ -- How To Keep A Healthy Level Of Insanity: 16. Have your coworkers address you by your wrestling name, Rock Hard Kim. /// 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 ///