diff src/usercmd.c @ 17468:fa6c9047ec70 v8.1.1732

patch 8.1.1732: completion in cmdwin does not work for buffer-local commands commit https://github.com/vim/vim/commit/f03e328348f87e1fe8ce4aad2a6a4237b9f78ce3 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 22 21:55:18 2019 +0200 patch 8.1.1732: completion in cmdwin does not work for buffer-local commands Problem: Completion in cmdwin does not work for buffer-local commands. Solution: Use the right buffer. (closes https://github.com/vim/vim/issues/4711)
author Bram Moolenaar <Bram@vim.org>
date Mon, 22 Jul 2019 22:00:05 +0200
parents 81705f4d9e03
children 9efb4dda9720
line wrap: on
line diff
--- a/src/usercmd.c
+++ b/src/usercmd.c
@@ -309,9 +309,16 @@ get_user_command_name(int idx)
     char_u *
 get_user_commands(expand_T *xp UNUSED, int idx)
 {
-    if (idx < curbuf->b_ucmds.ga_len)
-	return USER_CMD_GA(&curbuf->b_ucmds, idx)->uc_name;
-    idx -= curbuf->b_ucmds.ga_len;
+    // In cmdwin, the alternative buffer should be used.
+    buf_T *buf =
+#ifdef FEAT_CMDWIN
+	(cmdwin_type != 0 && get_cmdline_type() == NUL) ? prevwin->w_buffer :
+#endif
+	curbuf;
+
+    if (idx < buf->b_ucmds.ga_len)
+	return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name;
+    idx -= buf->b_ucmds.ga_len;
     if (idx < ucmds.ga_len)
 	return USER_CMD(idx)->uc_name;
     return NULL;
@@ -395,7 +402,13 @@ uc_list(char_u *name, size_t name_len)
     long	a;
     garray_T	*gap;
 
-    gap = &curbuf->b_ucmds;
+    /* In cmdwin, the alternative buffer should be used. */
+    gap =
+#ifdef FEAT_CMDWIN
+	(cmdwin_type != 0 && get_cmdline_type() == NUL) ?
+	&prevwin->w_buffer->b_ucmds :
+#endif
+	&curbuf->b_ucmds;
     for (;;)
     {
 	for (i = 0; i < gap->ga_len; ++i)