]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0742: getcmdprompt() implementation can be improved v9.1.0742
authorh-east <h.east.727@gmail.com>
Thu, 26 Sep 2024 14:01:57 +0000 (16:01 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 26 Sep 2024 14:01:57 +0000 (16:01 +0200)
Problem:  getcmdprompt() implementation can be improved
Solution: Improve and simplify it (h-east)

closes: #15743

Signed-off-by: h-east <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/evalfunc.c
src/ex_getln.c
src/proto/ex_getln.pro
src/testdir/test_cmdline.vim
src/version.c

index 7c096a261e60837a0e13b254bcb6c67c430d4f9c..67104eaf2c7caa7c453e6930723683b0000725b1 100644 (file)
@@ -3780,8 +3780,6 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
     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);
index 61f8379df559e563247fd3dae8a98fb915625c5e..ef7ca9186dd03bb0ce8865143e3c04d3de52990c 100644 (file)
@@ -30,7 +30,6 @@ 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
@@ -50,9 +49,6 @@ 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);
@@ -4235,24 +4231,6 @@ 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
  */
@@ -4272,7 +4250,8 @@ 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;
+    rettv->vval.v_string = p != NULL && p->cmdprompt != NULL ?
+                                           vim_strsave(p->cmdprompt) : NULL;
 }
 
 /*
@@ -4898,8 +4877,6 @@ 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');
index 8cf75b7d3663f040e4a2bf5349603b9739f3fede..1ab3b1ccafc04d350240942f671c467a97db4bc2 100644 (file)
@@ -40,7 +40,6 @@ void f_setcmdline(typval_T *argvars, typval_T *rettv);
 void f_setcmdpos(typval_T *argvars, typval_T *rettv);
 int get_cmdline_firstc(void);
 int get_list_range(char_u **str, int *num1, int *num2);
-void set_prompt(char_u* str);
 char *did_set_cedit(optset_T *args);
 int is_in_cmdwin(void);
 char_u *script_get(exarg_T *eap, char_u *cmd);
index 17717d2ab8409adc2a6240373df839b92bcdd857..708f211c6990adb38bb25ce4b158ff9e119969d2 100644 (file)
@@ -1650,6 +1650,17 @@ func Test_getcmdtype_getcmdprompt()
   call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
   call assert_equal('Answer?', g:cmdprompt)
   call assert_equal('', getcmdprompt())
+  call feedkeys(":\<CR>\<ESC>", "xt")
+  call assert_equal('', g:cmdprompt)
+  call assert_equal('', getcmdprompt())
+
+  let str = "C" .. repeat("c", 1023) .. "xyz"
+  call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
+  call assert_equal(str, g:cmdprompt)
+
+  call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
+  call assert_equal('Ans?', g:cmdprompt)
+  call assert_equal('', getcmdprompt())
 
   augroup test_CmdlineEnter
     au!
index 72e443aa00ed88420f1912cdfa9480d19524230a..f127fa12ea50e1ca0cb17a06ecbf67f16fb9a3ef 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    742,
 /**/
     741,
 /**/