To: vim_dev@googlegroups.com Subject: Patch 9.0.1243 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1243 Problem: :setglobal cannot use script-local function for "expr" option. Solution: Use the pointer to the option value properly. (closes #11883) Files: src/optionstr.c, src/testdir/test_edit.vim, src/testdir/test_fold.vim, src/testdir/test_gf.vim, src/testdir/test_normal.vim *** ../vim-9.0.1242/src/optionstr.c 2023-01-16 18:19:01.907301080 +0000 --- src/optionstr.c 2023-01-25 15:28:29.822772690 +0000 *************** *** 2311,2318 **** varp == &p_dex || # endif # ifdef FEAT_FOLDING ! varp == &curwin->w_p_fde || ! varp == &curwin->w_p_fdt || # endif gvarp == &p_fex || # ifdef FEAT_FIND_ID --- 2311,2318 ---- varp == &p_dex || # endif # ifdef FEAT_FOLDING ! gvarp == &curwin->w_allbuf_opt.wo_fde || ! gvarp == &curwin->w_allbuf_opt.wo_fdt || # endif gvarp == &p_fex || # ifdef FEAT_FIND_ID *************** *** 2327,2378 **** # endif varp == &p_ccv) { - char_u **p_opt = NULL; - char_u *name; - // If the option value starts with or s:, then replace that with // the script identifier. ! # ifdef FEAT_BEVAL ! if (varp == &p_bexpr) // 'balloonexpr' ! p_opt = (opt_flags & OPT_LOCAL) ? &curbuf->b_p_bexpr : &p_bexpr; ! # endif ! # ifdef FEAT_DIFF ! if (varp == &p_dex) // 'diffexpr' ! p_opt = &p_dex; ! # endif ! # ifdef FEAT_FOLDING ! if (varp == &curwin->w_p_fde) // 'foldexpr' ! p_opt = &curwin->w_p_fde; ! if (varp == &curwin->w_p_fdt) // 'foldtext' ! p_opt = &curwin->w_p_fdt; ! # endif ! if (gvarp == &p_fex) // 'formatexpr' ! p_opt = &curbuf->b_p_fex; ! # ifdef FEAT_FIND_ID ! if (gvarp == &p_inex) // 'includeexpr' ! p_opt = &curbuf->b_p_inex; ! # endif ! if (gvarp == &p_inde) // 'indentexpr' ! p_opt = &curbuf->b_p_inde; ! # ifdef FEAT_DIFF ! if (varp == &p_pex) // 'patchexpr' ! p_opt = &p_pex; ! # endif ! # ifdef FEAT_POSTSCRIPT ! if (varp == &p_pexpr) // 'printexpr' ! p_opt = &p_pexpr; ! # endif ! if (varp == &p_ccv) // 'charconvert' ! p_opt = &p_ccv; ! ! if (p_opt != NULL) { ! name = get_scriptlocal_funcname(*p_opt); ! if (name != NULL) ! { ! free_string_option(*p_opt); ! *p_opt = name; ! } } # ifdef FEAT_FOLDING --- 2327,2339 ---- # endif varp == &p_ccv) { // If the option value starts with or s:, then replace that with // the script identifier. ! char_u *name = get_scriptlocal_funcname(*varp); ! if (name != NULL) { ! free_string_option(*varp); ! *varp = name; } # ifdef FEAT_FOLDING *** ../vim-9.0.1242/src/testdir/test_edit.vim 2022-09-21 15:13:49.314998845 +0100 --- src/testdir/test_edit.vim 2023-01-25 15:28:29.822772690 +0000 *************** *** 330,337 **** --- 330,352 ---- endfunc set indentexpr=s:NewIndentExpr() call assert_equal(expand('') .. 'NewIndentExpr()', &indentexpr) + call assert_equal(expand('') .. 'NewIndentExpr()', &g:indentexpr) set indentexpr=NewIndentExpr() call assert_equal(expand('') .. 'NewIndentExpr()', &indentexpr) + call assert_equal(expand('') .. 'NewIndentExpr()', &g:indentexpr) + setlocal indentexpr= + setglobal indentexpr=s:NewIndentExpr() + call assert_equal(expand('') .. 'NewIndentExpr()', &g:indentexpr) + call assert_equal('', &indentexpr) + new + call assert_equal(expand('') .. 'NewIndentExpr()', &indentexpr) + bw! + setglobal indentexpr=NewIndentExpr() + call assert_equal(expand('') .. 'NewIndentExpr()', &g:indentexpr) + call assert_equal('', &indentexpr) + new + call assert_equal(expand('') .. 'NewIndentExpr()', &indentexpr) + bw! set indentexpr& bw! *** ../vim-9.0.1242/src/testdir/test_fold.vim 2023-01-17 19:48:02.759310921 +0000 --- src/testdir/test_fold.vim 2023-01-25 15:28:29.822772690 +0000 *************** *** 1503,1508 **** --- 1503,1509 ---- set foldmethod=expr foldexpr=s:FoldFunc() redraw! call assert_equal(expand('') .. 'FoldFunc()', &foldexpr) + call assert_equal(expand('') .. 'FoldFunc()', &g:foldexpr) call assert_equal(1, g:FoldLnum) set foldmethod& foldexpr= bw! *************** *** 1512,1519 **** set foldmethod=expr foldexpr=FoldFunc() redraw! call assert_equal(expand('') .. 'FoldFunc()', &foldexpr) call assert_equal(1, g:FoldLnum) ! set foldmethod& foldexpr= delfunc s:FoldFunc bw! endfunc --- 1513,1543 ---- set foldmethod=expr foldexpr=FoldFunc() redraw! call assert_equal(expand('') .. 'FoldFunc()', &foldexpr) + call assert_equal(expand('') .. 'FoldFunc()', &g:foldexpr) call assert_equal(1, g:FoldLnum) ! bw! ! call setline(1, 'abc') ! setlocal foldmethod& foldexpr& ! setglobal foldmethod=expr foldexpr=s:FoldFunc() ! call assert_equal(expand('') .. 'FoldFunc()', &g:foldexpr) ! call assert_equal('0', &foldexpr) ! enew! ! call setline(1, 'abc') ! redraw! ! call assert_equal(expand('') .. 'FoldFunc()', &foldexpr) ! call assert_equal(1, g:FoldLnum) ! bw! ! call setline(1, 'abc') ! setlocal foldmethod& foldexpr& ! setglobal foldmethod=expr foldexpr=FoldFunc() ! call assert_equal(expand('') .. 'FoldFunc()', &g:foldexpr) ! call assert_equal('0', &foldexpr) ! enew! ! call setline(1, 'abc') ! redraw! ! call assert_equal(expand('') .. 'FoldFunc()', &foldexpr) ! call assert_equal(1, g:FoldLnum) ! set foldmethod& foldexpr& delfunc s:FoldFunc bw! endfunc *************** *** 1527,1551 **** new | only call setline(1, range(50)) let g:FoldTextArgs = [] - set foldmethod=manual set foldtext=s:FoldText() norm! 4Gzf4j redraw! call assert_equal(expand('') .. 'FoldText()', &foldtext) call assert_equal([4, 8], g:FoldTextArgs) set foldtext& bw! new | only call setline(1, range(50)) let g:FoldTextArgs = [] - set foldmethod=manual set foldtext=FoldText() norm! 8Gzf4j redraw! call assert_equal(expand('') .. 'FoldText()', &foldtext) call assert_equal([8, 12], g:FoldTextArgs) set foldtext& bw! delfunc s:FoldText endfunc --- 1551,1603 ---- new | only call setline(1, range(50)) let g:FoldTextArgs = [] set foldtext=s:FoldText() norm! 4Gzf4j redraw! call assert_equal(expand('') .. 'FoldText()', &foldtext) + call assert_equal(expand('') .. 'FoldText()', &g:foldtext) call assert_equal([4, 8], g:FoldTextArgs) set foldtext& bw! new | only call setline(1, range(50)) let g:FoldTextArgs = [] set foldtext=FoldText() norm! 8Gzf4j redraw! call assert_equal(expand('') .. 'FoldText()', &foldtext) + call assert_equal(expand('') .. 'FoldText()', &g:foldtext) call assert_equal([8, 12], g:FoldTextArgs) set foldtext& bw! + call setline(1, range(50)) + let g:FoldTextArgs = [] + setlocal foldtext& + setglobal foldtext=s:FoldText() + call assert_equal(expand('') .. 'FoldText()', &g:foldtext) + call assert_equal('foldtext()', &foldtext) + enew! + call setline(1, range(50)) + norm! 12Gzf4j + redraw! + call assert_equal(expand('') .. 'FoldText()', &foldtext) + call assert_equal([12, 16], g:FoldTextArgs) + set foldtext& + bw! + call setline(1, range(50)) + let g:FoldTextArgs = [] + setlocal foldtext& + setglobal foldtext=FoldText() + call assert_equal(expand('') .. 'FoldText()', &g:foldtext) + call assert_equal('foldtext()', &foldtext) + enew! + call setline(1, range(50)) + norm! 16Gzf4j + redraw! + call assert_equal(expand('') .. 'FoldText()', &foldtext) + call assert_equal([16, 20], g:FoldTextArgs) + set foldtext& + bw! delfunc s:FoldText endfunc *** ../vim-9.0.1242/src/testdir/test_gf.vim 2022-09-28 21:06:30.634345977 +0100 --- src/testdir/test_gf.vim 2023-01-25 15:28:29.822772690 +0000 *************** *** 227,232 **** --- 227,233 ---- endfunc set includeexpr=s:IncludeFunc() call assert_equal(expand('') .. 'IncludeFunc()', &includeexpr) + call assert_equal(expand('') .. 'IncludeFunc()', &g:includeexpr) new | only call setline(1, 'TestFile1') let g:IncludeFname = '' *************** *** 235,245 **** --- 236,270 ---- bw! set includeexpr=IncludeFunc() call assert_equal(expand('') .. 'IncludeFunc()', &includeexpr) + call assert_equal(expand('') .. 'IncludeFunc()', &g:includeexpr) new | only call setline(1, 'TestFile2') let g:IncludeFname = '' call assert_fails('normal! gf', 'E447:') call assert_equal('TestFile2', g:IncludeFname) + bw! + setlocal includeexpr= + setglobal includeexpr=s:IncludeFunc() + call assert_equal(expand('') .. 'IncludeFunc()', &g:includeexpr) + call assert_equal('', &includeexpr) + new + call assert_equal(expand('') .. 'IncludeFunc()', &includeexpr) + call setline(1, 'TestFile3') + let g:IncludeFname = '' + call assert_fails('normal! gf', 'E447:') + call assert_equal('TestFile3', g:IncludeFname) + bw! + setlocal includeexpr= + setglobal includeexpr=IncludeFunc() + call assert_equal(expand('') .. 'IncludeFunc()', &g:includeexpr) + call assert_equal('', &includeexpr) + new + call assert_equal(expand('') .. 'IncludeFunc()', &includeexpr) + call setline(1, 'TestFile4') + let g:IncludeFname = '' + call assert_fails('normal! gf', 'E447:') + call assert_equal('TestFile4', g:IncludeFname) + bw! set includeexpr& delfunc s:IncludeFunc bw! *** ../vim-9.0.1242/src/testdir/test_normal.vim 2022-12-08 09:41:20.416361660 +0000 --- src/testdir/test_normal.vim 2023-01-25 15:28:29.822772690 +0000 *************** *** 262,267 **** --- 262,268 ---- endfunc set formatexpr=s:Format() call assert_equal(expand('') .. 'Format()', &formatexpr) + call assert_equal(expand('') .. 'Format()', &g:formatexpr) new | only call setline(1, range(1, 40)) let g:FormatArgs = [] *************** *** 270,275 **** --- 271,277 ---- bw! set formatexpr=Format() call assert_equal(expand('') .. 'Format()', &formatexpr) + call assert_equal(expand('') .. 'Format()', &g:formatexpr) new | only call setline(1, range(1, 40)) let g:FormatArgs = [] *************** *** 277,282 **** --- 279,285 ---- call assert_equal([4, 2], g:FormatArgs) bw! let &formatexpr = 's:Format()' + call assert_equal(expand('') .. 'Format()', &g:formatexpr) new | only call setline(1, range(1, 40)) let g:FormatArgs = [] *************** *** 284,295 **** --- 287,341 ---- call assert_equal([6, 2], g:FormatArgs) bw! let &formatexpr = 'Format()' + call assert_equal(expand('') .. 'Format()', &g:formatexpr) new | only call setline(1, range(1, 40)) let g:FormatArgs = [] normal! 8GVjgq call assert_equal([8, 2], g:FormatArgs) + bw! setlocal formatexpr= + setglobal formatexpr=s:Format() + call assert_equal(expand('') .. 'Format()', &g:formatexpr) + call assert_equal('', &formatexpr) + new + call assert_equal(expand('') .. 'Format()', &formatexpr) + call setline(1, range(1, 40)) + let g:FormatArgs = [] + normal! 10GVjgq + call assert_equal([10, 2], g:FormatArgs) + bw! + setglobal formatexpr=Format() + call assert_equal(expand('') .. 'Format()', &g:formatexpr) + call assert_equal('', &formatexpr) + new + call assert_equal(expand('') .. 'Format()', &formatexpr) + call setline(1, range(1, 40)) + let g:FormatArgs = [] + normal! 12GVjgq + call assert_equal([12, 2], g:FormatArgs) + bw! + let &g:formatexpr = 's:Format()' + call assert_equal(expand('') .. 'Format()', &g:formatexpr) + call assert_equal('', &formatexpr) + new + call assert_equal(expand('') .. 'Format()', &formatexpr) + call setline(1, range(1, 40)) + let g:FormatArgs = [] + normal! 14GVjgq + call assert_equal([14, 2], g:FormatArgs) + bw! + let &g:formatexpr = 'Format()' + call assert_equal(expand('') .. 'Format()', &g:formatexpr) + call assert_equal('', &formatexpr) + new + call assert_equal(expand('') .. 'Format()', &formatexpr) + call setline(1, range(1, 40)) + let g:FormatArgs = [] + normal! 16GVjgq + call assert_equal([16, 2], g:FormatArgs) + bw! + set formatexpr= delfunc s:Format bw! endfunc *** ../vim-9.0.1242/src/version.c 2023-01-25 15:04:17.943549251 +0000 --- src/version.c 2023-01-25 15:31:04.306728988 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1243, /**/ -- hundred-and-one symptoms of being an internet addict: 43. You tell the kids they can't use the computer because "Daddy's got work to do" and you don't even have a job. /// 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 ///