To: vim_dev@googlegroups.com Subject: Patch 8.2.3414 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3414 Problem: fullcommand() gives the wrong name if there is a buffer-local user command. (Naohiro Ono) Solution: Use a separate function to get the user command name. (closes #8840) Files: src/usercmd.c, src/proto/usercmd.pro, src/ex_docmd.c, src/testdir/test_cmdline.vim *** ../vim-8.2.3413/src/usercmd.c 2021-08-04 16:09:19.969646556 +0200 --- src/usercmd.c 2021-09-08 14:05:16.037620248 +0200 *************** *** 289,295 **** } char_u * ! get_user_command_name(int idx) { return get_user_commands(NULL, idx - (int)CMD_SIZE); } --- 289,295 ---- } char_u * ! expand_user_command_name(int idx) { return get_user_commands(NULL, idx - (int)CMD_SIZE); } *************** *** 315,320 **** --- 315,346 ---- return NULL; } + /* + * Get the name of user command "idx". "cmdidx" can be CMD_USER or + * CMD_USER_BUF. + * Returns NULL if the command is not found. + */ + char_u * + get_user_command_name(int idx, int cmdidx) + { + if (cmdidx == CMD_USER && idx < ucmds.ga_len) + return USER_CMD(idx)->uc_name; + if (cmdidx == CMD_USER_BUF) + { + // 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; + } + return NULL; + } + /* * Function given to ExpandGeneric() to obtain the list of user address type * names. *** ../vim-8.2.3413/src/proto/usercmd.pro 2021-08-01 14:52:05.558645405 +0200 --- src/proto/usercmd.pro 2021-09-08 14:05:18.309615060 +0200 *************** *** 1,8 **** /* usercmd.c */ char_u *find_ucmd(exarg_T *eap, char_u *p, int *full, expand_T *xp, int *complp); char_u *set_context_in_user_cmd(expand_T *xp, char_u *arg_in); ! char_u *get_user_command_name(int idx); char_u *get_user_commands(expand_T *xp, int idx); char_u *get_user_cmd_addr_type(expand_T *xp, int idx); char_u *get_user_cmd_flags(expand_T *xp, int idx); char_u *get_user_cmd_nargs(expand_T *xp, int idx); --- 1,9 ---- /* usercmd.c */ char_u *find_ucmd(exarg_T *eap, char_u *p, int *full, expand_T *xp, int *complp); char_u *set_context_in_user_cmd(expand_T *xp, char_u *arg_in); ! char_u *expand_user_command_name(int idx); char_u *get_user_commands(expand_T *xp, int idx); + char_u *get_user_command_name(int idx, int cmdidx); char_u *get_user_cmd_addr_type(expand_T *xp, int idx); char_u *get_user_cmd_flags(expand_T *xp, int idx); char_u *get_user_cmd_nargs(expand_T *xp, int idx); *** ../vim-8.2.3413/src/ex_docmd.c 2021-09-06 17:10:55.073336145 +0200 --- src/ex_docmd.c 2021-09-08 14:29:08.921625735 +0200 *************** *** 3895,3902 **** } rettv->vval.v_string = vim_strsave(IS_USER_CMDIDX(ea.cmdidx) ! ? get_user_commands(NULL, ea.useridx) ! : cmdnames[ea.cmdidx].cmd_name); } #endif --- 3895,3902 ---- } rettv->vval.v_string = vim_strsave(IS_USER_CMDIDX(ea.cmdidx) ! ? get_user_command_name(ea.useridx, ea.cmdidx) ! : cmdnames[ea.cmdidx].cmd_name); } #endif *************** *** 5519,5525 **** get_command_name(expand_T *xp UNUSED, int idx) { if (idx >= (int)CMD_SIZE) ! return get_user_command_name(idx); return cmdnames[idx].cmd_name; } --- 5519,5525 ---- get_command_name(expand_T *xp UNUSED, int idx) { if (idx >= (int)CMD_SIZE) ! return expand_user_command_name(idx); return cmdnames[idx].cmd_name; } *** ../vim-8.2.3413/src/testdir/test_cmdline.vim 2021-09-01 13:03:31.422768900 +0200 --- src/testdir/test_cmdline.vim 2021-09-08 14:07:55.165266243 +0200 *************** *** 482,487 **** --- 482,494 ---- call assert_equal('', fullcommand(test_null_string())) call assert_equal('syntax', 'syn'->fullcommand()) + + command -buffer BufferLocalCommand : + command GlobalCommand : + call assert_equal('GlobalCommand', fullcommand('GlobalCom')) + call assert_equal('BufferLocalCommand', fullcommand('BufferL')) + delcommand BufferLocalCommand + delcommand GlobalCommand endfunc func Test_shellcmd_completion() *** ../vim-8.2.3413/src/version.c 2021-09-08 12:31:31.862351834 +0200 --- src/version.c 2021-09-08 14:02:06.894068560 +0200 *************** *** 757,758 **** --- 757,760 ---- { /* Add new patch number below this line */ + /**/ + 3414, /**/ -- The goal of science is to build better mousetraps. The goal of nature is to build better mice. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///