diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2016-04-10 04:52:10 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2016-04-10 04:52:10 -0400 |
commit | 91c5005da82e6f9ab6bb2f46b27cb82b188b0391 (patch) | |
tree | 8ffe1898284a6e76aed87e4cdd8f64ef87b2e298 | |
parent | 1bf1ffc7346c0cc8e8ef337fd94badd3a530e90e (diff) | |
parent | 8d37201ed29a4149ff87b17e7ade209a0981986a (diff) | |
download | rneovim-91c5005da82e6f9ab6bb2f46b27cb82b188b0391.tar.gz rneovim-91c5005da82e6f9ab6bb2f46b27cb82b188b0391.tar.bz2 rneovim-91c5005da82e6f9ab6bb2f46b27cb82b188b0391.zip |
Merge pull request #4555 from justinmk/spell
spell: fix SpellFileMissing handler
-rw-r--r-- | runtime/autoload/spellfile.vim | 118 | ||||
-rw-r--r-- | runtime/plugin/spellfile.vim | 7 | ||||
-rw-r--r-- | src/nvim/spell.c | 13 |
3 files changed, 66 insertions, 72 deletions
diff --git a/runtime/autoload/spellfile.vim b/runtime/autoload/spellfile.vim index c32dd5df9b..a5ffa514ea 100644 --- a/runtime/autoload/spellfile.vim +++ b/runtime/autoload/spellfile.vim @@ -1,6 +1,4 @@ " Vim script to download a missing spell file -" Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2012 Jan 08 if !exists('g:spellfile_URL') " Prefer using http:// when netrw should be able to use it, since @@ -43,22 +41,23 @@ function! spellfile#LoadFile(lang) if len(dirlist) == 0 let dir_to_create = spellfile#WritableSpellDir() if &verbose || dir_to_create != '' - echomsg 'spellfile#LoadFile(): There is no writable spell directory.' + echomsg 'spellfile#LoadFile(): No (writable) spell directory found.' endif if dir_to_create != '' - if confirm("Shall I create " . dir_to_create, "&Yes\n&No", 2) == 1 - " After creating the directory it should show up in the list. - call mkdir(dir_to_create, "p") - let [dirlist, dirchoices] = spellfile#GetDirChoices() - endif + call mkdir(dir_to_create, "p") + " Now it should show up in the list. + let [dirlist, dirchoices] = spellfile#GetDirChoices() endif if len(dirlist) == 0 + echomsg 'Failed to create: '.dir_to_create return + else + echomsg 'Created '.dir_to_create endif endif - let msg = 'Cannot find spell file for "' . a:lang . '" in ' . &enc - let msg .= "\nDo you want me to try downloading it?" + let msg = 'No spell file for "' . a:lang . '" in ' . &enc + let msg .= "\nDownload it?" if confirm(msg, "&Yes\n&No", 2) == 1 let enc = &encoding if enc == 'iso-8859-15' @@ -78,78 +77,77 @@ function! spellfile#LoadFile(lang) " Careful: Nread() may have opened a new window for the error message, " we need to go back to our own buffer and window. if newbufnr != winbufnr(0) - let winnr = bufwinnr(newbufnr) - if winnr == -1 - " Our buffer has vanished!? Open a new window. - echomsg "download buffer disappeared, opening a new one" - new - setlocal bin fenc= - else - exe winnr . "wincmd w" - endif + let winnr = bufwinnr(newbufnr) + if winnr == -1 + " Our buffer has vanished!? Open a new window. + echomsg "download buffer disappeared, opening a new one" + new + setlocal bin fenc= + else + exe winnr . "wincmd w" + endif endif if newbufnr == winbufnr(0) - " We are back the old buffer, remove any (half-finished) download. - g/^/d + " We are back the old buffer, remove any (half-finished) download. + g/^/d_ else - let newbufnr = winbufnr(0) + let newbufnr = winbufnr(0) endif let fname = a:lang . '.ascii.spl' echo 'Could not find it, trying ' . fname . '...' call spellfile#Nread(fname) if getline(2) !~ 'VIMspell' - echo 'Sorry, downloading failed' - exe newbufnr . "bwipe!" - return + echo 'Download failed' + exe newbufnr . "bwipe!" + return endif endif " Delete the empty first line and mark the file unmodified. - 1d + 1d_ set nomod - let msg = "In which directory do you want to write the file:" - for i in range(len(dirlist)) - let msg .= "\n" . (i + 1) . '. ' . dirlist[i] - endfor - let dirchoice = confirm(msg, dirchoices) - 2 + if len(dirlist) == 1 + let dirchoice = 0 + else + let msg = "In which directory do you want to write the file:" + for i in range(len(dirlist)) + let msg .= "\n" . (i + 1) . '. ' . dirlist[i] + endfor + let dirchoice = confirm(msg, dirchoices) - 2 + endif if dirchoice >= 0 if exists('*fnameescape') - let dirname = fnameescape(dirlist[dirchoice]) + let dirname = fnameescape(dirlist[dirchoice]) else - let dirname = escape(dirlist[dirchoice], ' ') + let dirname = escape(dirlist[dirchoice], ' ') endif setlocal fenc= exe "write " . dirname . '/' . fname - " Also download the .sug file, if the user wants to. - let msg = "Do you want me to try getting the .sug file?\n" - let msg .= "This will improve making suggestions for spelling mistakes,\n" - let msg .= "but it uses quite a bit of memory." - if confirm(msg, "&No\n&Yes") == 2 - g/^/d - let fname = substitute(fname, '\.spl$', '.sug', '') - echo 'Downloading ' . fname . '...' - call spellfile#Nread(fname) - if getline(2) =~ 'VIMsug' - 1d - exe "write " . dirname . '/' . fname - set nomod - else - echo 'Sorry, downloading failed' - " Go back to our own buffer/window, Nread() may have taken us to - " another window. - if newbufnr != winbufnr(0) - let winnr = bufwinnr(newbufnr) - if winnr != -1 - exe winnr . "wincmd w" - endif - endif - if newbufnr == winbufnr(0) - set nomod - endif - endif + " Also download the .sug file. + g/^/d_ + let fname = substitute(fname, '\.spl$', '.sug', '') + echo 'Downloading ' . fname . '...' + call spellfile#Nread(fname) + if getline(2) =~ 'VIMsug' + 1d_ + exe "write " . dirname . '/' . fname + set nomod + else + echo 'Download failed' + " Go back to our own buffer/window, Nread() may have taken us to + " another window. + if newbufnr != winbufnr(0) + let winnr = bufwinnr(newbufnr) + if winnr != -1 + exe winnr . "wincmd w" + endif + endif + if newbufnr == winbufnr(0) + set nomod + endif endif endif diff --git a/runtime/plugin/spellfile.vim b/runtime/plugin/spellfile.vim index 437296090c..e03659d6d6 100644 --- a/runtime/plugin/spellfile.vim +++ b/runtime/plugin/spellfile.vim @@ -1,15 +1,8 @@ " Vim plugin for downloading spell files -" Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2006 Feb 01 -" Exit quickly when: -" - this plugin was already loaded -" - when 'compatible' is set -" - some autocommands are already taking care of spell files if exists("loaded_spellfile_plugin") || &cp || exists("#SpellFileMissing") finish endif let loaded_spellfile_plugin = 1 -" The function is in the autoload directory. autocmd SpellFileMissing * call spellfile#LoadFile(expand('<amatch>')) diff --git a/src/nvim/spell.c b/src/nvim/spell.c index cc7dc6210c..fdae89b84c 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2332,14 +2332,17 @@ static void spell_load_lang(char_u *lang) if (r == FAIL) { if (starting) { - // Some startup file sets &spell, but the necessary files don't exist: - // try to prompt the user at VimEnter. Also set spell again. #3027 - do_cmdline_cmd( - "autocmd VimEnter * call spellfile#LoadFile(&spelllang)|set spell"); + // Prompt the user at VimEnter if spell files are missing. #3027 + // Plugins aren't loaded yet, so spellfile.vim cannot handle this case. + char autocmd_buf[128] = { 0 }; + snprintf(autocmd_buf, sizeof(autocmd_buf), + "autocmd VimEnter * call spellfile#LoadFile('%s')|set spell", + lang); + do_cmdline_cmd(autocmd_buf); } else { smsg( _("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""), - lang, spell_enc(), lang); + lang, spell_enc(), lang); } } else if (sl.sl_slang != NULL) { // At least one file was loaded, now load ALL the additions. |