summaryrefslogtreecommitdiffstats
path: root/src/ex_cmds2.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2011-05-19 18:26:40 +0200
committerBram Moolenaar <Bram@vim.org>2011-05-19 18:26:40 +0200
commit9b486ca3915bf457ddbd6f55f28a1f143b8f63c3 (patch)
tree3ef7e512bcfa93a2e049f2e9139894a57b145293 /src/ex_cmds2.c
parentefa8e80c0bbd2a1c732f9cfccf296dacf96bddbe (diff)
updated for version 7.3.198v7.3.198
Problem: No completion for ":lang". Solution: Get locales to complete from. (Dominique Pelle)
Diffstat (limited to 'src/ex_cmds2.c')
-rw-r--r--src/ex_cmds2.c98
1 files changed, 96 insertions, 2 deletions
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
index 0fe9b32f6c..8dbe9294e4 100644
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -1476,7 +1476,7 @@ browse_save_fname(buf)
#endif
/*
- * Ask the user what to do when abondoning a changed buffer.
+ * Ask the user what to do when abandoning a changed buffer.
* Must check 'write' option first!
*/
void
@@ -4153,6 +4153,82 @@ ex_language(eap)
}
# if defined(FEAT_CMDL_COMPL) || defined(PROTO)
+
+static char_u **locales = NULL; /* Array of all available locales */
+static int did_init_locales = FALSE;
+
+static void init_locales __ARGS((void));
+static char_u **find_locales __ARGS((void));
+
+/*
+ * Lazy initialization of all available locales.
+ */
+ static void
+init_locales()
+{
+ if (!did_init_locales)
+ {
+ did_init_locales = TRUE;
+ locales = find_locales();
+ }
+}
+
+/* Return an array of strings for all available locales + NULL for the
+ * last element. Return NULL in case of error. */
+ static char_u **
+find_locales()
+{
+ garray_T locales_ga;
+ char_u *loc;
+
+ /* Find all available locales by running command "locale -a". If this
+ * doesn't work we won't have completion. */
+ char_u *locale_a = get_cmd_output((char_u *)"locale -a",
+ NULL, SHELL_SILENT);
+ if (locale_a == NULL)
+ return NULL;
+ ga_init2(&locales_ga, sizeof(char_u *), 20);
+
+ /* Transform locale_a string where each locale is separated by "\n"
+ * into an array of locale strings. */
+ loc = (char_u *)strtok((char *)locale_a, "\n");
+
+ while (loc != NULL)
+ {
+ if (ga_grow(&locales_ga, 1) == FAIL)
+ break;
+ loc = vim_strsave(loc);
+ if (loc == NULL)
+ break;
+
+ ((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc;
+ loc = (char_u *)strtok(NULL, "\n");
+ }
+ vim_free(locale_a);
+ if (ga_grow(&locales_ga, 1) == FAIL)
+ {
+ ga_clear(&locales_ga);
+ return NULL;
+ }
+ ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL;
+ return (char_u **)locales_ga.ga_data;
+}
+
+# if defined(EXITFREE) || defined(PROTO)
+ void
+free_locales()
+{
+ int i;
+ if (locales != NULL)
+ {
+ for (i = 0; locales[i] != NULL; i++)
+ vim_free(locales[i]);
+ vim_free(locales);
+ locales = NULL;
+ }
+}
+# endif
+
/*
* Function given to ExpandGeneric() to obtain the possible arguments of the
* ":language" command.
@@ -4168,7 +4244,25 @@ get_lang_arg(xp, idx)
return (char_u *)"ctype";
if (idx == 2)
return (char_u *)"time";
- return NULL;
+
+ init_locales();
+ if (locales == NULL)
+ return NULL;
+ return locales[idx - 3];
+}
+
+/*
+ * Function given to ExpandGeneric() to obtain the available locales.
+ */
+ char_u *
+get_locales(xp, idx)
+ expand_T *xp UNUSED;
+ int idx;
+{
+ init_locales();
+ if (locales == NULL)
+ return NULL;
+ return locales[idx];
}
# endif