aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/runtime.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-01-26 09:44:15 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-01-26 11:55:32 +0800
commit6644786db078e019426f90cf85da50e3fa1b6a67 (patch)
treead044561cd9b9c336ade9661f54e18fcbd9f7e46 /src/nvim/runtime.c
parent5ac34cf55db2b00c044fa95f75766dd89dd36ba9 (diff)
downloadrneovim-6644786db078e019426f90cf85da50e3fa1b6a67.tar.gz
rneovim-6644786db078e019426f90cf85da50e3fa1b6a67.tar.bz2
rneovim-6644786db078e019426f90cf85da50e3fa1b6a67.zip
vim-patch:9.0.1227: no cmdline completion for :runtime
Problem: No cmdline completion for :runtime. Solution: Add completion for :runtime. (closes vim/vim#11853, closes vim/vim#11447) Improve the resulting matches. https://github.com/vim/vim/commit/a6759381a590b2d395e05b109ca9ccfc356be5a8
Diffstat (limited to 'src/nvim/runtime.c')
-rw-r--r--src/nvim/runtime.c70
1 files changed, 58 insertions, 12 deletions
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index 24500b80b9..068a43c790 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -1194,11 +1194,22 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
// TODO(bfredl): this is bullshit, expandpath should not reinvent path logic.
for (int i = 0; dirnames[i] != NULL; i++) {
- size_t size = strlen(dirnames[i]) + pat_len + 16;
- char *s = xmalloc(size);
- snprintf(s, size, "%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat);
- globpath(p_rtp, s, &ga, 0);
- xfree(s);
+ size_t size = strlen(dirnames[i]) + pat_len * 2 + 26;
+ char *buf = xmalloc(size);
+ if (*dirnames[i] == NUL) {
+ // empty dir used for :runtime
+ if (path_tail(pat) == pat) {
+ // no path separator, match dir names and script files
+ snprintf(buf, size, "\\(%s*.\\(vim\\|lua\\)\\)\\|\\(%s*\\)", pat, pat);
+ } else {
+ // has path separator, match script files
+ snprintf(buf, size, "%s*.vim", pat);
+ }
+ } else {
+ snprintf(buf, size, "%s/%s*.\\(vim\\|lua\\)", dirnames[i], pat);
+ }
+ globpath(p_rtp, buf, &ga, 0);
+ xfree(buf);
}
if (flags & DIP_START) {
@@ -1241,18 +1252,53 @@ int ExpandRTDir(char *pat, int flags, int *num_file, char ***file, char *dirname
char *match = ((char **)ga.ga_data)[i];
char *s = match;
char *e = s + strlen(s);
+ char *res_start = s;
+ if ((flags & DIP_PRNEXT) != 0) {
+ char *p = strstr(match, 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 - s > 4 && (STRNICMP(e - 4, ".vim", 4) == 0
|| STRNICMP(e - 4, ".lua", 4) == 0)) {
- e -= 4;
- for (s = e; s > match; MB_PTR_BACK(match, s)) {
- if (vim_ispathsep(*s)) {
- break;
+ 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;
+ }
}
}
- s++;
+
*e = NUL;
- assert((e - s) + 1 >= 0);
- memmove(match, s, (size_t)(e - s) + 1);
+ }
+
+ if (res_start > match) {
+ assert((e - res_start) + 1 >= 0);
+ memmove(match, res_start, (size_t)(e - res_start) + 1);
+ }
+
+ // remove entries that look like backup files
+ if (e > s && e[-1] == '~') {
+ xfree(match);
+ char **fnames = (char **)ga.ga_data;
+ for (int j = i + 1; j < ga.ga_len; ++j) {
+ fnames[j - 1] = fnames[j];
+ }
+ ga.ga_len--;
+ i--;
}
}