diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-09-24 06:51:02 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2024-09-26 22:15:28 +0800 |
commit | c2fb1fc700db28cb554be9da8e79443b5d3a5fe9 (patch) | |
tree | b90b04c1b252237d2d705422eebd8eef6d17d96f /src | |
parent | 66197dde7084484c9d23fa488b2288bcae364ba7 (diff) | |
download | rneovim-c2fb1fc700db28cb554be9da8e79443b5d3a5fe9.tar.gz rneovim-c2fb1fc700db28cb554be9da8e79443b5d3a5fe9.tar.bz2 rneovim-c2fb1fc700db28cb554be9da8e79443b5d3a5fe9.zip |
vim-patch:9.1.0741: No way to get prompt for input()/confirm()
Problem: No way to get prompt for input()/confirm()
Solution: add getcmdprompt() function (Shougo Matsushita)
(Shougo Matsushita)
closes: vim/vim#15667
https://github.com/vim/vim/commit/6908428560a0d6ae27bf7af6fcb6dc362e31926c
Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.lua | 32 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 24 |
3 files changed, 49 insertions, 9 deletions
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 2a3327b37b..4545ad1149 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -3594,8 +3594,8 @@ M.funcs = { Only works when the command line is being edited, thus requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. See |:command-completion| for the return string. - Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and - |setcmdline()|. + Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|, + |getcmdprompt()| and |setcmdline()|. Returns an empty string when completion is not defined. ]=], name = 'getcmdcompltype', @@ -3605,13 +3605,13 @@ M.funcs = { }, getcmdline = { desc = [=[ - Return the current command-line. Only works when the command - line is being edited, thus requires use of |c_CTRL-\_e| or - |c_CTRL-R_=|. + Return the current command-line input. Only works when the + command line is being edited, thus requires use of + |c_CTRL-\_e| or |c_CTRL-R_=|. Example: >vim cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR> - <Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and - |setcmdline()|. + <Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|, + |getcmdprompt()| and |setcmdline()|. Returns an empty string when entering a password or using |inputsecret()|. ]=], @@ -3627,14 +3627,28 @@ M.funcs = { Only works when editing the command line, thus requires use of |c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping. Returns 0 otherwise. - Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and - |setcmdline()|. + Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|, + |getcmdprompt()| and |setcmdline()|. ]=], name = 'getcmdpos', params = {}, returns = 'integer', signature = 'getcmdpos()', }, + getcmdprompt = { + desc = [=[ + Return the current command-line prompt when using functions + like |input()| or |confirm()|. + Only works when the command line is being edited, thus + requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. + Also see |getcmdtype()|, |getcmdline()|, |getcmdpos()|, + |setcmdpos()| and |setcmdline()|. + ]=], + name = 'getcmdprompt', + params = {}, + returns = 'string', + signature = 'getcmdprompt()', + }, getcmdscreenpos = { desc = [=[ Return the screen position of the cursor in the command line diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index e8b9288717..4a96c9a3f3 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -813,6 +813,8 @@ static void f_confirm(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const char *message = tv_get_string_chk(&argvars[0]); if (message == NULL) { error = true; + } else { + set_prompt(message); } if (argvars[1].v_type != VAR_UNKNOWN) { buttons = tv_get_string_buf_chk(&argvars[1], buf); diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 6a57b3ab78..7eb4fe67a1 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4132,6 +4132,28 @@ void f_getcmdpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) rettv->vval.v_number = p != NULL ? p->cmdpos + 1 : 0; } +static char current_prompt[CMDBUFFSIZE + 1] = ""; + +/// Get current command line prompt. +static char *get_prompt(void) +{ + return current_prompt; +} + +/// Set current command line prompt. +void set_prompt(const char *str) +{ + xstrlcpy(current_prompt, str, sizeof(current_prompt)); +} + +/// "getcmdprompt()" function +void f_getcmdprompt(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) +{ + CmdlineInfo *p = get_ccline_ptr(); + rettv->v_type = VAR_STRING; + rettv->vval.v_string = p != NULL ? xstrdup(get_prompt()) : NULL; +} + /// "getcmdscreenpos()" function void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { @@ -4730,6 +4752,8 @@ void get_user_input(const typval_T *const argvars, typval_T *const rettv, const const bool cmd_silent_save = cmd_silent; cmd_silent = false; // Want to see the prompt. + set_prompt(prompt); + // Only the part of the message after the last NL is considered as // prompt for the command line, unlsess cmdline is externalized const char *p = prompt; |