summaryrefslogtreecommitdiffstats
path: root/src/ex_getln.c
diff options
context:
space:
mode:
authorShougo Matsushita <Shougo.Matsu@gmail.com>2022-05-07 12:48:29 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-07 12:48:29 +0100
commit79d599b8772022af1d657f368c2fc97aa342c0da (patch)
treeee415de85697c73717db8ca0679481349d097965 /src/ex_getln.c
parentc27747e6ddcbda7d1d3b39867898f746dc4db471 (diff)
patch 8.2.4903: cannot get the current cmdline completion type and positionv8.2.4903
Problem: Cannot get the current cmdline completion type and position. Solution: Add getcmdcompltype() and getcmdscreenpos(). (Shougo Matsushita, closes #10344)
Diffstat (limited to 'src/ex_getln.c')
-rw-r--r--src/ex_getln.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/ex_getln.c b/src/ex_getln.c
index 7020f5143a..09f2842833 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -4119,6 +4119,42 @@ get_cmdline_str(void)
}
/*
+ * Get the current command-line completion type.
+ */
+ static char_u *
+get_cmdline_completion(void)
+{
+ cmdline_info_T *p;
+
+ if (cmdline_star > 0)
+ return NULL;
+
+ p = get_ccline_ptr();
+ if (p && p->xpc != NULL)
+ {
+ char_u *cmd_compl;
+
+ set_expand_context(p->xpc);
+
+ cmd_compl = cmdcomplete_type_to_str(p->xpc->xp_context);
+ if (cmd_compl != NULL)
+ return vim_strnsave(cmd_compl, strlen((char *)cmd_compl));
+ }
+
+ return NULL;
+}
+
+/*
+ * "getcmdcompltype()" function
+ */
+ void
+f_getcmdcompltype(typval_T *argvars UNUSED, typval_T *rettv)
+{
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = get_cmdline_completion();
+}
+
+/*
* "getcmdline()" function
*/
void
@@ -4142,6 +4178,28 @@ f_getcmdpos(typval_T *argvars UNUSED, typval_T *rettv)
}
/*
+ * Get the command line cursor screen position.
+ */
+ static int
+get_cmdline_screen_pos(void)
+{
+ cmdline_info_T *p = get_ccline_ptr();
+
+ if (p == NULL)
+ return -1;
+ return p->cmdspos;
+}
+
+/*
+ * "getcmdscreenpos()" function
+ */
+ void
+f_getcmdscreenpos(typval_T *argvars UNUSED, typval_T *rettv)
+{
+ rettv->vval.v_number = get_cmdline_screen_pos() + 1;
+}
+
+/*
* 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.