Mirror of the Vim source from https://github.com/vim/vim
修訂 | 184d2020d8f12823a2f2cb96335a68ac1bda3270 (tree) |
---|---|
時間 | 2007-05-07 06:55:31 |
作者 | vimboss |
Commiter | vimboss |
updated for version 7.1a-001
@@ -1,6 +1,6 @@ | ||
1 | 1 | " Vim script to download a missing spell file |
2 | 2 | " Maintainer: Bram Moolenaar <Bram@vim.org> |
3 | -" Last Change: 2006 Aug 29 | |
3 | +" Last Change: 2007 May 06 | |
4 | 4 | |
5 | 5 | if !exists('g:spellfile_URL') |
6 | 6 | let g:spellfile_URL = 'ftp://ftp.vim.org/pub/vim/runtime/spell' |
@@ -58,19 +58,40 @@ | ||
58 | 58 | let fname = a:lang . '.' . enc . '.spl' |
59 | 59 | |
60 | 60 | " Split the window, read the file into a new buffer. |
61 | + " Remember the buffer number, we check it below. | |
61 | 62 | new |
63 | + let newbufnr = winbufnr(0) | |
62 | 64 | setlocal bin |
63 | 65 | echo 'Downloading ' . fname . '...' |
64 | 66 | call spellfile#Nread(fname) |
65 | 67 | if getline(2) !~ 'VIMspell' |
66 | 68 | " Didn't work, perhaps there is an ASCII one. |
67 | - g/^/d | |
69 | + " Careful: Nread() may have opened a new window for the error message, | |
70 | + " we need to go back to our own buffer and window. | |
71 | + if newbufnr != winbufnr(0) | |
72 | + let winnr = bufwinnr(newbufnr) | |
73 | + if winnr == -1 | |
74 | + " Our buffer has vanished!? Open a new window. | |
75 | + echomsg "download buffer disappeared, opening a new one" | |
76 | + new | |
77 | + setlocal bin | |
78 | + else | |
79 | + exe winnr . "wincmd w" | |
80 | + endif | |
81 | + endif | |
82 | + if newbufnr == winbufnr(0) | |
83 | + " We are back the old buffer, remove any (half-finished) download. | |
84 | + g/^/d | |
85 | + else | |
86 | + let newbufnr = winbufnr(0) | |
87 | + endif | |
88 | + | |
68 | 89 | let fname = a:lang . '.ascii.spl' |
69 | 90 | echo 'Could not find it, trying ' . fname . '...' |
70 | 91 | call spellfile#Nread(fname) |
71 | 92 | if getline(2) !~ 'VIMspell' |
72 | 93 | echo 'Sorry, downloading failed' |
73 | - bwipe! | |
94 | + exe newbufnr . "bwipe!" | |
74 | 95 | return |
75 | 96 | endif |
76 | 97 | endif |
@@ -96,17 +117,29 @@ | ||
96 | 117 | let fname = substitute(fname, '\.spl$', '.sug', '') |
97 | 118 | echo 'Downloading ' . fname . '...' |
98 | 119 | call spellfile#Nread(fname) |
99 | - if getline(2) !~ 'VIMsug' | |
100 | - echo 'Sorry, downloading failed' | |
101 | - else | |
120 | + if getline(2) =~ 'VIMsug' | |
102 | 121 | 1d |
103 | 122 | exe "write " . escape(dirlist[dirchoice], ' ') . '/' . fname |
123 | + set nomod | |
124 | + else | |
125 | + echo 'Sorry, downloading failed' | |
126 | + " Go back to our own buffer/window, Nread() may have taken us to | |
127 | + " another window. | |
128 | + if newbufnr != winbufnr(0) | |
129 | + let winnr = bufwinnr(newbufnr) | |
130 | + if winnr != -1 | |
131 | + exe winnr . "wincmd w" | |
132 | + endif | |
133 | + endif | |
134 | + if newbufnr == winbufnr(0) | |
135 | + set nomod | |
136 | + endif | |
104 | 137 | endif |
105 | - set nomod | |
106 | 138 | endif |
107 | 139 | endif |
108 | 140 | |
109 | - bwipe | |
141 | + " Wipe out the buffer we used. | |
142 | + exe newbufnr . "bwipe" | |
110 | 143 | endif |
111 | 144 | endfunc |
112 | 145 |
@@ -1426,6 +1426,13 @@ | ||
1426 | 1426 | if (curbuf->b_kmap_state & KEYMAP_INIT) |
1427 | 1427 | keymap_init(); |
1428 | 1428 | #endif |
1429 | +#ifdef FEAT_SPELL | |
1430 | + /* May need to set the spell language. Can only do this after the buffer | |
1431 | + * has been properly setup. */ | |
1432 | + if (!curbuf->b_help && curwin->w_p_spell && *curbuf->b_p_spl != NUL) | |
1433 | + did_set_spelllang(curbuf); | |
1434 | +#endif | |
1435 | + | |
1429 | 1436 | redraw_later(NOT_VALID); |
1430 | 1437 | } |
1431 | 1438 |
@@ -2415,11 +2422,6 @@ | ||
2415 | 2422 | if (p_fdls >= 0) |
2416 | 2423 | curwin->w_p_fdl = p_fdls; |
2417 | 2424 | #endif |
2418 | - | |
2419 | -#ifdef FEAT_SPELL | |
2420 | - if (curwin->w_p_spell && *buf->b_p_spl != NUL) | |
2421 | - did_set_spelllang(buf); | |
2422 | -#endif | |
2423 | 2425 | } |
2424 | 2426 | |
2425 | 2427 | /* |
@@ -3088,6 +3088,9 @@ | ||
3088 | 3088 | char_u *cp; |
3089 | 3089 | #endif |
3090 | 3090 | char_u *command = NULL; |
3091 | +#ifdef FEAT_SPELL | |
3092 | + int did_get_winopts = FALSE; | |
3093 | +#endif | |
3091 | 3094 | |
3092 | 3095 | if (eap != NULL) |
3093 | 3096 | command = eap->do_ecmd_cmd; |
@@ -3365,6 +3368,9 @@ | ||
3365 | 3368 | * before, reset the local window options to the global |
3366 | 3369 | * values. Also restores old folding stuff. */ |
3367 | 3370 | get_winopts(buf); |
3371 | +#ifdef FEAT_SPELL | |
3372 | + did_get_winopts = TRUE; | |
3373 | +#endif | |
3368 | 3374 | |
3369 | 3375 | #ifdef FEAT_AUTOCMD |
3370 | 3376 | } |
@@ -3640,6 +3646,13 @@ | ||
3640 | 3646 | } |
3641 | 3647 | #endif |
3642 | 3648 | |
3649 | +#ifdef FEAT_SPELL | |
3650 | + /* If the window options were changed may need to set the spell language. | |
3651 | + * Can only do this after the buffer has been properly setup. */ | |
3652 | + if (did_get_winopts && curwin->w_p_spell && *buf->b_p_spl != NUL) | |
3653 | + did_set_spelllang(buf); | |
3654 | +#endif | |
3655 | + | |
3643 | 3656 | if (command == NULL) |
3644 | 3657 | { |
3645 | 3658 | if (newcol >= 0) /* position set by autocommands */ |
@@ -4105,12 +4105,28 @@ | ||
4105 | 4105 | int nobreak = FALSE; |
4106 | 4106 | int i, j; |
4107 | 4107 | langp_T *lp, *lp2; |
4108 | + static int recursive = FALSE; | |
4109 | + char_u *ret_msg = NULL; | |
4110 | + char_u *spl_copy; | |
4111 | + | |
4112 | + /* We don't want to do this recursively. May happen when a language is | |
4113 | + * not available and the SpellFileMissing autocommand opens a new buffer | |
4114 | + * in which 'spell' is set. */ | |
4115 | + if (recursive) | |
4116 | + return NULL; | |
4117 | + recursive = TRUE; | |
4108 | 4118 | |
4109 | 4119 | ga_init2(&ga, sizeof(langp_T), 2); |
4110 | 4120 | clear_midword(buf); |
4111 | 4121 | |
4122 | + /* Make a copy of 'spellang', the SpellFileMissing autocommands may change | |
4123 | + * it under our fingers. */ | |
4124 | + spl_copy = vim_strsave(buf->b_p_spl); | |
4125 | + if (spl_copy == NULL) | |
4126 | + goto theend; | |
4127 | + | |
4112 | 4128 | /* loop over comma separated language names. */ |
4113 | - for (splp = buf->b_p_spl; *splp != NUL; ) | |
4129 | + for (splp = spl_copy; *splp != NUL; ) | |
4114 | 4130 | { |
4115 | 4131 | /* Get one language name. */ |
4116 | 4132 | copy_option_part(&splp, lang, MAXWLEN, ","); |
@@ -4176,7 +4192,18 @@ | ||
4176 | 4192 | if (filename) |
4177 | 4193 | (void)spell_load_file(lang, lang, NULL, FALSE); |
4178 | 4194 | else |
4195 | + { | |
4179 | 4196 | spell_load_lang(lang); |
4197 | +#ifdef FEAT_AUTOCMD | |
4198 | + /* SpellFileMissing autocommands may do anything, including | |
4199 | + * destroying the buffer we are using... */ | |
4200 | + if (!buf_valid(buf)) | |
4201 | + { | |
4202 | + ret_msg = (char_u *)"E797: SpellFileMissing autocommand deleted buffer"; | |
4203 | + goto theend; | |
4204 | + } | |
4205 | +#endif | |
4206 | + } | |
4180 | 4207 | } |
4181 | 4208 | |
4182 | 4209 | /* |
@@ -4215,7 +4242,8 @@ | ||
4215 | 4242 | if (ga_grow(&ga, 1) == FAIL) |
4216 | 4243 | { |
4217 | 4244 | ga_clear(&ga); |
4218 | - return e_outofmem; | |
4245 | + ret_msg = e_outofmem; | |
4246 | + goto theend; | |
4219 | 4247 | } |
4220 | 4248 | LANGP_ENTRY(ga, ga.ga_len)->lp_slang = slang; |
4221 | 4249 | LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask; |
@@ -4231,7 +4259,7 @@ | ||
4231 | 4259 | * round 1: load first name in 'spellfile'. |
4232 | 4260 | * round 2: load second name in 'spellfile. |
4233 | 4261 | * etc. */ |
4234 | - spf = curbuf->b_p_spf; | |
4262 | + spf = buf->b_p_spf; | |
4235 | 4263 | for (round = 0; round == 0 || *spf != NUL; ++round) |
4236 | 4264 | { |
4237 | 4265 | if (round == 0) |
@@ -4357,7 +4385,10 @@ | ||
4357 | 4385 | } |
4358 | 4386 | } |
4359 | 4387 | |
4360 | - return NULL; | |
4388 | +theend: | |
4389 | + vim_free(spl_copy); | |
4390 | + recursive = FALSE; | |
4391 | + return ret_msg; | |
4361 | 4392 | } |
4362 | 4393 | |
4363 | 4394 | /* |
@@ -667,6 +667,8 @@ | ||
667 | 667 | static int included_patches[] = |
668 | 668 | { /* Add new patch number below this line */ |
669 | 669 | /**/ |
670 | + 1, | |
671 | +/**/ | |
670 | 672 | 0 |
671 | 673 | }; |
672 | 674 |