diff src/spell.c @ 649:8157079cea85

updated for version 7.0191
author vimboss
date Wed, 01 Feb 2006 21:47:16 +0000
parents 593092a5362b
children 0e922220d322
line wrap: on
line diff
--- a/src/spell.c
+++ b/src/spell.c
@@ -2229,6 +2229,9 @@ spell_load_lang(lang)
     char_u	fname_enc[85];
     int		r;
     spelload_T	sl;
+#ifdef FEAT_AUTOCMD
+    int		round;
+#endif
 
     /* Copy the language name to pass it to spell_load_cb() as a cookie.
      * It's truncated when an error is detected. */
@@ -2236,24 +2239,41 @@ spell_load_lang(lang)
     sl.sl_slang = NULL;
     sl.sl_nobreak = FALSE;
 
-    /*
-     * Find the first spell file for "lang" in 'runtimepath' and load it.
-     */
-    vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5,
+#ifdef FEAT_AUTOCMD
+    /* We may retry when no spell file is found for the language, an
+     * autocommand may load it then. */
+    for (round = 1; round <= 2; ++round)
+#endif
+    {
+	/*
+	 * Find the first spell file for "lang" in 'runtimepath' and load it.
+	 */
+	vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5,
 					"spell/%s.%s.spl", lang, spell_enc());
-    r = do_in_runtimepath(fname_enc, FALSE, spell_load_cb, &sl);
-
-    if (r == FAIL && *sl.sl_lang != NUL)
-    {
-	/* Try loading the ASCII version. */
-	vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5,
+	r = do_in_runtimepath(fname_enc, FALSE, spell_load_cb, &sl);
+
+	if (r == FAIL && *sl.sl_lang != NUL)
+	{
+	    /* Try loading the ASCII version. */
+	    vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5,
 						  "spell/%s.ascii.spl", lang);
-	r = do_in_runtimepath(fname_enc, FALSE, spell_load_cb, &sl);
+	    r = do_in_runtimepath(fname_enc, FALSE, spell_load_cb, &sl);
+
+#ifdef FEAT_AUTOCMD
+	    if (r == FAIL && *sl.sl_lang != NUL && round == 1
+		    && apply_autocmds(EVENT_SPELLFILEMISSING, lang,
+					      curbuf->b_fname, FALSE, curbuf))
+		continue;
+	    break;
+#endif
+	}
     }
 
     if (r == FAIL)
+    {
 	smsg((char_u *)_("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""),
 						     lang, spell_enc(), lang);
+    }
     else if (sl.sl_slang != NULL)
     {
 	/* At least one file was loaded, now load ALL the additions. */