diff src/ex_getln.c @ 28757:add09d468c0d v8.2.4903

patch 8.2.4903: cannot get the current cmdline completion type and position Commit: https://github.com/vim/vim/commit/79d599b8772022af1d657f368c2fc97aa342c0da Author: Shougo Matsushita <Shougo.Matsu@gmail.com> Date: Sat May 7 12:48:29 2022 +0100 patch 8.2.4903: cannot get the current cmdline completion type and position Problem: Cannot get the current cmdline completion type and position. Solution: Add getcmdcompltype() and getcmdscreenpos(). (Shougo Matsushita, closes #10344)
author Bram Moolenaar <Bram@vim.org>
date Sat, 07 May 2022 14:00:02 +0200
parents 4a9fdf708575
children cf9f5b5c8079
line wrap: on
line diff
--- 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, ty
 }
 
 /*
+ * 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.