fix(keywordprg): default to :help if set to empty string (#19983)

This commit is contained in:
zeertzjq 2022-08-29 05:58:32 +08:00 committed by GitHub
parent 88c32b5eba
commit b21980bd60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -4278,13 +4278,12 @@ static void nv_ident(cmdarg_T *cap)
// double the length of the word. p_kp / curbuf->b_p_kp could be added
// and some numbers.
char_u *kp = *curbuf->b_p_kp == NUL ? p_kp : (char_u *)curbuf->b_p_kp; // 'keywordprg'
assert(*kp != NUL); // option.c:do_set() should default to ":help" if empty.
bool kp_ex = (*kp == ':'); // 'keywordprg' is an ex command
bool kp_help = (STRCMP(kp, ":he") == 0 || STRCMP(kp, ":help") == 0);
bool kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0 || STRCMP(kp, ":help") == 0);
if (kp_help && *skipwhite(ptr) == NUL) {
emsg(_(e_noident)); // found white space only
return;
}
bool kp_ex = (*kp == ':'); // 'keywordprg' is an ex command
size_t buf_size = n * 2 + 30 + STRLEN(kp);
char *buf = xmalloc(buf_size);
buf[0] = NUL;

View File

@ -1,6 +1,6 @@
local helpers = require('test.functional.helpers')(after_each)
local eq, clear, eval, feed, retry =
helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.retry
local eq, clear, eval, feed, meths, retry =
helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.meths, helpers.retry
describe('K', function()
local test_file = 'K_spec_out'
@ -58,4 +58,11 @@ describe('K', function()
helpers.neq(bufnr, eval('bufnr()'))
end)
it('empty string falls back to :help #19298', function()
meths.set_option('keywordprg', '')
meths.buf_set_lines(0, 0, -1, true, {'doesnotexist'})
feed('K')
eq('E149: Sorry, no help for doesnotexist', meths.get_vvar('errmsg'))
end)
end)