fix(help): show error when using :help! with nothing at cursor #38775

It's possible to still show the old Easter egg, but then the user won't
know about the new feature, so showing E349 is better.

(cherry picked from commit 9705a1c13b)
This commit is contained in:
zeertzjq
2026-04-05 22:59:22 +08:00
committed by github-actions[bot]
parent bac7c3a996
commit 4bf170d79d
4 changed files with 9 additions and 2 deletions

View File

@@ -63,6 +63,7 @@ EXTERN const char e_nogroup[] INIT(= N_("E28: No such highlight group name: %s")
EXTERN const char e_noinstext[] INIT(= N_("E29: No inserted text yet"));
EXTERN const char e_nolastcmd[] INIT(= N_("E30: No previous command line"));
EXTERN const char e_nomap[] INIT(= N_("E31: No such mapping"));
EXTERN const char e_noident[] INIT(= N_("E349: No identifier under cursor"));
EXTERN const char e_nomatch[] INIT(= N_("E479: No match"));
EXTERN const char e_nomatch2[] INIT(= N_("E480: No match: %s"));
EXTERN const char e_noname[] INIT(= N_("E32: No file name"));

View File

@@ -114,6 +114,10 @@ void ex_help(exarg_T *eap)
}
api_free_object(res);
api_clear_error(&err);
if (allocated_arg == NULL) {
emsg(_(e_noident));
return;
}
}
// Check if there is a match for the argument.

View File

@@ -132,8 +132,6 @@ static inline void normal_state_init(NormalState *s)
// n_*(): functions called to handle Normal mode commands.
// v_*(): functions called to handle Visual mode commands.
static const char *e_noident = N_("E349: No identifier under cursor");
/// Function to be called for a Normal or Visual mode command.
/// The argument is a cmdarg_T.
typedef void (*nv_func_T)(cmdarg_T *cap);

View File

@@ -156,6 +156,10 @@ describe(':help', function()
-- n.command [[set keywordprg=:help]]
-- Failure modes:
set_lines ''
cursor(0, { 1, 1 })
t.matches('E349: No identifier under cursor', t.pcall_err(n.exec, [[:help!]]))
set_lines 'xxxxxxxxx'
cursor(0, { 1, 4 })
t.matches('E149: No help for xxxxxxxxx', t.pcall_err(n.exec, [[:help!]]))