To: vim_dev@googlegroups.com Subject: Patch 9.0.1227 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1227 Problem: No cmdline completion for :runtime. Solution: Add completion for :runtime. (closes #11853, closes #11447) Improve the resulting matches. Files: src/cmdexpand.c, src/scriptfile.c, src/usercmd.c, src/vim.h, src/testdir/test_cmdline.vim *** ../vim-9.0.1226/src/cmdexpand.c 2023-01-09 19:04:19.300528373 +0000 --- src/cmdexpand.c 2023-01-21 20:54:07.182607048 +0000 *************** *** 56,61 **** --- 56,62 ---- && xp->xp_context != EXPAND_OLD_SETTING && xp->xp_context != EXPAND_OWNSYNTAX && xp->xp_context != EXPAND_PACKADD + && xp->xp_context != EXPAND_RUNTIME && xp->xp_context != EXPAND_SHELLCMD && xp->xp_context != EXPAND_TAGS && xp->xp_context != EXPAND_TAGS_LISTFILES *************** *** 1362,1367 **** --- 1363,1369 ---- // For a tag pattern starting with "/" no translation is needed. if (context == EXPAND_HELP || context == EXPAND_COLORS + || context == EXPAND_RUNTIME || context == EXPAND_COMPILER || context == EXPAND_OWNSYNTAX || context == EXPAND_FILETYPE *************** *** 2312,2317 **** --- 2314,2324 ---- xp->xp_pattern = arg; break; + case CMD_runtime: + xp->xp_context = EXPAND_RUNTIME; + xp->xp_pattern = arg; + break; + case CMD_compiler: xp->xp_context = EXPAND_COMPILER; xp->xp_pattern = arg; *************** *** 3019,3024 **** --- 3026,3037 ---- return ExpandRTDir(pat, DIP_START + DIP_OPT, numMatches, matches, directories); } + if (xp->xp_context == EXPAND_RUNTIME) + { + char *directories[] = {"", NULL}; + return ExpandRTDir(pat, DIP_START + DIP_OPT + DIP_PRNEXT, numMatches, + matches, directories); + } if (xp->xp_context == EXPAND_COMPILER) { char *directories[] = {"compiler", NULL}; *** ../vim-9.0.1226/src/scriptfile.c 2023-01-02 13:41:45.296274394 +0000 --- src/scriptfile.c 2023-01-21 21:50:44.478085840 +0000 *************** *** 990,1007 **** for (i = 0; dirnames[i] != NULL; ++i) { ! s = alloc(STRLEN(dirnames[i]) + pat_len + 7); ! if (s == NULL) { ga_clear_strings(&ga); return FAIL; } ! sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat); ! globpath(p_rtp, s, &ga, 0); ! vim_free(s); } ! if (flags & DIP_START) { for (i = 0; dirnames[i] != NULL; ++i) { s = alloc(STRLEN(dirnames[i]) + pat_len + 22); --- 990,1023 ---- for (i = 0; dirnames[i] != NULL; ++i) { ! size_t buflen = STRLEN(dirnames[i]) + pat_len * 2 + 17; ! char_u *buf = alloc(buflen); ! if (buf == NULL) { ga_clear_strings(&ga); return FAIL; } ! if (*(dirnames[i]) == NUL) ! { ! // empty dir used for :runtime ! if (gettail(pat) == pat) ! // no path separator, match dir names and script files ! vim_snprintf((char *)buf, buflen, "\\(%s*.vim\\)\\|\\(%s*\\)", ! pat, pat); ! else ! // has path separator, match script files ! vim_snprintf((char *)buf, buflen, "%s*.vim", pat); ! } ! else ! { ! vim_snprintf((char *)buf, buflen, "%s/%s*.vim", dirnames[i], pat); ! } ! globpath(p_rtp, buf, &ga, 0); ! vim_free(buf); } ! if (flags & DIP_START) ! { for (i = 0; dirnames[i] != NULL; ++i) { s = alloc(STRLEN(dirnames[i]) + pat_len + 22); *************** *** 1016,1022 **** } } ! if (flags & DIP_OPT) { for (i = 0; dirnames[i] != NULL; ++i) { s = alloc(STRLEN(dirnames[i]) + pat_len + 20); --- 1032,1039 ---- } } ! if (flags & DIP_OPT) ! { for (i = 0; dirnames[i] != NULL; ++i) { s = alloc(STRLEN(dirnames[i]) + pat_len + 20); *************** *** 1036,1050 **** match = ((char_u **)ga.ga_data)[i]; s = match; e = s + STRLEN(s); if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) { ! e -= 4; ! for (s = e; s > match; MB_PTR_BACK(match, s)) ! if (s < match || vim_ispathsep(*s)) ! break; ! ++s; *e = NUL; ! mch_memmove(match, s, e - s + 1); } } --- 1053,1104 ---- match = ((char_u **)ga.ga_data)[i]; s = match; e = s + STRLEN(s); + char_u *res_start = s; + if ((flags & DIP_PRNEXT) != 0) + { + char_u *p = (char_u *)strstr((char *)match, (char *)pat); + if (p != NULL) + // Drop what comes before "pat" in the match, so that for + // match "/long/path/syntax/cpp.vim" with pattern + // "syntax/cp" we only keep "syntax/cpp.vim". + res_start = p; + } + if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0) { ! if (res_start == s) ! { ! // Only keep the file name. ! // Remove file ext only if flag DIP_PRNEXT is not present. ! if ((flags & DIP_PRNEXT) == 0) ! e -= 4; ! for (s = e; s > match; MB_PTR_BACK(match, s)) ! { ! if (s < match) ! break; ! if (vim_ispathsep(*s)) ! { ! res_start = s + 1; ! break; ! } ! } ! } ! *e = NUL; ! } ! ! if (res_start > match) ! mch_memmove(match, res_start, e - res_start + 1); ! ! // remove entries that look like backup files ! if (e > s && e[-1] == '~') ! { ! vim_free(match); ! char_u **fnames = (char_u **)ga.ga_data; ! for (int j = i + 1; j < ga.ga_len; ++j) ! fnames[j - 1] = fnames[j]; ! --ga.ga_len; ! --i; } } *** ../vim-9.0.1226/src/usercmd.c 2022-12-19 16:49:23.886882904 +0000 --- src/usercmd.c 2023-01-21 20:51:00.394563626 +0000 *************** *** 86,91 **** --- 86,92 ---- #endif {EXPAND_SETTINGS, "option"}, {EXPAND_PACKADD, "packadd"}, + {EXPAND_RUNTIME, "runtime"}, {EXPAND_SHELLCMD, "shellcmd"}, #if defined(FEAT_SIGNS) {EXPAND_SIGN, "sign"}, *** ../vim-9.0.1226/src/vim.h 2023-01-14 21:07:03.998952303 +0000 --- src/vim.h 2023-01-21 20:51:00.394563626 +0000 *************** *** 811,816 **** --- 811,817 ---- #define EXPAND_DISASSEMBLE 50 #define EXPAND_BREAKPOINT 51 #define EXPAND_SCRIPTNAMES 52 + #define EXPAND_RUNTIME 53 // Values for exmode_active (0 is no exmode) #define EXMODE_NORMAL 1 *************** *** 2661,2666 **** --- 2662,2668 ---- #define DIP_NORTP 0x20 // do not use 'runtimepath' #define DIP_NOAFTER 0x40 // skip "after" directories #define DIP_AFTER 0x80 // only use "after" directories + #define DIP_PRNEXT 0x100 // for print also file extension // Lowest number used for window ID. Cannot have this many windows. #define LOWEST_WIN_ID 1000 *** ../vim-9.0.1226/src/testdir/test_cmdline.vim 2023-01-18 15:27:35.128167521 +0000 --- src/testdir/test_cmdline.vim 2023-01-21 21:53:41.330033254 +0000 *************** *** 552,557 **** --- 552,566 ---- call assert_true(index(l, '') >= 0) let l = getcompletion('not', 'mapclear') call assert_equal([], l) + + let l = getcompletion('', 'runtime') + call assert_true(index(l, 'defaults.vim') >= 0) + let l = getcompletion('synt', 'runtime') + call assert_true(index(l, 'syntax') >= 0) + let l = getcompletion('syntax/vi', 'runtime') + call assert_true(index(l, 'syntax/vim.vim') >= 0) + let l = getcompletion('notexitsts', 'runtime') + call assert_equal([], l) let l = getcompletion('.', 'shellcmd') call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"')) *** ../vim-9.0.1226/src/version.c 2023-01-21 15:54:40.426545808 +0000 --- src/version.c 2023-01-21 20:52:59.470589963 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1227, /**/ -- hundred-and-one symptoms of being an internet addict: 35. Your husband tells you he's had that beard for 2 months. /// 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 ///