summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-08-29 16:21:25 +0100
committerBram Moolenaar <Bram@vim.org>2022-08-29 16:21:25 +0100
commit54acb90d9e672315e3bd13f8dc71f828df97c868 (patch)
treea6ace12d6378c530d8341c69a30ccf2c76a69c45 /src
parentd5c8f11905abc1bdf3b8864dbc40187855ed9374 (diff)
patch 9.0.0320: command line type of CmdlineChange differs from getcmdtype()v9.0.0320
Problem: Command line type of CmdlineChange differs from getcmdtype(). Solution: Use the same type. (closes #11005)
Diffstat (limited to 'src')
-rw-r--r--src/ex_getln.c98
-rw-r--r--src/proto/ex_getln.pro3
-rw-r--r--src/testdir/test_cmdline.vim13
-rw-r--r--src/version.c2
4 files changed, 56 insertions, 60 deletions
diff --git a/src/ex_getln.c b/src/ex_getln.c
index dadcfef77f..2454be71fa 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -4114,6 +4114,30 @@ get_ccline_ptr(void)
}
#endif
+#if defined(FEAT_EVAL) || defined(FEAT_CMDWIN)
+/*
+ * Get the current command-line type.
+ * Returns ':' or '/' or '?' or '@' or '>' or '-'
+ * Only works when the command line is being edited.
+ * Returns NUL when something is wrong.
+ */
+ static int
+get_cmdline_type(void)
+{
+ cmdline_info_T *p = get_ccline_ptr();
+
+ if (p == NULL)
+ return NUL;
+ if (p->cmdfirstc == NUL)
+ return
+# ifdef FEAT_EVAL
+ (p->input_fn) ? '@' :
+# endif
+ '-';
+ return p->cmdfirstc;
+}
+#endif
+
#if defined(FEAT_EVAL) || defined(PROTO)
/*
* Get the current command line in allocated memory.
@@ -4187,40 +4211,41 @@ f_getcmdpos(typval_T *argvars UNUSED, typval_T *rettv)
{
cmdline_info_T *p = get_ccline_ptr();
- rettv->vval.v_number = 0;
- if (p != NULL)
- rettv->vval.v_number = p->cmdpos + 1;
+ rettv->vval.v_number = p != NULL ? p->cmdpos + 1 : 0;
}
/*
- * Get the command line cursor screen position.
+ * "getcmdscreenpos()" function
*/
- static int
-get_cmdline_screen_pos(void)
+ void
+f_getcmdscreenpos(typval_T *argvars UNUSED, typval_T *rettv)
{
cmdline_info_T *p = get_ccline_ptr();
- if (p == NULL)
- return -1;
- return p->cmdspos;
+ rettv->vval.v_number = p != NULL ? p->cmdspos + 1 : 0;
}
/*
- * "getcmdscreenpos()" function
+ * "getcmdtype()" function
*/
void
-f_getcmdscreenpos(typval_T *argvars UNUSED, typval_T *rettv)
+f_getcmdtype(typval_T *argvars UNUSED, typval_T *rettv)
{
- rettv->vval.v_number = get_cmdline_screen_pos() + 1;
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = alloc(2);
+ if (rettv->vval.v_string != NULL)
+ {
+ rettv->vval.v_string[0] = get_cmdline_type();
+ rettv->vval.v_string[1] = NUL;
+ }
}
// Set the command line str to "str".
// Returns 1 when failed, 0 when OK.
- int
+ static int
set_cmdline_str(char_u *str, int pos)
{
cmdline_info_T *p = get_ccline_ptr();
- int cmdline_type;
int len;
if (p == NULL)
@@ -4237,8 +4262,7 @@ set_cmdline_str(char_u *str, int pos)
redrawcmd();
// Trigger CmdlineChanged autocommands.
- cmdline_type = ccline.cmdfirstc == NUL ? '-' : ccline.cmdfirstc;
- trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED);
+ trigger_cmd_autocmd(get_cmdline_type(), EVENT_CMDLINECHANGED);
return 0;
}
@@ -4310,48 +4334,6 @@ f_setcmdpos(typval_T *argvars, typval_T *rettv)
}
#endif
-#if defined(FEAT_EVAL) || defined(FEAT_CMDWIN)
-/*
- * Get the current command-line type.
- * Returns ':' or '/' or '?' or '@' or '>' or '-'
- * Only works when the command line is being edited.
- * Returns NUL when something is wrong.
- */
- static int
-get_cmdline_type(void)
-{
- cmdline_info_T *p = get_ccline_ptr();
-
- if (p == NULL)
- return NUL;
- if (p->cmdfirstc == NUL)
- return
-# ifdef FEAT_EVAL
- (p->input_fn) ? '@' :
-# endif
- '-';
- return p->cmdfirstc;
-}
-#endif
-
-#if defined(FEAT_EVAL) || defined(PROTO)
-/*
- * "getcmdtype()" function
- */
- void
-f_getcmdtype(typval_T *argvars UNUSED, typval_T *rettv)
-{
- rettv->v_type = VAR_STRING;
- rettv->vval.v_string = alloc(2);
- if (rettv->vval.v_string != NULL)
- {
- rettv->vval.v_string[0] = get_cmdline_type();
- rettv->vval.v_string[1] = NUL;
- }
-}
-
-#endif
-
/*
* Return the first character of the current command line.
*/
diff --git a/src/proto/ex_getln.pro b/src/proto/ex_getln.pro
index 2eb32ab422..88f0175ae4 100644
--- a/src/proto/ex_getln.pro
+++ b/src/proto/ex_getln.pro
@@ -34,10 +34,9 @@ void f_getcmdcompltype(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_getcmdscreenpos(typval_T *argvars, typval_T *rettv);
-int set_cmdline_str(char_u *str, int pos);
+void f_getcmdtype(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_getcmdtype(typval_T *argvars, typval_T *rettv);
int get_cmdline_firstc(void);
int get_list_range(char_u **str, int *num1, int *num2);
char *check_cedit(void);
diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim
index 81f0c6f0eb..f349ae49ed 100644
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -3264,9 +3264,13 @@ endfunc
func Test_setcmdline()
func SetText(text, pos)
+ autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
call assert_equal(0, setcmdline(a:text))
call assert_equal(a:text, getcmdline())
call assert_equal(len(a:text) + 1, getcmdpos())
+ call assert_equal(getcmdtype(), g:cmdtype)
+ unlet g:cmdtype
+ autocmd! CmdlineChanged
call assert_equal(0, setcmdline(a:text, a:pos))
call assert_equal(a:text, getcmdline())
@@ -3282,6 +3286,13 @@ func Test_setcmdline()
call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
call assert_equal('set rtp?', @:)
+ call feedkeys(":let g:str = input('? ')\<CR>", 't')
+ call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
+ call assert_equal('foo', g:str)
+ unlet g:str
+
+ delfunc SetText
+
" setcmdline() returns 1 when not editing the command line.
call assert_equal(1, 'foo'->setcmdline())
@@ -3294,6 +3305,8 @@ func Test_setcmdline()
com! -nargs=* -complete=custom,CustomComplete DoCmd :
call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"DoCmd January February Mars', @:)
+ delcom DoCmd
+ delfunc CustomComplete
" Called in <expr>
cnoremap <expr>a setcmdline('let foo=')
diff --git a/src/version.c b/src/version.c
index f743bb970d..121da621b1 100644
--- a/src/version.c
+++ b/src/version.c
@@ -708,6 +708,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 320,
+/**/
319,
/**/
318,