Dominique Pellé wrote: > Please try and review the attached patch. > It think it does what's needed and it's rather simple: > > :setfiletype completes using things that match > $VIMRUNTIME/{syntax,ftplugin,indent}/*.vim and > ~/.vim/{syntax,ftplugin,indent}/*.vim > > :ownsyntax behaves as before, i.e. it completes using things that > match $VIMRUNTIME/syntax/*.vim and ~/.vim/syntax/*.vim > > You can verify that :ownsyntax and :setfiletype complete > differently with this example: > > :setfiletype host<CTRL-D> > hostconf hostsaccess > > :ownsyntax host<CTRL-D> > hostconf > > I have not done anything about the special files such as > syntax/2html.vim. I could hard-code something to exclude > them but it'd be ugly. Hopefully we can consider moving > those special files.
I send this patch again with slightly more elegant way of doing it saving 3 lines of code. Sorry for the noise. -- Dominique -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
diff -r da067045878f src/ex_docmd.c --- a/src/ex_docmd.c Tue Jul 27 20:47:25 2010 +0200 +++ b/src/ex_docmd.c Wed Jul 28 00:01:06 2010 +0200 @@ -3831,8 +3831,12 @@ xp->xp_pattern = arg; break; + case CMD_ownsyntax: + xp->xp_context = EXPAND_OWNSYNTAX; + xp->xp_pattern = arg; + break; + case CMD_setfiletype: - case CMD_ownsyntax: xp->xp_context = EXPAND_FILETYPE; xp->xp_pattern = arg; break; diff -r da067045878f src/ex_getln.c --- a/src/ex_getln.c Tue Jul 27 20:47:25 2010 +0200 +++ b/src/ex_getln.c Wed Jul 28 00:01:06 2010 +0200 @@ -4116,6 +4116,7 @@ if (context == EXPAND_HELP || context == EXPAND_COLORS || context == EXPAND_COMPILER + || context == EXPAND_OWNSYNTAX || context == EXPAND_FILETYPE || (context == EXPAND_TAGS && fname[0] == '/')) retval = vim_strnsave(fname, len); @@ -4502,8 +4503,10 @@ return ExpandRTDir(pat, num_file, file, "colors"); if (xp->xp_context == EXPAND_COMPILER) return ExpandRTDir(pat, num_file, file, "compiler"); + if (xp->xp_context == EXPAND_OWNSYNTAX) + return ExpandRTDir(pat, num_file, file, "syntax"); if (xp->xp_context == EXPAND_FILETYPE) - return ExpandRTDir(pat, num_file, file, "syntax"); + return ExpandRTDir(pat, num_file, file, "{syntax,indent,ftplugin}"); # if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) if (xp->xp_context == EXPAND_USER_LIST) return ExpandUserList(xp, num_file, file); @@ -4942,28 +4945,39 @@ } #endif +/* Used in qsort */ +static int cmp_str(s1, s2) + const void *s1; + const void *s2; +{ + return STRCMP(*(char_u **)s1, *(char_u **)s2); +} + /* * Expand color scheme, compiler or filetype names: - * 'runtimepath'/{dirname}/{pat}.vim + * 'runtimepath'/{dirnames}/{pat}.vim + * dirnames may contain one directory (ex: "colorscheme") or can be a glob + * expression matching multiple directories (ex: "{syntax,ftplugin,indent}"). */ static int -ExpandRTDir(pat, num_file, file, dirname) +ExpandRTDir(pat, num_file, file, dirnames) char_u *pat; int *num_file; char_u ***file; - char *dirname; /* "colors", "compiler" or "syntax" */ + char *dirnames; /* "colors", "compiler" or "syntax" */ { char_u *all; char_u *s; char_u *e; garray_T ga; + int i; *num_file = 0; *file = NULL; - s = alloc((unsigned)(STRLEN(pat) + STRLEN(dirname) + 7)); + s = alloc((unsigned)(STRLEN(pat) + STRLEN(dirnames) + 7)); if (s == NULL) return FAIL; - sprintf((char *)s, "%s/%s*.vim", dirname, pat); + sprintf((char *)s, "%s/%s*.vim", dirnames, pat); all = globpath(p_rtp, s, 0); vim_free(s); if (all == NULL) @@ -4993,6 +5007,26 @@ vim_free(all); *file = ga.ga_data; *num_file = ga.ga_len; + + if (*num_file > 1) + { + /* Sort and remove dupes which can happen when specifying multiple + * directories in dirnames such as "{syntax,ftplugin,indent}" + */ + qsort(*file, *num_file, sizeof(char_u *), cmp_str); + for (i = *num_file - 1; i > 0; i--) + { + if (STRCMP((*file)[i - 1], (*file)[i]) == 0) + { + /* Remove dupe (*file)[i] */ + vim_free((*file)[i]); + if (*num_file - i - 1 > 0) + mch_memmove(&(*file)[i], &(*file)[i + 1], + (*num_file - i - 1)*sizeof(char *)); + --*num_file; + } + } + } return OK; } diff -r da067045878f src/vim.h --- a/src/vim.h Tue Jul 27 20:47:25 2010 +0200 +++ b/src/vim.h Wed Jul 28 00:01:06 2010 +0200 @@ -774,7 +774,8 @@ #define EXPAND_PROFILE 35 #define EXPAND_BEHAVE 36 #define EXPAND_FILETYPE 37 -#define EXPAND_FILES_IN_PATH 38 +#define EXPAND_FILES_IN_PATH 38 +#define EXPAND_OWNSYNTAX 39 /* Values for exmode_active (0 is no exmode) */ #define EXMODE_NORMAL 1