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:
parent
770b38df40
commit
6908428560
@ -1,4 +1,4 @@
|
|||||||
*builtin.txt* For Vim version 9.1. Last change: 2024 Sep 10
|
*builtin.txt* For Vim version 9.1. Last change: 2024 Sep 23
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@ -232,8 +232,9 @@ getcharsearch() Dict last character search
|
|||||||
getcharstr([{expr}]) String get one character from the user
|
getcharstr([{expr}]) String get one character from the user
|
||||||
getcmdcompltype() String return the type of the current
|
getcmdcompltype() String return the type of the current
|
||||||
command-line completion
|
command-line completion
|
||||||
getcmdline() String return the current command-line
|
getcmdline() String return the current command-line input
|
||||||
getcmdpos() Number return cursor position in command-line
|
getcmdpos() Number return cursor position in command-line
|
||||||
|
getcmdprompt() String return the current command-line prompt
|
||||||
getcmdscreenpos() Number return cursor screen position in
|
getcmdscreenpos() Number return cursor screen position in
|
||||||
command-line
|
command-line
|
||||||
getcmdtype() String return current command-line type
|
getcmdtype() String return current command-line type
|
||||||
@ -3978,21 +3979,21 @@ getcmdcompltype() *getcmdcompltype()*
|
|||||||
Only works when the command line is being edited, thus
|
Only works when the command line is being edited, thus
|
||||||
requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
|
requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
|
||||||
See |:command-completion| for the return string.
|
See |:command-completion| for the return string.
|
||||||
Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
|
Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
|
||||||
|setcmdline()|.
|
|getcmdprompt()| and |setcmdline()|.
|
||||||
Returns an empty string when completion is not defined.
|
Returns an empty string when completion is not defined.
|
||||||
|
|
||||||
Return type: |String|
|
Return type: |String|
|
||||||
|
|
||||||
|
|
||||||
getcmdline() *getcmdline()*
|
getcmdline() *getcmdline()*
|
||||||
Return the current command-line. Only works when the command
|
Return the current command-line input. Only works when the
|
||||||
line is being edited, thus requires use of |c_CTRL-\_e| or
|
command line is being edited, thus requires use of
|
||||||
|c_CTRL-R_=|.
|
|c_CTRL-\_e| or |c_CTRL-R_=|.
|
||||||
Example: >
|
Example: >
|
||||||
:cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
|
:cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
|
||||||
< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()| and
|
< Also see |getcmdtype()|, |getcmdpos()|, |setcmdpos()|,
|
||||||
|setcmdline()|.
|
|getcmdprompt()| and |setcmdline()|.
|
||||||
Returns an empty string when entering a password or using
|
Returns an empty string when entering a password or using
|
||||||
|inputsecret()|.
|
|inputsecret()|.
|
||||||
|
|
||||||
@ -4005,12 +4006,23 @@ getcmdpos() *getcmdpos()*
|
|||||||
Only works when editing the command line, thus requires use of
|
Only works when editing the command line, thus requires use of
|
||||||
|c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
|
|c_CTRL-\_e| or |c_CTRL-R_=| or an expression mapping.
|
||||||
Returns 0 otherwise.
|
Returns 0 otherwise.
|
||||||
Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()| and
|
Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
|
||||||
|setcmdline()|.
|
|getcmdprompt()| and |setcmdline()|.
|
||||||
|
|
||||||
Return type: |Number|
|
Return type: |Number|
|
||||||
|
|
||||||
|
|
||||||
|
getcmdprompt() *getcmdprompt()*
|
||||||
|
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()|.
|
||||||
|
|
||||||
|
Return type: |String|
|
||||||
|
|
||||||
|
|
||||||
getcmdscreenpos() *getcmdscreenpos()*
|
getcmdscreenpos() *getcmdscreenpos()*
|
||||||
Return the screen position of the cursor in the command line
|
Return the screen position of the cursor in the command line
|
||||||
as a byte count. The first column is 1.
|
as a byte count. The first column is 1.
|
||||||
|
@ -7827,6 +7827,7 @@ getcharstr() builtin.txt /*getcharstr()*
|
|||||||
getcmdcompltype() builtin.txt /*getcmdcompltype()*
|
getcmdcompltype() builtin.txt /*getcmdcompltype()*
|
||||||
getcmdline() builtin.txt /*getcmdline()*
|
getcmdline() builtin.txt /*getcmdline()*
|
||||||
getcmdpos() builtin.txt /*getcmdpos()*
|
getcmdpos() builtin.txt /*getcmdpos()*
|
||||||
|
getcmdprompt() builtin.txt /*getcmdprompt()*
|
||||||
getcmdscreenpos() builtin.txt /*getcmdscreenpos()*
|
getcmdscreenpos() builtin.txt /*getcmdscreenpos()*
|
||||||
getcmdtype() builtin.txt /*getcmdtype()*
|
getcmdtype() builtin.txt /*getcmdtype()*
|
||||||
getcmdwintype() builtin.txt /*getcmdwintype()*
|
getcmdwintype() builtin.txt /*getcmdwintype()*
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
*usr_41.txt* For Vim version 9.1. Last change: 2024 Jun 09
|
*usr_41.txt* For Vim version 9.1. Last change: 2024 Sep 23
|
||||||
|
|
||||||
VIM USER MANUAL - by Bram Moolenaar
|
VIM USER MANUAL - by Bram Moolenaar
|
||||||
|
|
||||||
@ -1070,7 +1070,8 @@ Buffers, windows and the argument list:
|
|||||||
Command line: *command-line-functions*
|
Command line: *command-line-functions*
|
||||||
getcmdcompltype() get the type of the current command line
|
getcmdcompltype() get the type of the current command line
|
||||||
completion
|
completion
|
||||||
getcmdline() get the current command line
|
getcmdline() get the current command line input
|
||||||
|
getcmdprompt() get the current command line prompt
|
||||||
getcmdpos() get position of the cursor in the command line
|
getcmdpos() get position of the cursor in the command line
|
||||||
getcmdscreenpos() get screen position of the cursor in the
|
getcmdscreenpos() get screen position of the cursor in the
|
||||||
command line
|
command line
|
||||||
|
@ -41608,6 +41608,7 @@ Functions: ~
|
|||||||
|diff()| diff two Lists of strings
|
|diff()| diff two Lists of strings
|
||||||
|filecopy()| copy a file {from} to {to}
|
|filecopy()| copy a file {from} to {to}
|
||||||
|foreach()| apply function to List items
|
|foreach()| apply function to List items
|
||||||
|
|getcmdprompt()| get prompt for input()/confirm()
|
||||||
|getregion()| get a region of text from a buffer
|
|getregion()| get a region of text from a buffer
|
||||||
|getregionpos()| get a list of positions for a region
|
|getregionpos()| get a list of positions for a region
|
||||||
|id()| get unique identifier for a Dict, List, Object,
|
|id()| get unique identifier for a Dict, List, Object,
|
||||||
|
@ -2097,6 +2097,8 @@ static funcentry_T global_functions[] =
|
|||||||
ret_string, f_getcmdline},
|
ret_string, f_getcmdline},
|
||||||
{"getcmdpos", 0, 0, 0, NULL,
|
{"getcmdpos", 0, 0, 0, NULL,
|
||||||
ret_number, f_getcmdpos},
|
ret_number, f_getcmdpos},
|
||||||
|
{"getcmdprompt", 0, 0, 0, NULL,
|
||||||
|
ret_string, f_getcmdprompt},
|
||||||
{"getcmdscreenpos", 0, 0, 0, NULL,
|
{"getcmdscreenpos", 0, 0, 0, NULL,
|
||||||
ret_number, f_getcmdscreenpos},
|
ret_number, f_getcmdscreenpos},
|
||||||
{"getcmdtype", 0, 0, 0, NULL,
|
{"getcmdtype", 0, 0, 0, NULL,
|
||||||
@ -3778,6 +3780,8 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
|
|||||||
message = tv_get_string_chk(&argvars[0]);
|
message = tv_get_string_chk(&argvars[0]);
|
||||||
if (message == NULL)
|
if (message == NULL)
|
||||||
error = TRUE;
|
error = TRUE;
|
||||||
|
else
|
||||||
|
set_prompt(message);
|
||||||
if (argvars[1].v_type != VAR_UNKNOWN)
|
if (argvars[1].v_type != VAR_UNKNOWN)
|
||||||
{
|
{
|
||||||
buttons = tv_get_string_buf_chk(&argvars[1], buf);
|
buttons = tv_get_string_buf_chk(&argvars[1], buf);
|
||||||
|
@ -30,6 +30,7 @@ static cmdline_info_T ccline;
|
|||||||
|
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
static int new_cmdpos; // position set by set_cmdline_pos()
|
static int new_cmdpos; // position set by set_cmdline_pos()
|
||||||
|
static char_u current_prompt[CMDBUFFSIZE + 1] = "";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int extra_char = NUL; // extra character to display when redrawing
|
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 draw_cmdline(int start, int len);
|
||||||
static void save_cmdline(cmdline_info_T *ccp);
|
static void save_cmdline(cmdline_info_T *ccp);
|
||||||
static void restore_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 int cmdline_paste(int regname, int literally, int remcr);
|
||||||
static void redrawcmdprompt(void);
|
static void redrawcmdprompt(void);
|
||||||
static int ccheck_abbr(int);
|
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();
|
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
|
* "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;
|
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
|
* "getcmdscreenpos()" function
|
||||||
*/
|
*/
|
||||||
@ -4865,6 +4898,8 @@ get_user_input(
|
|||||||
cmd_silent = FALSE; // Want to see the prompt.
|
cmd_silent = FALSE; // Want to see the prompt.
|
||||||
if (prompt != NULL)
|
if (prompt != NULL)
|
||||||
{
|
{
|
||||||
|
set_prompt(prompt);
|
||||||
|
|
||||||
// Only the part of the message after the last NL is considered as
|
// Only the part of the message after the last NL is considered as
|
||||||
// prompt for the command line
|
// prompt for the command line
|
||||||
p = vim_strrchr(prompt, '\n');
|
p = vim_strrchr(prompt, '\n');
|
||||||
|
@ -33,12 +33,14 @@ cmdline_info_T *get_cmdline_info(void);
|
|||||||
void f_getcmdcompltype(typval_T *argvars, typval_T *rettv);
|
void f_getcmdcompltype(typval_T *argvars, typval_T *rettv);
|
||||||
void f_getcmdline(typval_T *argvars, typval_T *rettv);
|
void f_getcmdline(typval_T *argvars, typval_T *rettv);
|
||||||
void f_getcmdpos(typval_T *argvars, typval_T *rettv);
|
void f_getcmdpos(typval_T *argvars, typval_T *rettv);
|
||||||
|
void f_getcmdprompt(typval_T *argvars, typval_T *rettv);
|
||||||
void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv);
|
void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv);
|
||||||
void f_getcmdtype(typval_T *argvars, typval_T *rettv);
|
void f_getcmdtype(typval_T *argvars, typval_T *rettv);
|
||||||
void f_setcmdline(typval_T *argvars, typval_T *rettv);
|
void f_setcmdline(typval_T *argvars, typval_T *rettv);
|
||||||
void f_setcmdpos(typval_T *argvars, typval_T *rettv);
|
void f_setcmdpos(typval_T *argvars, typval_T *rettv);
|
||||||
int get_cmdline_firstc(void);
|
int get_cmdline_firstc(void);
|
||||||
int get_list_range(char_u **str, int *num1, int *num2);
|
int get_list_range(char_u **str, int *num1, int *num2);
|
||||||
|
void set_prompt(char_u* str);
|
||||||
char *did_set_cedit(optset_T *args);
|
char *did_set_cedit(optset_T *args);
|
||||||
int is_in_cmdwin(void);
|
int is_in_cmdwin(void);
|
||||||
char_u *script_get(exarg_T *eap, char_u *cmd);
|
char_u *script_get(exarg_T *eap, char_u *cmd);
|
||||||
|
@ -1617,7 +1617,7 @@ endfunc
|
|||||||
|
|
||||||
set cpo&
|
set cpo&
|
||||||
|
|
||||||
func Test_getcmdtype()
|
func Test_getcmdtype_getcmdprompt()
|
||||||
call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
|
call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
|
||||||
|
|
||||||
let cmdtype = ''
|
let cmdtype = ''
|
||||||
@ -1641,6 +1641,20 @@ func Test_getcmdtype()
|
|||||||
cunmap <F6>
|
cunmap <F6>
|
||||||
|
|
||||||
call assert_equal('', getcmdline())
|
call assert_equal('', getcmdline())
|
||||||
|
|
||||||
|
call assert_equal('', getcmdprompt())
|
||||||
|
augroup test_CmdlineEnter
|
||||||
|
autocmd!
|
||||||
|
autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
|
||||||
|
augroup END
|
||||||
|
call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
|
||||||
|
call assert_equal('Answer?', g:cmdprompt)
|
||||||
|
call assert_equal('', getcmdprompt())
|
||||||
|
|
||||||
|
augroup test_CmdlineEnter
|
||||||
|
au!
|
||||||
|
augroup END
|
||||||
|
augroup! test_CmdlineEnter
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_verbosefile()
|
func Test_verbosefile()
|
||||||
|
@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
741,
|
||||||
/**/
|
/**/
|
||||||
740,
|
740,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user