To: vim_dev@googlegroups.com Subject: Patch 8.2.4617 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4617 Problem: No completion for :scriptnames. Solution: Implement :scriptnames completion. (Yegappan Lakshmanan, closes #10005) Files: runtime/doc/builtin.txt, src/cmdexpand.c, src/ex_cmds.h, src/scriptfile.c, src/usercmd.c, src/vim.h, src/testdir/test_cmdline.vim, src/testdir/test_quickfix.vim *** ../vim-8.2.4616/runtime/doc/builtin.txt 2022-03-22 16:06:24.946137125 +0000 --- runtime/doc/builtin.txt 2022-03-24 10:36:11.210130525 +0000 *************** *** 3246,3251 **** --- 3256,3262 ---- messages |:messages| suboptions option options packadd optional package |pack-add| names + scriptnames sourced script names |:scriptnames| shellcmd Shell command sign |:sign| suboptions syntax syntax file names |'syntax'| *************** *** 3265,3271 **** If the 'wildoptions' option contains 'fuzzy', then fuzzy matching is used to get the completion matches. Otherwise ! regular expression matching is used. If {type} is "cmdline", then the |cmdline-completion| result is returned. For example, to complete the possible values after --- 3276,3285 ---- If the 'wildoptions' option contains 'fuzzy', then fuzzy matching is used to get the completion matches. Otherwise ! regular expression matching is used. Thus this function ! follows the user preference, what happens on the command line. ! If you do not want this you can make 'wildoptions' empty ! before calling getcompletion() and restore it afterwards. If {type} is "cmdline", then the |cmdline-completion| result is returned. For example, to complete the possible values after *** ../vim-8.2.4616/src/cmdexpand.c 2022-03-22 16:06:24.946137125 +0000 --- src/cmdexpand.c 2022-03-24 10:36:11.210130525 +0000 *************** *** 1709,1714 **** --- 1709,1732 ---- return NULL; } + + static char_u * + set_context_in_scriptnames_cmd(expand_T *xp, char_u *arg) + { + char_u *p; + + xp->xp_context = EXPAND_NOTHING; + xp->xp_pattern = NULL; + + p = skipwhite(arg); + if (VIM_ISDIGIT(*p)) + return NULL; + + xp->xp_context = EXPAND_SCRIPTNAMES; + xp->xp_pattern = p; + + return NULL; + } #endif /* *************** *** 2072,2077 **** --- 2090,2098 ---- case CMD_profdel: case CMD_breakdel: return set_context_in_breakadd_cmd(xp, arg, cmdidx); + + case CMD_scriptnames: + return set_context_in_scriptnames_cmd(xp, arg); #endif default: *************** *** 2495,2500 **** --- 2516,2538 ---- } return NULL; } + + /* + * Function given to ExpandGeneric() to obtain the possible arguments for the + * ":scriptnames" command. + */ + static char_u * + get_scriptnames_arg(expand_T *xp UNUSED, int idx) + { + scriptitem_T *si; + + if (!SCRIPT_ID_VALID(idx + 1)) + return NULL; + + si = SCRIPT_ITEM(idx + 1); + home_replace(NULL, si->sn_name, NameBuff, MAXPATHL, TRUE); + return NameBuff; + } #endif /* *************** *** 2584,2589 **** --- 2622,2628 ---- {EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE}, #ifdef FEAT_EVAL {EXPAND_BREAKPOINT, get_breakadd_arg, TRUE, TRUE}, + {EXPAND_SCRIPTNAMES, get_scriptnames_arg, TRUE, FALSE}, #endif }; int i; *************** *** 2791,2796 **** --- 2830,2837 ---- int score = 0; int fuzzy; int match; + int sort_matches = FALSE; + int funcsort = FALSE; fuzzy = cmdline_fuzzy_complete(pat); *matches = NULL; *************** *** 2878,2891 **** if (ga.ga_len == 0) return OK; ! // Sort the results. Keep menu's in the specified order. if (!fuzzy && xp->xp_context != EXPAND_MENUNAMES ! && xp->xp_context != EXPAND_MENUS) { ! if (xp->xp_context == EXPAND_EXPRESSION ! || xp->xp_context == EXPAND_FUNCTIONS ! || xp->xp_context == EXPAND_USER_FUNC ! || xp->xp_context == EXPAND_DISASSEMBLE) // functions should be sorted to the end. qsort((void *)ga.ga_data, (size_t)ga.ga_len, sizeof(char_u *), sort_func_compare); --- 2919,2943 ---- if (ga.ga_len == 0) return OK; ! // sort the matches when using regular expression matching and sorting ! // applies to the completion context. Menus and scriptnames should be kept ! // in the specified order. if (!fuzzy && xp->xp_context != EXPAND_MENUNAMES ! && xp->xp_context != EXPAND_MENUS ! && xp->xp_context != EXPAND_SCRIPTNAMES) ! sort_matches = TRUE; ! ! // functions should be sorted to the end. ! if (xp->xp_context == EXPAND_EXPRESSION ! || xp->xp_context == EXPAND_FUNCTIONS ! || xp->xp_context == EXPAND_USER_FUNC ! || xp->xp_context == EXPAND_DISASSEMBLE) ! funcsort = TRUE; ! ! // Sort the matches. ! if (sort_matches) { ! if (funcsort) // functions should be sorted to the end. qsort((void *)ga.ga_data, (size_t)ga.ga_len, sizeof(char_u *), sort_func_compare); *************** *** 2900,2914 **** } else { - int funcsort = FALSE; - - if (xp->xp_context == EXPAND_EXPRESSION - || xp->xp_context == EXPAND_FUNCTIONS - || xp->xp_context == EXPAND_USER_FUNC - || xp->xp_context == EXPAND_DISASSEMBLE) - // functions should be sorted to the end. - funcsort = TRUE; - if (fuzzymatches_to_strmatches(ga.ga_data, matches, ga.ga_len, funcsort) == FAIL) return FAIL; --- 2952,2957 ---- *** ../vim-8.2.4616/src/ex_cmds.h 2022-03-19 12:56:42.529503830 +0000 --- src/ex_cmds.h 2022-03-24 10:36:11.210130525 +0000 *************** *** 1356,1362 **** EX_CMDARG|EX_TRLBAR, ADDR_NONE), EXCMD(CMD_scriptnames, "scriptnames", ex_scriptnames, ! EX_BANG|EX_RANGE|EX_COUNT|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, ADDR_OTHER), EXCMD(CMD_scriptencoding, "scriptencoding", ex_scriptencoding, EX_WORD1|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, --- 1356,1362 ---- EX_CMDARG|EX_TRLBAR, ADDR_NONE), EXCMD(CMD_scriptnames, "scriptnames", ex_scriptnames, ! EX_BANG|EX_FILES|EX_RANGE|EX_COUNT|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, ADDR_OTHER), EXCMD(CMD_scriptencoding, "scriptencoding", ex_scriptencoding, EX_WORD1|EX_TRLBAR|EX_CMDWIN|EX_LOCK_OK, *** ../vim-8.2.4616/src/scriptfile.c 2022-03-22 12:13:49.147376718 +0000 --- src/scriptfile.c 2022-03-24 10:36:11.210130525 +0000 *************** *** 1769,1782 **** { int i; ! if (eap->addr_count > 0) { // :script {scriptId}: edit the script ! if (!SCRIPT_ID_VALID(eap->line2)) emsg(_(e_invalid_argument)); else { ! eap->arg = SCRIPT_ITEM(eap->line2)->sn_name; do_exedit(eap, NULL); } return; --- 1769,1788 ---- { int i; ! if (eap->addr_count > 0 || *eap->arg != NUL) { // :script {scriptId}: edit the script ! if (eap->addr_count > 0 && !SCRIPT_ID_VALID(eap->line2)) emsg(_(e_invalid_argument)); else { ! if (eap->addr_count > 0) ! eap->arg = SCRIPT_ITEM(eap->line2)->sn_name; ! else ! { ! expand_env(eap->arg, NameBuff, MAXPATHL); ! eap->arg = NameBuff; ! } do_exedit(eap, NULL); } return; *** ../vim-8.2.4616/src/usercmd.c 2022-03-23 21:36:23.713441139 +0000 --- src/usercmd.c 2022-03-24 10:36:11.214130515 +0000 *************** *** 93,98 **** --- 93,99 ---- {EXPAND_USER_VARS, "var"}, #if defined(FEAT_EVAL) {EXPAND_BREAKPOINT, "breakpoint"}, + {EXPAND_SCRIPTNAMES, "scriptnames"}, #endif {0, NULL} }; *** ../vim-8.2.4616/src/vim.h 2022-03-16 13:33:22.078467971 +0000 --- src/vim.h 2022-03-24 10:36:11.214130515 +0000 *************** *** 802,807 **** --- 802,808 ---- #define EXPAND_DIFF_BUFFERS 49 #define EXPAND_DISASSEMBLE 50 #define EXPAND_BREAKPOINT 51 + #define EXPAND_SCRIPTNAMES 52 // Values for exmode_active (0 is no exmode) #define EXMODE_NORMAL 1 *** ../vim-8.2.4616/src/testdir/test_cmdline.vim 2022-03-22 16:06:24.946137125 +0000 --- src/testdir/test_cmdline.vim 2022-03-24 10:36:11.210130525 +0000 *************** *** 3257,3260 **** --- 3257,3287 ---- call assert_equal("\"breakdel here ", @:) endfunc + " Test for :scriptnames argument completion + func Test_cmdline_complete_scriptnames() + set wildmenu + call writefile(['let a = 1'], 'Xa1b2c3.vim') + source Xa1b2c3.vim + call feedkeys(":script \\\\\"\", 'tx') + call assert_match("\"script .*Xa1b2c3.vim$", @:) + call feedkeys(":script \\\\\"\", 'tx') + call assert_match("\"script .*Xa1b2c3.vim$", @:) + call feedkeys(":script b2c3\\\"\", 'tx') + call assert_equal("\"script b2c3", @:) + call feedkeys(":script 2\\\"\", 'tx') + call assert_match("\"script 2\$", @:) + call feedkeys(":script \\\ \\\"\", 'tx') + call assert_match("\"script .*Xa1b2c3.vim $", @:) + call feedkeys(":script \\\\"\", 'tx') + call assert_equal("\"script ", @:) + call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0]) + call assert_equal([], getcompletion('Xa1b2', 'scriptnames')) + new + call feedkeys(":script \\\\", 'tx') + call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t')) + bw! + call delete('Xa1b2c3.vim') + set wildmenu& + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.4616/src/testdir/test_quickfix.vim 2022-02-26 10:31:24.699882028 +0000 --- src/testdir/test_quickfix.vim 2022-03-24 10:36:11.214130515 +0000 *************** *** 6202,6205 **** --- 6202,6240 ---- %bw! endfunc + " Test for the status message that is displayed when opening a new quickfix + " list + func Test_qflist_statusmsg() + cexpr "1\n2" + cexpr "1\n2\n3\ntest_quickfix.vim:1:msg" + call assert_equal('(4 of 4): msg', v:statusmsg) + call setqflist([], 'f') + %bw! + + " When creating a new quickfix list, if an autocmd changes the quickfix list + " in the stack, then an error message should be displayed. + augroup QF_Test + au! + au BufEnter test_quickfix.vim colder + augroup END + cexpr "1\n2" + call assert_fails('cexpr "1\n2\n3\ntest_quickfix.vim:1:msg"', 'E925:') + call setqflist([], 'f') + augroup QF_Test + au! + augroup END + %bw! + + augroup QF_Test + au! + au BufEnter test_quickfix.vim caddexpr "4" + augroup END + call assert_fails('cexpr "1\n2\n3\ntest_quickfix.vim:1:msg"', 'E925:') + call setqflist([], 'f') + augroup QF_Test + au! + augroup END + %bw! + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.4616/src/version.c 2022-03-23 21:36:23.713441139 +0000 --- src/version.c 2022-03-24 10:38:06.773796826 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4617, /**/ -- This is the polymorph virus! Follow these instructions carefully: 1. Send this message to everybody you know. 2. Format your harddisk. Thank you for your cooperation in spreading the most powerful virus ever! /// 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 ///