Re: added completion to the :setfiletype command.

2010-07-29 Fir de Conversatie François Ingelrest
Hi,

2010/7/28 Dominique Pellé:
 I'm sorry, I messed up again and forgot one file in the patch :-(
 Here it is again.

This new feature is great! It's easier and a bit faster to have
completion at hand when setting the file type.

One (maybe silly) question though: Isn't it possible to use completion
also with :set ft= ? It's not that I can't use :setf, just that
I'm used to the former and thought that the patch wasn't working at
first.

-- 
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


Re: added completion to the :setfiletype command.

2010-07-29 Fir de Conversatie Jürgen Krämer

Hi,

François Ingelrest wrote:
 
 One (maybe silly) question though: Isn't it possible to use completion
 also with :set ft= ? It's not that I can't use :setf, just that
 I'm used to the former and thought that the patch wasn't working at
 first.

that would make :set ft= behave differently from other options. Normally

  :set option=tab

completes with the current value of option.

Regards,
Jürgen

-- 
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)

-- 
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


Re: added completion to the :setfiletype command.

2010-07-29 Fir de Conversatie Benjamin R. Haskell
On Thu, 29 Jul 2010, Jürgen Krämer wrote:

 
 Hi,
 
 François Ingelrest wrote:
  
  One (maybe silly) question though: Isn't it possible to use 
  completion also with :set ft= ? It's not that I can't use :setf, 
  just that I'm used to the former and thought that the patch wasn't 
  working at first.
 
 that would make :set ft= behave differently from other options. Normally
 
   :set option=tab
 
 completes with the current value of option.

I encountered the same initial surprise as François.  Not a Vim73 
proposal, but could this be changed?  For free-form options, the current 
behavior makes sense.  For options with limited choices, though, it'd be 
nice to know the valid ones.

(...on the other hand, I'm a bit of a tabaholic as a Zsh user.)

-- 
Best,
Ben

-- 
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


Re: added completion to the :setfiletype command.

2010-07-29 Fir de Conversatie Bram Moolenaar

Dominique Pellé wrote:

  Here is the updated patch taking into account Nazri's comments.
  Using fnamecmp() is fine indeed after rethinking about it.
 
 I'm sorry, I messed up again and forgot one file in the patch :-(
 Here it is again.

Thanks, I'll include it now.

Please make any further patches on top of this one.

-- 
ARTHUR:... and I am your king 
OLD WOMAN: Ooooh!  I didn't know we had a king.  I thought we were an
   autonomous collective ...
 Monty Python and the Holy Grail PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
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


Re: added completion to the :setfiletype command.

2010-07-28 Fir de Conversatie Bram Moolenaar

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 hostCTRL-D
  hostconf hostsaccess
 
  :ownsyntax hostCTRL-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.

Thanks.

I'll await the updated version that re-uses the function to remove
duplicates.

Using fnamecmp() or STRCMP(): fnamecmp() should work the same or
slightly better.  E.g. if there is an indent/perl.vim and
syntax/Perl.vim it should end up only in perl.  But only on systems
where case is ignored.  That's about correct, it matches the way Vim
will find and read the file from the filetype.  Another solution would
be to lower case the name always, as filetypes are supposed to be lower
case.

-- 
How come wrong numbers are never busy?

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
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


Re: added completion to the :setfiletype command.

2010-07-28 Fir de Conversatie Ingo Karkat
On 28-Jul-2010 00:03, Dominique Pellé wrote:
 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 hostCTRL-D
 hostconf hostsaccess

 :ownsyntax hostCTRL-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

Sorry, I haven't tried your patch yet, only reviewed it. I'd like to point out
the naming peculiarities for ftplugins (:help ftplugin-name), which I think
require additional filtering of the retrieved *.vim names:

| The generic names for the filetype plugins are:
|
|   ftplugin/filetype.vim
|   ftplugin/filetype_name.vim
|   ftplugin/filetype/name.vim

Therefore, ftplugin (this doesn't seem to apply to syntax and indent scripts)
file names containing an underscore should be filtered from the list of
filenames, to avoid that those filetype_name names appear in the completion
list. For example, I use vim_ingoabb.vim to define my own abbreviations for the
Vim filetype.
I think it is okay to filter out the filetype_name.vim and ignore the
filetype/name.vim files, though it would be more correct to consider them,
too. Those alternative ways are meant for additions to the main filetype.vim
file, so only considering the main file should yield all installed filetypes,
anyway.

I'm sorry if this makes the implementation more complex, but I think these
spurious filetypes shouldn't be included.


 + return ExpandRTDir(pat, num_file, file, {syntax,indent,ftplugin});

Have you tested this on Windows? If I execute
:echo globpath(rtp, '{syntax,indent,ftplugin}/*.vim')
nothing is returned on Windows. :help wildcards mentions:
|   Which wildcards are supported depends on the system.
Seems like the {a,b,c} is a Bash-ism that isn't available on Windows.

Please excuse me if nothing here actually applies to your patch; as I said, I
haven't been able to actually test it yet, but wanted to get this feedback out
to you while you're still fiddling with it.

-- regards, ingo

-- 
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


Re: added completion to the :setfiletype command.

2010-07-28 Fir de Conversatie Matt Wozniski
On Wed, Jul 28, 2010 at 9:20 AM, Ingo Karkat sw...@ingo-karkat.de wrote:
 Sorry, I haven't tried your patch yet, only reviewed it. I'd like to point out
 the naming peculiarities for ftplugins (:help ftplugin-name), which I think
 require additional filtering of the retrieved *.vim names:

 | The generic names for the filetype plugins are:
 |
 |       ftplugin/filetype.vim
 |       ftplugin/filetype_name.vim
 |       ftplugin/filetype/name.vim

Yeah, I was about to point this out.  Really, since the goal is to get
a list of all possible filetype, we should include any directory in
ftplugin, and we should remove everything after an _ from the
filenames.  I definitely don't think we should just filter out files
with an _ in the name.

~Matt

-- 
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


Re: added completion to the :setfiletype command.

2010-07-28 Fir de Conversatie Dominique Pellé
2010/7/28 Bram Moolenaar b...@moolenaar.net:

 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 hostCTRL-D
  hostconf     hostsaccess
 
  :ownsyntax hostCTRL-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.

 Thanks.

 I'll await the updated version that re-uses the function to remove
 duplicates.

 Using fnamecmp() or STRCMP(): fnamecmp() should work the same or
 slightly better.  E.g. if there is an indent/perl.vim and
 syntax/Perl.vim it should end up only in perl.  But only on systems
 where case is ignored.  That's about correct, it matches the way Vim
 will find and read the file from the filetype.  Another solution would
 be to lower case the name always, as filetypes are supposed to be lower
 case.


Here is the updated patch taking into account Nazri's comments.
Using fnamecmp() is fine indeed after rethinking about it.

remove_duplicates() now also loops backwards to avoid moving
elements that would later be removed.

You can check that completion works with this example:

You can verify that :ownsyntax and :setfiletype complete
differently with this example:

  :setfiletype hostCTRL-D
  hostconf hostsaccess

  :ownsyntax hostCTRL-D
  hostconf

Still remains to be solved the problem of the few files such as
syntax/2html.vim which are not syntax or ftplugin files.
I'd prefer to move those special files somewhere else.  Is that OK?

Cheers
-- 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 33148c37f3c9 src/ex_getln.c
--- a/src/ex_getln.c	Wed Jul 28 19:38:16 2010 +0200
+++ b/src/ex_getln.c	Wed Jul 28 20:43:48 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);
@@ -4944,14 +4947,16 @@
 
 /*
  * 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;
 {
 char_u	*all;
 char_u	*s;
@@ -4960,10 +4965,10 @@
 
 *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)
@@ -4991,6 +4996,13 @@
 	++e;
 }
 vim_free(all);
+
+/* Sort and remove duplicates which can happen when specifying multiple
+ * directories in dirnames such as {syntax,ftplugin,indent}.
+ */
+sort_strings((char_u **)ga.ga_data, ga.ga_len);
+remove_duplicates(ga);
+
 *file = ga.ga_data;
 *num_file = ga.ga_len;
 return OK;
diff -r 33148c37f3c9 src/misc1.c
--- a/src/misc1.c	Wed Jul 28 19:38:16 2010 +0200
+++ b/src/misc1.c	Wed Jul 28 20:43:48 2010 +0200
@@ -9238,7 +9238,6 @@
 #if defined(FEAT_SEARCHPATH)
 static int find_previous_pathsep __ARGS((char_u *path, char_u **psep));
 static int is_unique __ARGS((char_u *maybe_unique, garray_T *gap, int i));
-static void 

Re: added completion to the :setfiletype command.

2010-07-28 Fir de Conversatie Dominique Pellé
Dominique Pellé wrote:

 Here is the updated patch taking into account Nazri's comments.
 Using fnamecmp() is fine indeed after rethinking about it.

I'm sorry, I messed up again and forgot one file in the patch :-(
Here it is again.

-- 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 33148c37f3c9 src/ex_docmd.c
--- a/src/ex_docmd.c	Wed Jul 28 19:38:16 2010 +0200
+++ b/src/ex_docmd.c	Wed Jul 28 22:10:16 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 33148c37f3c9 src/ex_getln.c
--- a/src/ex_getln.c	Wed Jul 28 19:38:16 2010 +0200
+++ b/src/ex_getln.c	Wed Jul 28 22:10:16 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);
@@ -4944,14 +4947,16 @@
 
 /*
  * 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;
 {
 char_u	*all;
 char_u	*s;
@@ -4960,10 +4965,10 @@
 
 *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)
@@ -4991,6 +4996,13 @@
 	++e;
 }
 vim_free(all);
+
+/* Sort and remove duplicates which can happen when specifying multiple
+ * directories in dirnames such as {syntax,ftplugin,indent}.
+ */
+sort_strings((char_u **)ga.ga_data, ga.ga_len);
+remove_duplicates(ga);
+
 *file = ga.ga_data;
 *num_file = ga.ga_len;
 return OK;
diff -r 33148c37f3c9 src/misc1.c
--- a/src/misc1.c	Wed Jul 28 19:38:16 2010 +0200
+++ b/src/misc1.c	Wed Jul 28 22:10:16 2010 +0200
@@ -9238,7 +9238,6 @@
 #if defined(FEAT_SEARCHPATH)
 static int find_previous_pathsep __ARGS((char_u *path, char_u **psep));
 static int is_unique __ARGS((char_u *maybe_unique, garray_T *gap, int i));
-static void remove_duplicates __ARGS((garray_T *gap));
 static void uniquefy_paths __ARGS((garray_T *gap, char_u *pattern));
 static int expand_in_path __ARGS((garray_T *gap, char_u	*pattern, int flags));
 
@@ -9308,29 +9307,6 @@
 }
 
 /*
- * Remove adjacent duplicate entries from gap, which is a list of file names
- * in allocated memory.
- */
-static void
-remove_duplicates(gap)
-garray_T *gap;
-{
-int	i;
-int	j;
-char_u  **fnames = (char_u **)gap-ga_data;
-
-for (i = 1; i  gap-ga_len; ++i)
-	if (fnamecmp(fnames[i - 1], fnames[i]) == 0)
-	{
-	vim_free(fnames[i]);
-	for (j = i + 1; j  gap-ga_len; ++j)
-		fnames[j - 1] = fnames[j];
-	--gap-ga_len;
-	--i;
-	}
-}
-
-/*
  * Sorts, removes duplicates and modifies all the fullpath names in gap so that
  * they are unique with respect to each other while conserving the part that
  * matches the pattern. Beware, this is at least O(n^2) wrt gap-ga_len.
@@ -9450,6 +9426,30 @@
 }
 #endif
 
+#if defined(FEAT_SEARCHPATH) || defined(FEAT_CMDL_COMPL) || defined(PROTO)
+/*
+ * Remove adjacent duplicate entries from gap, which is a list of file names
+ * in allocated memory.
+ */
+void
+remove_duplicates(gap)
+garray_T	*gap;
+{
+int	i;
+int	j;
+char_u  **fnames = (char_u **)gap-ga_data;
+
+for (i = gap-ga_len - 1; i  0; --i)
+	if (fnamecmp(fnames[i - 1], fnames[i]) == 0)
+	{
+	vim_free(fnames[i]);
+	for (j = i + 

Re: added completion to the :setfiletype command.

2010-07-28 Fir de Conversatie Bram Moolenaar

 2010/7/28 Bram Moolenaar b...@moolenaar.net:
 
  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 hostCTRL-D
   hostconf hostsaccess
  
   :ownsyntax hostCTRL-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.
 
  Thanks.
 
  I'll await the updated version that re-uses the function to remove
  duplicates.
 
  Using fnamecmp() or STRCMP(): fnamecmp() should work the same or
  slightly better.  E.g. if there is an indent/perl.vim and
  syntax/Perl.vim it should end up only in perl.  But only on systems
  where case is ignored.  That's about correct, it matches the way Vim
  will find and read the file from the filetype.  Another solution would
  be to lower case the name always, as filetypes are supposed to be lower
  case.
 
 
 Here is the updated patch taking into account Nazri's comments.
 Using fnamecmp() is fine indeed after rethinking about it.
 
 remove_duplicates() now also loops backwards to avoid moving
 elements that would later be removed.
 
 You can check that completion works with this example:
 
 You can verify that :ownsyntax and :setfiletype complete
 differently with this example:
 
   :setfiletype hostCTRL-D
   hostconf hostsaccess
 
   :ownsyntax hostCTRL-D
   hostconf
 
 Still remains to be solved the problem of the few files such as
 syntax/2html.vim which are not syntax or ftplugin files.
 I'd prefer to move those special files somewhere else.  Is that OK?

Sounds good.

-- 
CART DRIVER: Bring out your dead!
   There are legs stick out of windows and doors.  Two MEN are fighting in the
   mud - covered from head to foot in it.  Another MAN is on his hands in
   knees shovelling mud into his mouth.  We just catch sight of a MAN falling
   into a well.
 Monty Python and the Holy Grail PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
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


Re: added completion to the :setfiletype command.

2010-07-27 Fir de Conversatie Ingo Karkat
On 26-Jul-2010 23:29, Dominique Pellé wrote:
 The completion EXPAND_FILETYPE expands things from files
 located in $VIMRUNTIME/syntax/.

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.

 Maybe $VIMRUNTIME/syntax/ should have rather be called
 $VIMRUNTIME/filetype/ but this should not be changed anymore
 since it has been like this for a long time and changing name would
 break things.

As I understand it, there are three integration points: indent (obvious), syntax
(for highlighting) and ftplugin (other buffer settings). Though syntax seems to
be the most common one, I would prefer keeping that descriptive name.

-- regards, ingo

-- 
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


Re: [patch] added completion to the :setfiletype command.

2010-07-27 Fir de Conversatie Bram Moolenaar

Dominique Pelle wrote:

 Bram Moolenaar b...@moolenaar.net wrote:
 
  Christian Brabandt wrote:
 
  Hi Dominique!
 
  On Sa, 24 Jul 2010, Dominique Pellé wrote:
 
   Hi
  
   Attached patch adds completion to the :setfiletype command.
   Example:
  
   :setf javaCTRL-D
   javajavacc  javascript
  
   -- Dominique
  
 
   diff -r 0c8219a26bc9 src/ex_docmd.c
   --- a/src/ex_docmd.cSat Jul 24 20:57:44 2010 +0200
   +++ b/src/ex_docmd.cSat Jul 24 23:36:07 2010 +0200
   @@ -3829,6 +3829,7 @@
   xp-xp_pattern = arg;
   break;
  
   +   case CMD_setfiletype:
   case CMD_ownsyntax:
   xp-xp_context = EXPAND_FILETYPE;
   xp-xp_pattern = arg;
 
 
  Since we now have filetype completion, why not add this to the
  command-completion?
 
  chrisbra t41:~/vim/src [1157]% hg diff ex_docmd.c ../runtime/doc/map.txt
  diff -r 5bd81e397907 runtime/doc/map.txt
  --- a/runtime/doc/map.txt   Sun Jul 25 22:30:20 2010 +0200
  +++ b/runtime/doc/map.txt   Mon Jul 26 13:22:25 2010 +0200
  @@ -1215,6 +1215,7 @@
  -complete=mapping   mapping name
  -complete=menu  menus
  -complete=optionoptions
  +   -complete=syntaxsyntax
  -complete=tag   tags
  -complete=tag_listfiles tags, file names are shown when CTRL-D is 
  hit
  -complete=var   user variables
  diff -r 5bd81e397907 src/ex_docmd.c
  --- a/src/ex_docmd.cSun Jul 25 22:30:20 2010 +0200
  +++ b/src/ex_docmd.cMon Jul 26 13:22:25 2010 +0200
  @@ -5280,6 +5280,7 @@
   {EXPAND_MENUS, menu},
   {EXPAND_SETTINGS, option},
   {EXPAND_SHELLCMD, shellcmd},
  +{EXPAND_FILETYPE, syntax},
   #if defined(FEAT_SIGNS)
   {EXPAND_SIGN, sign},
   #endif
 
  If this is completing filetypes, why call it syntax?  I would find
  filetype less confusing.
 
  In the same way, we could also add compiler and colorscheme completion.
  Is that useful?
 
  Generally completion is useful.  Note that I'm not going to include new
  features now. But these tiny changes should be OK.
 
 
 I remember being a bit confused too with this when I wrote the patch.
 The completion EXPAND_FILETYPE expands things from files
 located in $VIMRUNTIME/syntax/.
 
 EXPAND_SYNTAX already existed but it's something completely
 different: it the expansion of the :syntax  command.
 
 Maybe $VIMRUNTIME/syntax/ should have rather be called
 $VIMRUNTIME/filetype/ but this should not be changed anymore
 since it has been like this for a long time and changing name would
 break things.

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?

-- 
Corn oil comes from corn and olive oil comes from olives, so where
does baby oil come from?

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
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


Re: added completion to the :setfiletype command.

2010-07-27 Fir de Conversatie Peter Odding

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?


 - Peter Odding

PS. Thanks Dominique and Christian for the patches you've posted, I've 
always been annoyed that :setfiletype doesn't support completion :-)


--
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


Re: [patch] added completion to the :setfiletype command.

2010-07-27 Fir de Conversatie Tony Mechelynck

On 27/07/10 09:44, Bram Moolenaar 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?



The scripts in syntax/ which are not filetypes constitute a closed list 
(IIUC: 2html, syncolor, synload and syntax), they could be excluded from 
the list.


OTOH, there might be a few filetypes with an ftplugin and/or an indent 
script but no syntax script. Are they worth the trouble of adding them 
to the list? (Taking care of duplicates could be done by a sort and 
uniquify after scanning all syntax etc. subdirs of all 'runtimepath' 
directories.)



Best regards,
Tony.
--
It is illegal for a driver to be blindfolded while operating a vehicle.
[real standing law in Alabama, United States of America]

--
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


Re: added completion to the :setfiletype command.

2010-07-27 Fir de Conversatie Dominique Pellé
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?

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?

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?

I don't think this is a blocker for the release but Bram can decide :-)

-- 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


Re: added completion to the :setfiletype command.

2010-07-27 Fir de Conversatie Peter Odding

Dominique Pellé wrote:

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?

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...


I was specifically talking about completion of file types under ~/.vim, 
otherwise Vim could just include a static list of names. Here's what I 
(and I assume Ingo) have in mind:


function! IdealFtComplete()
  let types = {}
  let pattern = '{ftplugin,syntax,indent}/*.vim'
  let ignored = ['syntax', 'manual', 'synload', 'nosyntax', '2html',
\ 'colortest', 'hitest', 'whitespace', 'AppendMatchGroup',
\ 'GenericIndent']
  for filename in split(globpath(rtp, pattern, 1), \n)
let type = fnamemodify(filename, :t:r)
if index(ignored, type) == -1 | let types[type] = 1 | endif
  endfor
  return sort(keys(types))
endfunction

I've excluded the files you identified in your previous message because 
I agree they probably shouldn't be considered for file type completion.


 - Peter Odding

--
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


Re: added completion to the :setfiletype command.

2010-07-27 Fir de Conversatie Bram Moolenaar

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.

-- 
The most powerful force in the universe is gossip.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
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


Re: added completion to the :setfiletype command.

2010-07-27 Fir de Conversatie Dominique Pellé
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 hostCTRL-D
hostconf hostsaccess

:ownsyntax hostCTRL-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

Re: added completion to the :setfiletype command.

2010-07-27 Fir de Conversatie Dominique Pellé
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 hostCTRL-D
 hostconf     hostsaccess

 :ownsyntax hostCTRL-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_PATH38
+#define EXPAND_FILES_IN_PATH	38
+#define EXPAND_OWNSYNTAX	39
 
 /* Values for exmode_active (0 is no exmode) */
 #define EXMODE_NORMAL		1


Re: added completion to the :setfiletype command.

2010-07-27 Fir de Conversatie Nazri Ramliy
2010/7/28 Dominique Pellé dominique.pe...@gmail.com:
 I send this patch again with slightly more elegant way of doing it
 saving 3 lines of code. Sorry for the noise.

From your patch:

+/* Used in qsort */
+static int cmp_str(s1, s2)
+const void *s1;
+const void *s2;
+{
+return STRCMP(*(char_u **)s1, *(char_u **)s2);
+}
+
...
+   /* 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;
+   }
+   }

The code to achieve this (sort and remove duplicates) are already implemented
and you can reuse it in place of the codes above.

The functions misc2.c:sort_strings() and misc1.c:remove_duplicates()
can be used as-is.

You'll have to export misc1.c:remove_duplicates() though.

See the sample usage in misc1.c:9455.

nazri.

-- 
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


Re: added completion to the :setfiletype command.

2010-07-27 Fir de Conversatie Dominique Pellé
Nazri Ramliy wrote:

 2010/7/28 Dominique Pellé dominique.pe...@gmail.com:
 I send this patch again with slightly more elegant way of doing it
 saving 3 lines of code. Sorry for the noise.

 From your patch:

 +/* Used in qsort */
 +static int cmp_str(s1, s2)
 +    const void *s1;
 +    const void *s2;
 +{
 +    return STRCMP(*(char_u **)s1, *(char_u **)s2);
 +}
 +
 ...
 +       /* 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;
 +           }
 +       }

 The code to achieve this (sort and remove duplicates) are already implemented
 and you can reuse it in place of the codes above.

 The functions misc2.c:sort_strings() and misc1.c:remove_duplicates()
 can be used as-is.

 You'll have to export misc1.c:remove_duplicates() though.

 See the sample usage in misc1.c:9455.

 nazri.


Thanks for having a look Nazri.  I'll update the patch later today with
your comments.  Some remarks though:

* yes, I can reuse sort_strings() as-is (I'll do that)

* I could also reuse remove_duplicates() but it has a slightly
  different behavior since it calls fnamecmp() instead of
  STRCMP() to check for dupes. I wonder whether that's
  desirable here.  I think it's better to use STRCMP() in my case.

Remark about remove_duplicate() in misc1.c: It'd be slightly better
if remove_duplicates(...) looped backward (as in my function) to
avoid doing more moves than necessary when there are dupes (and
to compare with 0 in exit condition which is also cheaper).  Say you
have to remove dupes in this pathological case:
x, x, x, ... x, x  (n times)
remove_duplicate() as currently implemented would do  (n-1)*n/2
moves (that's O(n^2)) whereas when looping backward() as in my
function, it does 0 moves. Looping backward will always do less
moves since it avoids moving duplicates already removed.

Cheers
-- 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


Re: added completion to the :setfiletype command.

2010-07-27 Fir de Conversatie Nazri Ramliy
2010/7/28 Dominique Pellé dominique.pe...@gmail.com:
 * I could also reuse remove_duplicates() but it has a slightly
  different behavior since it calls fnamecmp() instead of
  STRCMP() to check for dupes. I wonder whether that's
  desirable here.  I think it's better to use STRCMP() in my case.

In that case maybe remove_duplicate can be modified to accept a
second argument which is a function pointer to be used as the
string comparator.

 Remark about remove_duplicate() in misc1.c: It'd be slightly better
 if remove_duplicates(...) looped backward (as in my function) to
 avoid doing more moves than necessary when there are dupes (and
 to compare with 0 in exit condition which is also cheaper).  Say you
 have to remove dupes in this pathological case:
 x, x, x, ... x, x  (n times)
 remove_duplicate() as currently implemented would do  (n-1)*n/2
 moves (that's O(n^2)) whereas when looping backward() as in my
 function, it does 0 moves. Looping backward will always do less
 moves since it avoids moving duplicates already removed.

That is indeed the better implementation.  I didn't notice the difference
the first time I looked at your loop.

nazri.

-- 
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


Re: [patch] added completion to the :setfiletype command.

2010-07-26 Fir de Conversatie Christian Brabandt
Hi Dominique!

On Sa, 24 Jul 2010, Dominique Pellé wrote:

 Hi
 
 Attached patch adds completion to the :setfiletype command.
 Example:
 
 :setf javaCTRL-D
 javajavacc  javascript
 
 -- Dominique
 

 diff -r 0c8219a26bc9 src/ex_docmd.c
 --- a/src/ex_docmd.c  Sat Jul 24 20:57:44 2010 +0200
 +++ b/src/ex_docmd.c  Sat Jul 24 23:36:07 2010 +0200
 @@ -3829,6 +3829,7 @@
   xp-xp_pattern = arg;
   break;
  
 + case CMD_setfiletype:
   case CMD_ownsyntax:
   xp-xp_context = EXPAND_FILETYPE;
   xp-xp_pattern = arg;


Since we now have filetype completion, why not add this to the 
command-completion?

chrisbra t41:~/vim/src [1157]% hg diff ex_docmd.c ../runtime/doc/map.txt
diff -r 5bd81e397907 runtime/doc/map.txt
--- a/runtime/doc/map.txt   Sun Jul 25 22:30:20 2010 +0200
+++ b/runtime/doc/map.txt   Mon Jul 26 13:22:25 2010 +0200
@@ -1215,6 +1215,7 @@
-complete=mapping   mapping name
-complete=menu  menus
-complete=optionoptions
+   -complete=syntaxsyntax
-complete=tag   tags
-complete=tag_listfiles tags, file names are shown when CTRL-D is hit
-complete=var   user variables
diff -r 5bd81e397907 src/ex_docmd.c
--- a/src/ex_docmd.cSun Jul 25 22:30:20 2010 +0200
+++ b/src/ex_docmd.cMon Jul 26 13:22:25 2010 +0200
@@ -5280,6 +5280,7 @@
 {EXPAND_MENUS, menu},
 {EXPAND_SETTINGS, option},
 {EXPAND_SHELLCMD, shellcmd},
+{EXPAND_FILETYPE, syntax},
 #if defined(FEAT_SIGNS)
 {EXPAND_SIGN, sign},
 #endif

In the same way, we could also add compiler and colorscheme completion. 
Is that useful?

regards,
Christian

-- 
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


Re: [patch] added completion to the :setfiletype command.

2010-07-26 Fir de Conversatie Bram Moolenaar

Christian Brabandt wrote:

 Hi Dominique!
 
 On Sa, 24 Jul 2010, Dominique Pellé wrote:
 
  Hi
  
  Attached patch adds completion to the :setfiletype command.
  Example:
  
  :setf javaCTRL-D
  javajavacc  javascript
  
  -- Dominique
  
 
  diff -r 0c8219a26bc9 src/ex_docmd.c
  --- a/src/ex_docmd.cSat Jul 24 20:57:44 2010 +0200
  +++ b/src/ex_docmd.cSat Jul 24 23:36:07 2010 +0200
  @@ -3829,6 +3829,7 @@
  xp-xp_pattern = arg;
  break;
   
  +   case CMD_setfiletype:
  case CMD_ownsyntax:
  xp-xp_context = EXPAND_FILETYPE;
  xp-xp_pattern = arg;
 
 
 Since we now have filetype completion, why not add this to the 
 command-completion?
 
 chrisbra t41:~/vim/src [1157]% hg diff ex_docmd.c ../runtime/doc/map.txt
 diff -r 5bd81e397907 runtime/doc/map.txt
 --- a/runtime/doc/map.txt   Sun Jul 25 22:30:20 2010 +0200
 +++ b/runtime/doc/map.txt   Mon Jul 26 13:22:25 2010 +0200
 @@ -1215,6 +1215,7 @@
 -complete=mapping   mapping name
 -complete=menu  menus
 -complete=optionoptions
 +   -complete=syntaxsyntax
 -complete=tag   tags
 -complete=tag_listfiles tags, file names are shown when CTRL-D is hit
 -complete=var   user variables
 diff -r 5bd81e397907 src/ex_docmd.c
 --- a/src/ex_docmd.cSun Jul 25 22:30:20 2010 +0200
 +++ b/src/ex_docmd.cMon Jul 26 13:22:25 2010 +0200
 @@ -5280,6 +5280,7 @@
  {EXPAND_MENUS, menu},
  {EXPAND_SETTINGS, option},
  {EXPAND_SHELLCMD, shellcmd},
 +{EXPAND_FILETYPE, syntax},
  #if defined(FEAT_SIGNS)
  {EXPAND_SIGN, sign},
  #endif

If this is completing filetypes, why call it syntax?  I would find
filetype less confusing.

 In the same way, we could also add compiler and colorscheme completion. 
 Is that useful?

Generally completion is useful.  Note that I'm not going to include new
features now. But these tiny changes should be OK.

-- 
Communication is one of the most compli..., eh, well, it's hard.
You know what I mean.  Not?

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
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


Re: [patch] added completion to the :setfiletype command.

2010-07-25 Fir de Conversatie Bram Moolenaar

Dominique wrote:

 Attached patch adds completion to the :setfiletype command.
 Example:
 
 :setf javaCTRL-D
 javajavacc  javascript

Thanks.

-- 
Beer  pretzels can't be served at the same time in any bar or restaurant.
[real standing law in North Dakota, United States of America]

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
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


[patch] added completion to the :setfiletype command.

2010-07-24 Fir de Conversatie Dominique Pellé
Hi

Attached patch adds completion to the :setfiletype command.
Example:

:setf javaCTRL-D
javajavacc  javascript

-- 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 0c8219a26bc9 src/ex_docmd.c
--- a/src/ex_docmd.c	Sat Jul 24 20:57:44 2010 +0200
+++ b/src/ex_docmd.c	Sat Jul 24 23:36:07 2010 +0200
@@ -3829,6 +3829,7 @@
 	xp-xp_pattern = arg;
 	break;
 
+	case CMD_setfiletype:
 	case CMD_ownsyntax:
 	xp-xp_context = EXPAND_FILETYPE;
 	xp-xp_pattern = arg;