aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_getln.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-08-30 07:07:50 +0800
committerGitHub <noreply@github.com>2022-08-30 07:07:50 +0800
commit7f20d61e0036433a819cb89aa73baf81d4ff5d2c (patch)
treef1ba2d3514378e1f3fa44b538c8dda004ae81de1 /src/nvim/ex_getln.c
parentf58a9795990a3b324f66912e4ae33dae7eb7474d (diff)
parente6e9879cb3eecf9d5c3f3964259a89dc36f60d52 (diff)
downloadrneovim-7f20d61e0036433a819cb89aa73baf81d4ff5d2c.tar.gz
rneovim-7f20d61e0036433a819cb89aa73baf81d4ff5d2c.tar.bz2
rneovim-7f20d61e0036433a819cb89aa73baf81d4ff5d2c.zip
Merge pull request #19999 from zeertzjq/vim-9.0.0320
vim-patch:9.0.0320: command line type of CmdlineChange differs from getcmdtype()
Diffstat (limited to 'src/nvim/ex_getln.c')
-rw-r--r--src/nvim/ex_getln.c146
1 files changed, 92 insertions, 54 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index ec2672c675..66c3327ce3 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -3933,8 +3933,41 @@ static CmdlineInfo *get_ccline_ptr(void)
}
}
+/// 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)
+{
+ CmdlineInfo *p = get_ccline_ptr();
+
+ if (p == NULL) {
+ return NUL;
+ }
+ if (p->cmdfirstc == NUL) {
+ return (p->input_fn) ? '@' : '-';
+ }
+ return p->cmdfirstc;
+}
+
+/// Get the current command line in allocated memory.
+/// Only works when the command line is being edited.
+/// Returns NULL when something is wrong.
+static char_u *get_cmdline_str(void)
+{
+ if (cmdline_star > 0) {
+ return NULL;
+ }
+ CmdlineInfo *p = get_ccline_ptr();
+
+ if (p == NULL) {
+ return NULL;
+ }
+ return vim_strnsave(p->cmdbuff, (size_t)p->cmdlen);
+}
+
/// Get the current command-line completion type.
-char_u *get_cmdline_completion(void)
+static char_u *get_cmdline_completion(void)
{
if (cmdline_star > 0) {
return NULL;
@@ -3952,54 +3985,45 @@ char_u *get_cmdline_completion(void)
return NULL;
}
-/*
- * Get the current command line in allocated memory.
- * Only works when the command line is being edited.
- * Returns NULL when something is wrong.
- */
-char_u *get_cmdline_str(void)
+/// "getcmdcompltype()" function
+void f_getcmdcompltype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
- if (cmdline_star > 0) {
- return NULL;
- }
- CmdlineInfo *p = get_ccline_ptr();
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = (char *)get_cmdline_completion();
+}
- if (p == NULL) {
- return NULL;
- }
- return vim_strnsave(p->cmdbuff, (size_t)p->cmdlen);
+/// "getcmdline()" function
+void f_getcmdline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
+{
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = (char *)get_cmdline_str();
}
-/*
- * Get the current command line position, counted in bytes.
- * Zero is the first position.
- * Only works when the command line is being edited.
- * Returns -1 when something is wrong.
- */
-int get_cmdline_pos(void)
+/// "getcmdpos()" function
+void f_getcmdpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
CmdlineInfo *p = get_ccline_ptr();
-
- if (p == NULL) {
- return -1;
- }
- return p->cmdpos;
+ rettv->vval.v_number = p != NULL ? p->cmdpos + 1 : 0;
}
-/// Get the command line cursor screen position.
-int get_cmdline_screen_pos(void)
+/// "getcmdscreenpos()" function
+void f_getcmdscreenpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
CmdlineInfo *p = get_ccline_ptr();
+ rettv->vval.v_number = p != NULL ? p->cmdspos + 1 : 0;
+}
- if (p == NULL) {
- return -1;
- }
- return p->cmdspos;
+/// "getcmdtype()" function
+void f_getcmdtype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
+{
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = xmallocz(1);
+ rettv->vval.v_string[0] = (char)get_cmdline_type();
}
/// Set the command line str to "str".
/// @return 1 when failed, 0 when OK.
-int set_cmdline_str(const char *str, int pos)
+static int set_cmdline_str(const char *str, int pos)
{
CmdlineInfo *p = get_ccline_ptr();
@@ -4018,17 +4042,15 @@ int set_cmdline_str(const char *str, int pos)
redrawcmd();
// Trigger CmdlineChanged autocommands.
- do_autocmd_cmdlinechanged(ccline.cmdfirstc == NUL ? '-' : ccline.cmdfirstc);
+ do_autocmd_cmdlinechanged(get_cmdline_type());
return 0;
}
-/*
- * Set the command line byte position to "pos". Zero is the first position.
- * Only works when the command line is being edited.
- * Returns 1 when failed, 0 when OK.
- */
-int set_cmdline_pos(int pos)
+/// Set the command line byte position to "pos". Zero is the first position.
+/// Only works when the command line is being edited.
+/// @return 1 when failed, 0 when OK.
+static int set_cmdline_pos(int pos)
{
CmdlineInfo *p = get_ccline_ptr();
@@ -4046,23 +4068,39 @@ int set_cmdline_pos(int pos)
return 0;
}
-/*
- * 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.
- */
-int get_cmdline_type(void)
+/// "setcmdline()" function
+void f_setcmdline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
- CmdlineInfo *p = get_ccline_ptr();
+ if (argvars[0].v_type != VAR_STRING || argvars[0].vval.v_string == NULL) {
+ emsg(_(e_stringreq));
+ return;
+ }
- if (p == NULL) {
- return NUL;
+ int pos = -1;
+ if (argvars[1].v_type != VAR_UNKNOWN) {
+ bool error = false;
+
+ pos = (int)tv_get_number_chk(&argvars[1], &error) - 1;
+ if (error) {
+ return;
+ }
+ if (pos < 0) {
+ emsg(_(e_positive));
+ return;
+ }
}
- if (p->cmdfirstc == NUL) {
- return (p->input_fn) ? '@' : '-';
+
+ rettv->vval.v_number = set_cmdline_str(argvars[0].vval.v_string, pos);
+}
+
+/// "setcmdpos()" function
+void f_setcmdpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
+{
+ const int pos = (int)tv_get_number(&argvars[0]) - 1;
+
+ if (pos >= 0) {
+ rettv->vval.v_number = set_cmdline_pos(pos);
}
- return p->cmdfirstc;
}
/// Return the first character of the current command line.