Bram Moolenaar wrote:
> Dominique Pelle wrote:
>
>> Peter Odding wrote:
>>
>> > Ingo Karkat wrote:
>> >>
>> >> Granted, most filetypes do define custom highlighting via a
>> >> $VIMRUNTIME/syntax/<filetype>.vim script. But shouldn't the filetype
>> >> completion
>> >> also take into account files from the ftplugin and syntax directories,
>> >> too?
>> >> If I for example have a custom filetype "bullettext" that defines custom
>> >> fold
>> >> and indent settings, but no highlighting, I would expect to have this
>> >> filetype
>> >> included in the completion.
>> >
>> > Like Ingo I have several custom file types under my ~/.vim/ directory that
>> > don't have an associated syntax script and visa versa.
>> >
>> > Bram Molenaar wrote:
>> >>
>> >> Aha, so the filetypes are found by looking in the syntax directory.
>> >> Well, the result is still a list of filetypes, although there can be a
>> >> few syntax files that are not a filetype (e.g. 2html.vim). So do we let
>> >> the implementation details prevail? Or stick to the intention?
>> >
>> > If sticking to the intention doesn't involve too much code that would IMHO
>> > be preferable to the current implementation because of the reason given
>> > above.
>> >
>> > Ideally file type completion would consider the base filenames of the Vim
>> > scripts in the system wide / user specific ftplugin / syntax / indent
>> > directories (and also their /after/ variants) but this might be too
>> > complex?
>>
>> I can try to change the behavior. But just to make sure I understand
>> the problems:
>>
>> :setfiletype and :ownsyntax commands currently both perform
>> completion by looking at syntax/*.vim from both $VIMRUNTIME
>> and ~/.vim/.
>>
>> That's almost fine, but it not ideal for 2 reasons:
>>
>> 1/ :setfiletype should actually complete by looking at files matching
>> {syntax,ftplugin,indent}/*.vim from both $VIMRUNTIME/ and ~/.vim/
>> :ownsyntax completion should only look at syntax/*.vim (as it does now).
>>
>> 2/ there are a few files matching syntax/*.vim which are not syntax
>> files such as 2html.vim, syntax.vim, colortest.vim... They can thus
>> show up as a spurious completion results. These special files are
>> listed in syntax/README.txt. Any reasons for them to be in the
>> syntax/ directory?
>
> Historic reasons. I think it's not much of a problem, one would simply
> not select these as the desired filetype. Moving them elsewhere will
> break scripts.
>
>> In practice, current implementation is almost fine since almost
>> all files matching $VIMRUNTIME/{ftplugin,indent}/*.vim have a
>> corresponding file matching $VIMRUNTIME/syntax/*.vim. Using
>> the following commands...
>>
>> $ cd /usr/local/share/vim/vim73c
>> $ vim -d <(cd syntax/; ls *.vim) <(cd ftplugin/; ls *.vim)
>> $ vim -d <(cd syntax/; ls *.vim) <(cd indent/; ls *.vim)
>>
>> ... I see only 3 files matching ftplugin/*.vim which do not correspond
>> to any file syntax/*.vim
>>
>> - ftplugin/hostaccess.vim
>> - ftplugin/quickfix.vim
>> - ftplugin/AppendMatchGroup.vim: this file does not look
>> like a file type plugin anyway. It appears to contain a helper
>> function. Should it really be there?
>
> That should be an autoload script. I don't think that was possible when
> it was written. I'll ping the author, but it's been a long time.
>
>> And 1 file matching index/*.vim which has no corresponding files
>> matching syntax/*.vim:
>>
>> - indent/GenericIndent.vim: this file is not an indent file but
>> contains helper functions. Should it be stored somewhere else?
>
> It's from the same author.
>
>> I don't think this is a blocker for the release but Bram can decide :-)
>
> I think that users will be disappointed when the filetype they were
> looking for does not show up in completion. It's not so bad if a few
> more choices pop up, a user can simply skip over them.
>
> We need to keep performance in mind, completion is being done
> interactive. But the syntax directory is the biggest one, adding indent
> and ftplugin can't make it more than twice as slow. Hopefully.
>
> Following these arguments we should add the indent and ftplugin
> directories. And make sure duplicates are removed.
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.
Regards
-- 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 Tue Jul 27 23:22:01 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 Tue Jul 27 23:22:01 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,40 @@
}
#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
*/
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) + 9));
if (s == NULL)
return FAIL;
- sprintf((char *)s, "%s/%s*.vim", dirname, pat);
+ if (vim_strchr((char_u *)dirnames, ',') == NULL)
+ sprintf((char *)s, "%s/%s*.vim", dirnames, pat);
+ else
+ sprintf((char *)s, "{%s}/%s*.vim", dirnames, pat);
all = globpath(p_rtp, s, 0);
vim_free(s);
if (all == NULL)
@@ -4993,6 +5008,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 Tue Jul 27 23:22:01 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