To: vim_dev@googlegroups.com Subject: Patch 8.2.3280 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3280 Problem: 'virtualedit' local to buffer is not the best solution. Solution: Make it window-local. (Gary Johnson, closes #8685) Files: runtime/doc/options.txt, src/buffer.c, src/drawscreen.c, src/ops.c, src/option.c, src/option.h, src/optionstr.c, src/structs.h, src/testdir/test_virtualedit.vim *** ../vim-8.2.3279/runtime/doc/options.txt 2021-07-26 22:19:05.372122592 +0200 --- runtime/doc/options.txt 2021-08-03 18:22:12.256593449 +0200 *************** *** 8634,8640 **** *'virtualedit'* *'ve'* 'virtualedit' 've' string (default "") ! global or local to buffer |global-local| A comma separated list of these words: block Allow virtual editing in Visual block mode. insert Allow virtual editing in Insert mode. --- 8643,8649 ---- *'virtualedit'* *'ve'* 'virtualedit' 've' string (default "") ! global or local to window |global-local| A comma separated list of these words: block Allow virtual editing in Visual block mode. insert Allow virtual editing in Insert mode. *** ../vim-8.2.3279/src/buffer.c 2021-07-29 20:37:45.652199179 +0200 --- src/buffer.c 2021-08-03 18:22:12.260593440 +0200 *************** *** 2388,2394 **** #endif clear_string_option(&buf->b_p_bkc); clear_string_option(&buf->b_p_menc); - clear_string_option(&buf->b_p_ve); } /* --- 2388,2393 ---- *** ../vim-8.2.3279/src/drawscreen.c 2021-07-26 22:19:05.376122583 +0200 --- src/drawscreen.c 2021-08-03 18:22:12.260593440 +0200 *************** *** 2006,2020 **** { colnr_T fromc, toc; #if defined(FEAT_LINEBREAK) ! int save_ve_flags = curbuf->b_ve_flags; if (curwin->w_p_lbr) ! curbuf->b_ve_flags = VE_ALL; #endif getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); ++toc; #if defined(FEAT_LINEBREAK) ! curbuf->b_ve_flags = save_ve_flags; #endif // Highlight to the end of the line, unless 'virtualedit' has // "block". --- 2006,2020 ---- { colnr_T fromc, toc; #if defined(FEAT_LINEBREAK) ! int save_ve_flags = curwin->w_ve_flags; if (curwin->w_p_lbr) ! curwin->w_ve_flags = VE_ALL; #endif getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); ++toc; #if defined(FEAT_LINEBREAK) ! curwin->w_ve_flags = save_ve_flags; #endif // Highlight to the end of the line, unless 'virtualedit' has // "block". *** ../vim-8.2.3279/src/ops.c 2021-07-26 22:19:05.380122574 +0200 --- src/ops.c 2021-08-03 18:22:12.260593440 +0200 *************** *** 1475,1495 **** // already disabled, but still need it when calling // coladvance_force(). // coladvance_force() uses get_ve_flags() to get the 'virtualedit' ! // state for the current buffer. To override that state, we need to ! // set the buffer-local value of ve_flags rather than the global value. if (curwin->w_cursor.coladd > 0) { ! int old_ve_flags = curbuf->b_ve_flags; if (u_save_cursor() == FAIL) return; ! curbuf->b_ve_flags = VE_ALL; coladvance_force(oap->op_type == OP_APPEND ? oap->end_vcol + 1 : getviscol()); if (oap->op_type == OP_APPEND) --curwin->w_cursor.col; ! curbuf->b_ve_flags = old_ve_flags; } // Get the info about the block before entering the text block_prep(oap, &bd, oap->start.lnum, TRUE); --- 1475,1495 ---- // already disabled, but still need it when calling // coladvance_force(). // coladvance_force() uses get_ve_flags() to get the 'virtualedit' ! // state for the current window. To override that state, we need to ! // set the window-local value of ve_flags rather than the global value. if (curwin->w_cursor.coladd > 0) { ! int old_ve_flags = curwin->w_ve_flags; if (u_save_cursor() == FAIL) return; ! curwin->w_ve_flags = VE_ALL; coladvance_force(oap->op_type == OP_APPEND ? oap->end_vcol + 1 : getviscol()); if (oap->op_type == OP_APPEND) --curwin->w_cursor.col; ! curwin->w_ve_flags = old_ve_flags; } // Get the info about the block before entering the text block_prep(oap, &bd, oap->start.lnum, TRUE); *** ../vim-8.2.3279/src/option.c 2021-07-29 21:11:26.815533418 +0200 --- src/option.c 2021-08-03 18:27:56.795843540 +0200 *************** *** 5182,5189 **** redraw_later(NOT_VALID); break; case PV_VE: ! clear_string_option(&buf->b_p_ve); ! buf->b_ve_flags = 0; break; } } --- 5182,5189 ---- redraw_later(NOT_VALID); break; case PV_VE: ! clear_string_option(&((win_T *)from)->w_p_ve); ! ((win_T *)from)->w_ve_flags = 0; break; } } *************** *** 5244,5250 **** case PV_BKC: return (char_u *)&(curbuf->b_p_bkc); case PV_MENC: return (char_u *)&(curbuf->b_p_menc); case PV_LCS: return (char_u *)&(curwin->w_p_lcs); ! case PV_VE: return (char_u *)&(curbuf->b_p_ve); } return NULL; // "cannot happen" --- 5244,5250 ---- case PV_BKC: return (char_u *)&(curbuf->b_p_bkc); case PV_MENC: return (char_u *)&(curbuf->b_p_menc); case PV_LCS: return (char_u *)&(curwin->w_p_lcs); ! case PV_VE: return (char_u *)&(curwin->w_p_ve); } return NULL; // "cannot happen" *************** *** 5345,5350 **** --- 5345,5352 ---- case PV_LIST: return (char_u *)&(curwin->w_p_list); case PV_LCS: return *curwin->w_p_lcs != NUL ? (char_u *)&(curwin->w_p_lcs) : p->var; + case PV_VE: return *curwin->w_p_ve != NUL + ? (char_u *)&(curwin->w_p_ve) : p->var; #ifdef FEAT_SPELL case PV_SPELL: return (char_u *)&(curwin->w_p_spell); #endif *************** *** 5512,5519 **** case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts); case PV_VTS: return (char_u *)&(curbuf->b_p_vts); #endif - case PV_VE: return *curbuf->b_p_ve != NUL - ? (char_u *)&(curbuf->b_p_ve) : p->var; default: iemsg(_("E356: get_varp ERROR")); } // always return a valid pointer to avoid a crash! --- 5514,5519 ---- *************** *** 5593,5598 **** --- 5593,5600 ---- to->wo_lcs = vim_strsave(from->wo_lcs); to->wo_nu = from->wo_nu; to->wo_rnu = from->wo_rnu; + to->wo_ve = vim_strsave(from->wo_ve); + to->wo_ve_flags = from->wo_ve_flags; #ifdef FEAT_LINEBREAK to->wo_nuw = from->wo_nuw; #endif *************** *** 5726,5731 **** --- 5728,5734 ---- #endif check_string_option(&wop->wo_wcr); check_string_option(&wop->wo_lcs); + check_string_option(&wop->wo_ve); } /* *************** *** 5772,5777 **** --- 5775,5781 ---- clear_string_option(&wop->wo_tws); #endif clear_string_option(&wop->wo_lcs); + clear_string_option(&wop->wo_ve); } #ifdef FEAT_EVAL *************** *** 6091,6098 **** buf->b_p_lw = empty_option; #endif buf->b_p_menc = empty_option; - buf->b_p_ve = empty_option; - buf->b_ve_flags = 0; /* * Don't copy the options set by ex_help(), use the saved values, --- 6095,6100 ---- *************** *** 7041,7048 **** unsigned int get_ve_flags(void) { ! return (curbuf->b_ve_flags ? curbuf->b_ve_flags : ve_flags) ! & ~(VE_NONE | VE_NONEU); } #if defined(FEAT_LINEBREAK) || defined(PROTO) --- 7043,7050 ---- unsigned int get_ve_flags(void) { ! return (curwin->w_ve_flags ? curwin->w_ve_flags : ve_flags) ! & ~(VE_NONE | VE_NONEU); } #if defined(FEAT_LINEBREAK) || defined(PROTO) *** ../vim-8.2.3279/src/option.h 2021-07-26 22:19:05.380122574 +0200 --- src/option.h 2021-08-03 18:26:54.619980553 +0200 *************** *** 1052,1059 **** #define VE_INSERT 6 // includes "all" #define VE_ALL 4 #define VE_ONEMORE 8 ! #define VE_NONE 16 ! #define VE_NONEU 32 // Upper-case NONE EXTERN long p_verbose; // 'verbose' #ifdef IN_OPTION_C char_u *p_vfile = (char_u *)""; // used before options are initialized --- 1052,1059 ---- #define VE_INSERT 6 // includes "all" #define VE_ALL 4 #define VE_ONEMORE 8 ! #define VE_NONE 16 // "none" ! #define VE_NONEU 32 // "NONE" EXTERN long p_verbose; // 'verbose' #ifdef IN_OPTION_C char_u *p_vfile = (char_u *)""; // used before options are initialized *** ../vim-8.2.3279/src/optionstr.c 2021-07-26 22:19:05.380122574 +0200 --- src/optionstr.c 2021-08-03 18:22:12.264593431 +0200 *************** *** 298,304 **** check_string_option(&buf->b_p_vsts); check_string_option(&buf->b_p_vts); #endif - check_string_option(&buf->b_p_ve); } /* --- 298,303 ---- *************** *** 2083,2090 **** if (opt_flags & OPT_LOCAL) { ! ve = curbuf->b_p_ve; ! flags = &curbuf->b_ve_flags; } if ((opt_flags & OPT_LOCAL) && *ve == NUL) --- 2082,2089 ---- if (opt_flags & OPT_LOCAL) { ! ve = curwin->w_p_ve; ! flags = &curwin->w_ve_flags; } if ((opt_flags & OPT_LOCAL) && *ve == NUL) *** ../vim-8.2.3279/src/structs.h 2021-07-26 22:19:05.380122574 +0200 --- src/structs.h 2021-08-03 18:22:12.264593431 +0200 *************** *** 231,236 **** --- 231,240 ---- #define w_p_nu w_onebuf_opt.wo_nu // 'number' int wo_rnu; #define w_p_rnu w_onebuf_opt.wo_rnu // 'relativenumber' + char_u *wo_ve; + #define w_p_ve w_onebuf_opt.wo_ve // 'virtualedit' + unsigned wo_ve_flags; + #define w_ve_flags w_onebuf_opt.wo_ve_flags // flags for 'virtualedit' #ifdef FEAT_LINEBREAK long wo_nuw; # define w_p_nuw w_onebuf_opt.wo_nuw // 'numberwidth' *************** *** 2969,2976 **** #ifdef FEAT_TERMINAL long b_p_twsl; // 'termwinscroll' #endif - char_u *b_p_ve; // 'virtualedit' local value - unsigned b_ve_flags; // flags for 'virtualedit' /* * end of buffer options --- 2973,2978 ---- *** ../vim-8.2.3279/src/testdir/test_virtualedit.vim 2021-07-26 22:19:05.384122565 +0200 --- src/testdir/test_virtualedit.vim 2021-08-03 18:22:12.264593431 +0200 *************** *** 407,413 **** let s:result_ve_on = 'a x' let s:result_ve_off = 'x' ! " Utility function for Test_global_local() func s:TryVirtualeditReplace() call setline(1, 'a') normal gg7l --- 407,413 ---- let s:result_ve_on = 'a x' let s:result_ve_off = 'x' ! " Utility function for Test_global_local_virtualedit() func s:TryVirtualeditReplace() call setline(1, 'a') normal gg7l *************** *** 415,421 **** endfunc " Test for :set and :setlocal ! func Test_global_local() new " Verify that 'virtualedit' is initialized to empty, can be set globally to --- 415,421 ---- endfunc " Test for :set and :setlocal ! func Test_global_local_virtualedit() new " Verify that 'virtualedit' is initialized to empty, can be set globally to *************** *** 435,442 **** call s:TryVirtualeditReplace() call assert_equal(s:result_ve_off, getline(1)) ! " Verify that :set affects multiple buffers ! new set ve=all call s:TryVirtualeditReplace() call assert_equal(s:result_ve_on, getline(1)) --- 435,442 ---- call s:TryVirtualeditReplace() call assert_equal(s:result_ve_off, getline(1)) ! " Verify that :set affects multiple windows. ! split set ve=all call s:TryVirtualeditReplace() call assert_equal(s:result_ve_on, getline(1)) *************** *** 449,465 **** call assert_equal(s:result_ve_off, getline(1)) bwipe! ! " Verify that :setlocal affects only the current buffer ! setlocal ve=all new ! call s:TryVirtualeditReplace() ! call assert_equal(s:result_ve_off, getline(1)) setlocal ve=all - wincmd p - setlocal ve= - wincmd p call s:TryVirtualeditReplace() call assert_equal(s:result_ve_on, getline(1)) bwipe! call s:TryVirtualeditReplace() call assert_equal(s:result_ve_off, getline(1)) --- 449,463 ---- call assert_equal(s:result_ve_off, getline(1)) bwipe! ! " Verify that :setlocal affects only the current window. new ! split setlocal ve=all call s:TryVirtualeditReplace() call assert_equal(s:result_ve_on, getline(1)) + wincmd p + call s:TryVirtualeditReplace() + call assert_equal(s:result_ve_off, getline(1)) bwipe! call s:TryVirtualeditReplace() call assert_equal(s:result_ve_off, getline(1)) *************** *** 518,523 **** --- 516,538 ---- bwipe! + " Verify that the 'virtualedit' state is copied to new windows. + new + call s:TryVirtualeditReplace() + call assert_equal(s:result_ve_off, getline(1)) + split + setlocal ve=all + call s:TryVirtualeditReplace() + call assert_equal(s:result_ve_on, getline(1)) + split + call s:TryVirtualeditReplace() + call assert_equal(s:result_ve_on, getline(1)) + setlocal ve= + split + call s:TryVirtualeditReplace() + call assert_equal(s:result_ve_off, getline(1)) + bwipe! + setlocal virtualedit& set virtualedit& endfunc *** ../vim-8.2.3279/src/version.c 2021-08-02 22:26:52.014701338 +0200 --- src/version.c 2021-08-03 18:30:04.279560878 +0200 *************** *** 757,758 **** --- 757,760 ---- { /* Add new patch number below this line */ + /**/ + 3280, /**/ -- FATHER: Who are you? PRINCE: I'm ... your son ... FATHER: Not you. LAUNCELOT: I'm ... er ... Sir Launcelot, sir. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// 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 ///