summaryrefslogtreecommitdiffstats
path: root/src/ex_docmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ex_docmd.c')
-rw-r--r--src/ex_docmd.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index d4b972a2ef..f0c7aad7df 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -5408,6 +5408,25 @@ get_bad_opt(char_u *p, exarg_T *eap)
}
/*
+ * Function given to ExpandGeneric() to obtain the list of bad= names.
+ */
+ static char_u *
+get_bad_name(expand_T *xp UNUSED, int idx)
+{
+ // Note: Keep this in sync with getargopt.
+ static char *(p_bad_values[]) =
+ {
+ "?",
+ "keep",
+ "drop",
+ };
+
+ if (idx < (int)ARRAY_LENGTH(p_bad_values))
+ return (char_u*)p_bad_values[idx];
+ return NULL;
+}
+
+/*
* Get "++opt=arg" argument.
* Return FAIL or OK.
*/
@@ -5419,6 +5438,8 @@ getargopt(exarg_T *eap)
int bad_char_idx;
char_u *p;
+ // Note: Keep this in sync with get_argopt_name.
+
// ":edit ++[no]bin[ary] file"
if (STRNCMP(arg, "bin", 3) == 0 || STRNCMP(arg, "nobin", 5) == 0)
{
@@ -5499,6 +5520,96 @@ getargopt(exarg_T *eap)
return OK;
}
+/*
+ * Function given to ExpandGeneric() to obtain the list of ++opt names.
+ */
+ static char_u *
+get_argopt_name(expand_T *xp UNUSED, int idx)
+{
+ // Note: Keep this in sync with getargopt.
+ static char *(p_opt_values[]) =
+ {
+ "fileformat=",
+ "encoding=",
+ "binary",
+ "nobinary",
+ "bad=",
+ "edit",
+ };
+
+ if (idx < (int)ARRAY_LENGTH(p_opt_values))
+ return (char_u*)p_opt_values[idx];
+ return NULL;
+}
+
+/*
+ * Command-line expansion for ++opt=name.
+ */
+ int
+expand_argopt(
+ char_u *pat,
+ expand_T *xp,
+ regmatch_T *rmp,
+ char_u ***matches,
+ int *numMatches)
+{
+ if (xp->xp_pattern > xp->xp_line && *(xp->xp_pattern-1) == '=')
+ {
+ char_u *(*cb)(expand_T *, int) = NULL;
+
+ char_u *name_end = xp->xp_pattern - 1;
+ if (name_end - xp->xp_line >= 2
+ && STRNCMP(name_end - 2, "ff", 2) == 0)
+ cb = get_fileformat_name;
+ else if (name_end - xp->xp_line >= 10
+ && STRNCMP(name_end - 10, "fileformat", 10) == 0)
+ cb = get_fileformat_name;
+ else if (name_end - xp->xp_line >= 3
+ && STRNCMP(name_end - 3, "enc", 3) == 0)
+ cb = get_encoding_name;
+ else if (name_end - xp->xp_line >= 8
+ && STRNCMP(name_end - 8, "encoding", 8) == 0)
+ cb = get_encoding_name;
+ else if (name_end - xp->xp_line >= 3
+ && STRNCMP(name_end - 3, "bad", 3) == 0)
+ cb = get_bad_name;
+
+ if (cb != NULL)
+ {
+ return ExpandGeneric(
+ pat,
+ xp,
+ rmp,
+ matches,
+ numMatches,
+ cb,
+ FALSE);
+ }
+ return FAIL;
+ }
+
+ // Special handling of "ff" which acts as a short form of
+ // "fileformat", as "ff" is not a substring of it.
+ if (STRCMP(xp->xp_pattern, "ff") == 0)
+ {
+ *matches = ALLOC_MULT(char_u *, 1);
+ if (*matches == NULL)
+ return FAIL;
+ *numMatches = 1;
+ (*matches)[0] = vim_strsave((char_u*)"fileformat=");
+ return OK;
+ }
+
+ return ExpandGeneric(
+ pat,
+ xp,
+ rmp,
+ matches,
+ numMatches,
+ get_argopt_name,
+ FALSE);
+}
+
static void
ex_autocmd(exarg_T *eap)
{