• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revision5614e76f3dee23b6f20a44bb99dc0481b90244a5 (tree)
Zeit2023-01-26 00:45:03
AutorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 9.0.1243: :setglobal cannot use script-local function for "expr" option

Commit: https://github.com/vim/vim/commit/01d4efe2e87632aa085897d3d64e27585908f977
Author: zeertzjq <zeertzjq@outlook.com>
Date: Wed Jan 25 15:31:28 2023 +0000

patch 9.0.1243: :setglobal cannot use script-local function for "expr" option
Problem: :setglobal cannot use script-local function for "expr" option.
Solution: Use the pointer to the option value properly. (closes https://github.com/vim/vim/issues/11883)

Ändern Zusammenfassung

Diff

diff -r 08ee50169c0f -r 5614e76f3dee src/optionstr.c
--- a/src/optionstr.c Wed Jan 25 16:15:07 2023 +0100
+++ b/src/optionstr.c Wed Jan 25 16:45:03 2023 +0100
@@ -2311,8 +2311,8 @@
23112311 varp == &p_dex ||
23122312 # endif
23132313 # ifdef FEAT_FOLDING
2314- varp == &curwin->w_p_fde ||
2315- varp == &curwin->w_p_fdt ||
2314+ gvarp == &curwin->w_allbuf_opt.wo_fde ||
2315+ gvarp == &curwin->w_allbuf_opt.wo_fdt ||
23162316 # endif
23172317 gvarp == &p_fex ||
23182318 # ifdef FEAT_FIND_ID
@@ -2327,52 +2327,13 @@
23272327 # endif
23282328 varp == &p_ccv)
23292329 {
2330- char_u **p_opt = NULL;
2331- char_u *name;
2332-
23332330 // If the option value starts with <SID> or s:, then replace that with
23342331 // the script identifier.
2335-# ifdef FEAT_BEVAL
2336- if (varp == &p_bexpr) // 'balloonexpr'
2337- p_opt = (opt_flags & OPT_LOCAL) ? &curbuf->b_p_bexpr : &p_bexpr;
2338-# endif
2339-# ifdef FEAT_DIFF
2340- if (varp == &p_dex) // 'diffexpr'
2341- p_opt = &p_dex;
2342-# endif
2343-# ifdef FEAT_FOLDING
2344- if (varp == &curwin->w_p_fde) // 'foldexpr'
2345- p_opt = &curwin->w_p_fde;
2346- if (varp == &curwin->w_p_fdt) // 'foldtext'
2347- p_opt = &curwin->w_p_fdt;
2348-# endif
2349- if (gvarp == &p_fex) // 'formatexpr'
2350- p_opt = &curbuf->b_p_fex;
2351-# ifdef FEAT_FIND_ID
2352- if (gvarp == &p_inex) // 'includeexpr'
2353- p_opt = &curbuf->b_p_inex;
2354-# endif
2355- if (gvarp == &p_inde) // 'indentexpr'
2356- p_opt = &curbuf->b_p_inde;
2357-# ifdef FEAT_DIFF
2358- if (varp == &p_pex) // 'patchexpr'
2359- p_opt = &p_pex;
2360-# endif
2361-# ifdef FEAT_POSTSCRIPT
2362- if (varp == &p_pexpr) // 'printexpr'
2363- p_opt = &p_pexpr;
2364-# endif
2365- if (varp == &p_ccv) // 'charconvert'
2366- p_opt = &p_ccv;
2367-
2368- if (p_opt != NULL)
2332+ char_u *name = get_scriptlocal_funcname(*varp);
2333+ if (name != NULL)
23692334 {
2370- name = get_scriptlocal_funcname(*p_opt);
2371- if (name != NULL)
2372- {
2373- free_string_option(*p_opt);
2374- *p_opt = name;
2375- }
2335+ free_string_option(*varp);
2336+ *varp = name;
23762337 }
23772338
23782339 # ifdef FEAT_FOLDING
diff -r 08ee50169c0f -r 5614e76f3dee src/testdir/test_edit.vim
--- a/src/testdir/test_edit.vim Wed Jan 25 16:15:07 2023 +0100
+++ b/src/testdir/test_edit.vim Wed Jan 25 16:45:03 2023 +0100
@@ -330,8 +330,23 @@
330330 endfunc
331331 set indentexpr=s:NewIndentExpr()
332332 call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr)
333+ call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &g:indentexpr)
333334 set indentexpr=<SID>NewIndentExpr()
334335 call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr)
336+ call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &g:indentexpr)
337+ setlocal indentexpr=
338+ setglobal indentexpr=s:NewIndentExpr()
339+ call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &g:indentexpr)
340+ call assert_equal('', &indentexpr)
341+ new
342+ call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr)
343+ bw!
344+ setglobal indentexpr=<SID>NewIndentExpr()
345+ call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &g:indentexpr)
346+ call assert_equal('', &indentexpr)
347+ new
348+ call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr)
349+ bw!
335350 set indentexpr&
336351
337352 bw!
diff -r 08ee50169c0f -r 5614e76f3dee src/testdir/test_fold.vim
--- a/src/testdir/test_fold.vim Wed Jan 25 16:15:07 2023 +0100
+++ b/src/testdir/test_fold.vim Wed Jan 25 16:45:03 2023 +0100
@@ -1503,6 +1503,7 @@
15031503 set foldmethod=expr foldexpr=s:FoldFunc()
15041504 redraw!
15051505 call assert_equal(expand('<SID>') .. 'FoldFunc()', &foldexpr)
1506+ call assert_equal(expand('<SID>') .. 'FoldFunc()', &g:foldexpr)
15061507 call assert_equal(1, g:FoldLnum)
15071508 set foldmethod& foldexpr=
15081509 bw!
@@ -1512,8 +1513,31 @@
15121513 set foldmethod=expr foldexpr=<SID>FoldFunc()
15131514 redraw!
15141515 call assert_equal(expand('<SID>') .. 'FoldFunc()', &foldexpr)
1516+ call assert_equal(expand('<SID>') .. 'FoldFunc()', &g:foldexpr)
15151517 call assert_equal(1, g:FoldLnum)
1516- set foldmethod& foldexpr=
1518+ bw!
1519+ call setline(1, 'abc')
1520+ setlocal foldmethod& foldexpr&
1521+ setglobal foldmethod=expr foldexpr=s:FoldFunc()
1522+ call assert_equal(expand('<SID>') .. 'FoldFunc()', &g:foldexpr)
1523+ call assert_equal('0', &foldexpr)
1524+ enew!
1525+ call setline(1, 'abc')
1526+ redraw!
1527+ call assert_equal(expand('<SID>') .. 'FoldFunc()', &foldexpr)
1528+ call assert_equal(1, g:FoldLnum)
1529+ bw!
1530+ call setline(1, 'abc')
1531+ setlocal foldmethod& foldexpr&
1532+ setglobal foldmethod=expr foldexpr=<SID>FoldFunc()
1533+ call assert_equal(expand('<SID>') .. 'FoldFunc()', &g:foldexpr)
1534+ call assert_equal('0', &foldexpr)
1535+ enew!
1536+ call setline(1, 'abc')
1537+ redraw!
1538+ call assert_equal(expand('<SID>') .. 'FoldFunc()', &foldexpr)
1539+ call assert_equal(1, g:FoldLnum)
1540+ set foldmethod& foldexpr&
15171541 delfunc s:FoldFunc
15181542 bw!
15191543 endfunc
@@ -1527,25 +1551,53 @@
15271551 new | only
15281552 call setline(1, range(50))
15291553 let g:FoldTextArgs = []
1530- set foldmethod=manual
15311554 set foldtext=s:FoldText()
15321555 norm! 4Gzf4j
15331556 redraw!
15341557 call assert_equal(expand('<SID>') .. 'FoldText()', &foldtext)
1558+ call assert_equal(expand('<SID>') .. 'FoldText()', &g:foldtext)
15351559 call assert_equal([4, 8], g:FoldTextArgs)
15361560 set foldtext&
15371561 bw!
15381562 new | only
15391563 call setline(1, range(50))
15401564 let g:FoldTextArgs = []
1541- set foldmethod=manual
15421565 set foldtext=<SID>FoldText()
15431566 norm! 8Gzf4j
15441567 redraw!
15451568 call assert_equal(expand('<SID>') .. 'FoldText()', &foldtext)
1569+ call assert_equal(expand('<SID>') .. 'FoldText()', &g:foldtext)
15461570 call assert_equal([8, 12], g:FoldTextArgs)
15471571 set foldtext&
15481572 bw!
1573+ call setline(1, range(50))
1574+ let g:FoldTextArgs = []
1575+ setlocal foldtext&
1576+ setglobal foldtext=s:FoldText()
1577+ call assert_equal(expand('<SID>') .. 'FoldText()', &g:foldtext)
1578+ call assert_equal('foldtext()', &foldtext)
1579+ enew!
1580+ call setline(1, range(50))
1581+ norm! 12Gzf4j
1582+ redraw!
1583+ call assert_equal(expand('<SID>') .. 'FoldText()', &foldtext)
1584+ call assert_equal([12, 16], g:FoldTextArgs)
1585+ set foldtext&
1586+ bw!
1587+ call setline(1, range(50))
1588+ let g:FoldTextArgs = []
1589+ setlocal foldtext&
1590+ setglobal foldtext=<SID>FoldText()
1591+ call assert_equal(expand('<SID>') .. 'FoldText()', &g:foldtext)
1592+ call assert_equal('foldtext()', &foldtext)
1593+ enew!
1594+ call setline(1, range(50))
1595+ norm! 16Gzf4j
1596+ redraw!
1597+ call assert_equal(expand('<SID>') .. 'FoldText()', &foldtext)
1598+ call assert_equal([16, 20], g:FoldTextArgs)
1599+ set foldtext&
1600+ bw!
15491601 delfunc s:FoldText
15501602 endfunc
15511603
diff -r 08ee50169c0f -r 5614e76f3dee src/testdir/test_gf.vim
--- a/src/testdir/test_gf.vim Wed Jan 25 16:15:07 2023 +0100
+++ b/src/testdir/test_gf.vim Wed Jan 25 16:45:03 2023 +0100
@@ -227,6 +227,7 @@
227227 endfunc
228228 set includeexpr=s:IncludeFunc()
229229 call assert_equal(expand('<SID>') .. 'IncludeFunc()', &includeexpr)
230+ call assert_equal(expand('<SID>') .. 'IncludeFunc()', &g:includeexpr)
230231 new | only
231232 call setline(1, 'TestFile1')
232233 let g:IncludeFname = ''
@@ -235,11 +236,35 @@
235236 bw!
236237 set includeexpr=<SID>IncludeFunc()
237238 call assert_equal(expand('<SID>') .. 'IncludeFunc()', &includeexpr)
239+ call assert_equal(expand('<SID>') .. 'IncludeFunc()', &g:includeexpr)
238240 new | only
239241 call setline(1, 'TestFile2')
240242 let g:IncludeFname = ''
241243 call assert_fails('normal! gf', 'E447:')
242244 call assert_equal('TestFile2', g:IncludeFname)
245+ bw!
246+ setlocal includeexpr=
247+ setglobal includeexpr=s:IncludeFunc()
248+ call assert_equal(expand('<SID>') .. 'IncludeFunc()', &g:includeexpr)
249+ call assert_equal('', &includeexpr)
250+ new
251+ call assert_equal(expand('<SID>') .. 'IncludeFunc()', &includeexpr)
252+ call setline(1, 'TestFile3')
253+ let g:IncludeFname = ''
254+ call assert_fails('normal! gf', 'E447:')
255+ call assert_equal('TestFile3', g:IncludeFname)
256+ bw!
257+ setlocal includeexpr=
258+ setglobal includeexpr=<SID>IncludeFunc()
259+ call assert_equal(expand('<SID>') .. 'IncludeFunc()', &g:includeexpr)
260+ call assert_equal('', &includeexpr)
261+ new
262+ call assert_equal(expand('<SID>') .. 'IncludeFunc()', &includeexpr)
263+ call setline(1, 'TestFile4')
264+ let g:IncludeFname = ''
265+ call assert_fails('normal! gf', 'E447:')
266+ call assert_equal('TestFile4', g:IncludeFname)
267+ bw!
243268 set includeexpr&
244269 delfunc s:IncludeFunc
245270 bw!
diff -r 08ee50169c0f -r 5614e76f3dee src/testdir/test_normal.vim
--- a/src/testdir/test_normal.vim Wed Jan 25 16:15:07 2023 +0100
+++ b/src/testdir/test_normal.vim Wed Jan 25 16:45:03 2023 +0100
@@ -262,6 +262,7 @@
262262 endfunc
263263 set formatexpr=s:Format()
264264 call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
265+ call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
265266 new | only
266267 call setline(1, range(1, 40))
267268 let g:FormatArgs = []
@@ -270,6 +271,7 @@
270271 bw!
271272 set formatexpr=<SID>Format()
272273 call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
274+ call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
273275 new | only
274276 call setline(1, range(1, 40))
275277 let g:FormatArgs = []
@@ -277,6 +279,7 @@
277279 call assert_equal([4, 2], g:FormatArgs)
278280 bw!
279281 let &formatexpr = 's:Format()'
282+ call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
280283 new | only
281284 call setline(1, range(1, 40))
282285 let g:FormatArgs = []
@@ -284,12 +287,55 @@
284287 call assert_equal([6, 2], g:FormatArgs)
285288 bw!
286289 let &formatexpr = '<SID>Format()'
290+ call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
287291 new | only
288292 call setline(1, range(1, 40))
289293 let g:FormatArgs = []
290294 normal! 8GVjgq
291295 call assert_equal([8, 2], g:FormatArgs)
296+ bw!
292297 setlocal formatexpr=
298+ setglobal formatexpr=s:Format()
299+ call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
300+ call assert_equal('', &formatexpr)
301+ new
302+ call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
303+ call setline(1, range(1, 40))
304+ let g:FormatArgs = []
305+ normal! 10GVjgq
306+ call assert_equal([10, 2], g:FormatArgs)
307+ bw!
308+ setglobal formatexpr=<SID>Format()
309+ call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
310+ call assert_equal('', &formatexpr)
311+ new
312+ call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
313+ call setline(1, range(1, 40))
314+ let g:FormatArgs = []
315+ normal! 12GVjgq
316+ call assert_equal([12, 2], g:FormatArgs)
317+ bw!
318+ let &g:formatexpr = 's:Format()'
319+ call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
320+ call assert_equal('', &formatexpr)
321+ new
322+ call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
323+ call setline(1, range(1, 40))
324+ let g:FormatArgs = []
325+ normal! 14GVjgq
326+ call assert_equal([14, 2], g:FormatArgs)
327+ bw!
328+ let &g:formatexpr = '<SID>Format()'
329+ call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
330+ call assert_equal('', &formatexpr)
331+ new
332+ call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
333+ call setline(1, range(1, 40))
334+ let g:FormatArgs = []
335+ normal! 16GVjgq
336+ call assert_equal([16, 2], g:FormatArgs)
337+ bw!
338+ set formatexpr=
293339 delfunc s:Format
294340 bw!
295341 endfunc
diff -r 08ee50169c0f -r 5614e76f3dee src/version.c
--- a/src/version.c Wed Jan 25 16:15:07 2023 +0100
+++ b/src/version.c Wed Jan 25 16:45:03 2023 +0100
@@ -696,6 +696,8 @@
696696 static int included_patches[] =
697697 { /* Add new patch number below this line */
698698 /**/
699+ 1243,
700+/**/
699701 1242,
700702 /**/
701703 1241,
Show on old repository browser