From fcba86c0316dc0d6341078b50e7967206a1627a0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 13:57:32 +0100 Subject: [PATCH] patch 9.0.0544: minor issues with setting a string option Problem: Minor issues with setting a string option. Solution: Adjust the code, add a test. (closes #11192) --- src/option.c | 12 +++++------- src/testdir/test_options.vim | 14 ++++++++++++++ src/version.c | 2 ++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/option.c b/src/option.c index 586796240..6052b38b9 100644 --- a/src/option.c +++ b/src/option.c @@ -1323,13 +1323,11 @@ do_set_string( /* * Set 'keywordprg' to ":help" if an empty * value was passed to :set by the user. - * Misuse errbuf[] for the resulting string. */ if (varp == (char_u *)&p_kp && (*arg == NUL || *arg == ' ')) { - STRCPY(errbuf, ":help"); save_arg = arg; - arg = (char_u *)errbuf; + arg = (char_u *)":help"; } /* * Convert 'backspace' number to string, for @@ -1417,7 +1415,7 @@ do_set_string( * but do remove it for "\\\\machine\\path". * The reverse is found in ExpandOldSetting(). */ - while (*arg && !VIM_ISWHITE(*arg)) + while (*arg != NUL && !VIM_ISWHITE(*arg)) { int i; @@ -1427,7 +1425,7 @@ do_set_string( && vim_isfilec(arg[1]) && !VIM_ISWHITE(arg[1]) && (arg[1] != '\\' - || (s == newval && arg[2] != '\\'))) + || (s == newval && arg[2] != '\\'))) #endif ) ++arg; // remove backslash @@ -1565,8 +1563,8 @@ do_set_string( } } - if (save_arg != NULL) // number for 'whichwrap' - arg = save_arg; + if (save_arg != NULL) + arg = save_arg; // arg was temporarily changed, restore it } /* diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim index a0ee53bb3..a890009e0 100644 --- a/src/testdir/test_options.vim +++ b/src/testdir/test_options.vim @@ -1343,4 +1343,18 @@ func Test_switchbuf_reset() only! endfunc +" :set empty string for global 'keywordprg' falls back to ":help" +func Test_keywordprg_empty() + let k = &keywordprg + set keywordprg=man + call assert_equal('man', &keywordprg) + set keywordprg= + call assert_equal(':help', &keywordprg) + set keywordprg=man + call assert_equal('man', &keywordprg) + call assert_equal("\n keywordprg=:help", execute('set kp= kp?')) + let &keywordprg = k +endfunc + + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index d3694560f..d9bcbbc7b 100644 --- a/src/version.c +++ b/src/version.c @@ -699,6 +699,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 544, /**/ 543, /**/ -- 2.40.0