]> granicus.if.org Git - vim/commitdiff
Add completion for ":ownsyntax" and improve completion for ":filetype".
authorBram Moolenaar <Bram@vim.org>
Thu, 29 Jul 2010 18:59:59 +0000 (20:59 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 29 Jul 2010 18:59:59 +0000 (20:59 +0200)
(Dominique Pelle)

runtime/doc/todo.txt
src/ex_docmd.c
src/ex_getln.c
src/misc1.c
src/proto/misc1.pro
src/vim.h

index 66bbf5dc431f04578058749ffebf7c9e029b4cb7..55a8b4c5cfc775762758c08760c418aacbf04fea 100644 (file)
@@ -1,4 +1,4 @@
-*todo.txt*      For Vim version 7.3c.  Last change: 2010 Jul 28
+*todo.txt*      For Vim version 7.3c.  Last change: 2010 Jul 29
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -30,8 +30,6 @@ be worked on, but only if you sponsor Vim development.  See |sponsor|.
                                                        *known-bugs*
 -------------------- Known bugs and current work -----------------------
 
-Patch for :filetype completion. (Dominique Pelle, Jul 28)
-
 Windows 7: "Open with..." menu starts Vim without a file.
 Need to use other registry methods in if_ole.cpp?
 
index 2b63c0850597919a1e19ef140704d5ded49ecf32..c4732f704822023f51bc016c17a820a430bbcfea 100644 (file)
@@ -3831,8 +3831,12 @@ set_one_cmd_context(xp, buff)
            xp->xp_pattern = arg;
            break;
 
-       case CMD_setfiletype:
        case CMD_ownsyntax:
+           xp->xp_context = EXPAND_OWNSYNTAX;
+           xp->xp_pattern = arg;
+           break;
+
+       case CMD_setfiletype:
            xp->xp_context = EXPAND_FILETYPE;
            xp->xp_pattern = arg;
            break;
index dfd163dfe084b4d87f7fdb359ffc01f8af0ae65d..b292f639162ca326d3635d085cb951f1035a34a5 100644 (file)
@@ -4116,6 +4116,7 @@ addstar(fname, len, context)
        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 @@ ExpandFromContext(xp, pat, num_file, file, options)
        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_FILETYPE)
+    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,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 @@ ExpandUserList(xp, num_file, file)
 
 /*
  * 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 @@ ExpandRTDir(pat, num_file, file, dirname)
 
     *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 @@ ExpandRTDir(pat, num_file, file, dirname)
            ++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;
index c6ac00157b8984179ca75728768cda82ef2b75da..9b8bbf12d85ad3a2cff62f2456be33128fc57841 100644 (file)
@@ -9238,7 +9238,6 @@ unix_expandpath(gap, path, wildoff, flags, didstar)
 #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 expand_path_option __ARGS((char_u *curdir, garray_T        *gap));
 static char_u *get_path_cutoff __ARGS((char_u *fname, garray_T *gap));
 static void uniquefy_paths __ARGS((garray_T *gap, char_u *pattern));
@@ -9301,29 +9300,6 @@ is_unique(maybe_unique, gap, i)
     return TRUE;  /* no match found */
 }
 
-/*
- * 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;
-       }
-}
-
 /*
  * Split the 'path' option to a an array of strings as garray_T.  Relative
  * paths are expanded to their equivalent fullpath.  This includes the "."
@@ -9642,6 +9618,30 @@ expand_in_path(gap, pattern, flags)
 }
 #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 + 1; j < gap->ga_len; ++j)
+               fnames[j - 1] = fnames[j];
+           --gap->ga_len;
+       }
+}
+#endif
+
 /*
  * Generic wildcard expansion code.
  *
index 2a7b87ee946bc0af809b28279aa9d4c977b01bfb..93bfff60d4c6f3aca04d355e04202231ec0d35e2 100644 (file)
@@ -90,6 +90,7 @@ int expand_wildcards_eval __ARGS((char_u **pat, int *num_file, char_u ***file, i
 int expand_wildcards __ARGS((int num_pat, char_u **pat, int *num_file, char_u ***file, int flags));
 int match_suffix __ARGS((char_u *fname));
 int unix_expandpath __ARGS((garray_T *gap, char_u *path, int wildoff, int flags, int didstar));
+void remove_duplicates __ARGS((garray_T *gap));
 int gen_expand_wildcards __ARGS((int num_pat, char_u **pat, int *num_file, char_u ***file, int flags));
 void addfile __ARGS((garray_T *gap, char_u *f, int flags));
 char_u *get_cmd_output __ARGS((char_u *cmd, char_u *infile, int flags));
index 38bd0eff3c74b7ef1ef0f87b703c6c4651501292..b9ce325539573dfcf76d6988643880f2534b9c0e 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -774,7 +774,8 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname);
 #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