1
0
forked from aniani/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: #15667

Signed-off-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Shougo Matsushita
2024-09-23 20:34:47 +02:00
committed by Christian Brabandt
parent 770b38df40
commit 6908428560
9 changed files with 86 additions and 14 deletions

View File

@@ -30,6 +30,7 @@ static cmdline_info_T ccline;
#ifdef FEAT_EVAL
static int new_cmdpos; // position set by set_cmdline_pos()
static char_u current_prompt[CMDBUFFSIZE + 1] = "";
#endif
static int extra_char = NUL; // extra character to display when redrawing
@@ -49,6 +50,9 @@ static void alloc_cmdbuff(int len);
static void draw_cmdline(int start, int len);
static void save_cmdline(cmdline_info_T *ccp);
static void restore_cmdline(cmdline_info_T *ccp);
#ifdef FEAT_EVAL
static char_u *get_prompt(void);
#endif
static int cmdline_paste(int regname, int literally, int remcr);
static void redrawcmdprompt(void);
static int ccheck_abbr(int);
@@ -4231,6 +4235,24 @@ f_getcmdline(typval_T *argvars UNUSED, typval_T *rettv)
rettv->vval.v_string = get_cmdline_str();
}
/*
* Get current command line prompt.
*/
static char_u *
get_prompt(void)
{
return current_prompt;
}
/*
* Set current command line prompt.
*/
void
set_prompt(char_u* str)
{
vim_strncpy(current_prompt, str, sizeof(current_prompt) - 1);
}
/*
* "getcmdpos()" function
*/
@@ -4242,6 +4264,17 @@ f_getcmdpos(typval_T *argvars UNUSED, typval_T *rettv)
rettv->vval.v_number = p != NULL ? p->cmdpos + 1 : 0;
}
/*
* "getcmdprompt()" function
*/
void
f_getcmdprompt(typval_T *argvars UNUSED, typval_T *rettv)
{
cmdline_info_T *p = get_ccline_ptr();
rettv->v_type = VAR_STRING;
rettv->vval.v_string = p != NULL ? vim_strsave(get_prompt()) : NULL;
}
/*
* "getcmdscreenpos()" function
*/
@@ -4865,6 +4898,8 @@ get_user_input(
cmd_silent = FALSE; // Want to see the prompt.
if (prompt != NULL)
{
set_prompt(prompt);
// Only the part of the message after the last NL is considered as
// prompt for the command line
p = vim_strrchr(prompt, '\n');