mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
Merge pull request #4555 from justinmk/spell
spell: fix SpellFileMissing handler
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
" Vim script to download a missing spell file
|
" Vim script to download a missing spell file
|
||||||
" Maintainer: Bram Moolenaar <Bram@vim.org>
|
|
||||||
" Last Change: 2012 Jan 08
|
|
||||||
|
|
||||||
if !exists('g:spellfile_URL')
|
if !exists('g:spellfile_URL')
|
||||||
" Prefer using http:// when netrw should be able to use it, since
|
" Prefer using http:// when netrw should be able to use it, since
|
||||||
@@ -43,22 +41,23 @@ function! spellfile#LoadFile(lang)
|
|||||||
if len(dirlist) == 0
|
if len(dirlist) == 0
|
||||||
let dir_to_create = spellfile#WritableSpellDir()
|
let dir_to_create = spellfile#WritableSpellDir()
|
||||||
if &verbose || dir_to_create != ''
|
if &verbose || dir_to_create != ''
|
||||||
echomsg 'spellfile#LoadFile(): There is no writable spell directory.'
|
echomsg 'spellfile#LoadFile(): No (writable) spell directory found.'
|
||||||
endif
|
endif
|
||||||
if dir_to_create != ''
|
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")
|
call mkdir(dir_to_create, "p")
|
||||||
|
" Now it should show up in the list.
|
||||||
let [dirlist, dirchoices] = spellfile#GetDirChoices()
|
let [dirlist, dirchoices] = spellfile#GetDirChoices()
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
if len(dirlist) == 0
|
if len(dirlist) == 0
|
||||||
|
echomsg 'Failed to create: '.dir_to_create
|
||||||
return
|
return
|
||||||
|
else
|
||||||
|
echomsg 'Created '.dir_to_create
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let msg = 'Cannot find spell file for "' . a:lang . '" in ' . &enc
|
let msg = 'No spell file for "' . a:lang . '" in ' . &enc
|
||||||
let msg .= "\nDo you want me to try downloading it?"
|
let msg .= "\nDownload it?"
|
||||||
if confirm(msg, "&Yes\n&No", 2) == 1
|
if confirm(msg, "&Yes\n&No", 2) == 1
|
||||||
let enc = &encoding
|
let enc = &encoding
|
||||||
if enc == 'iso-8859-15'
|
if enc == 'iso-8859-15'
|
||||||
@@ -90,7 +89,7 @@ function! spellfile#LoadFile(lang)
|
|||||||
endif
|
endif
|
||||||
if newbufnr == winbufnr(0)
|
if newbufnr == winbufnr(0)
|
||||||
" We are back the old buffer, remove any (half-finished) download.
|
" We are back the old buffer, remove any (half-finished) download.
|
||||||
g/^/d
|
g/^/d_
|
||||||
else
|
else
|
||||||
let newbufnr = winbufnr(0)
|
let newbufnr = winbufnr(0)
|
||||||
endif
|
endif
|
||||||
@@ -99,21 +98,25 @@ function! spellfile#LoadFile(lang)
|
|||||||
echo 'Could not find it, trying ' . fname . '...'
|
echo 'Could not find it, trying ' . fname . '...'
|
||||||
call spellfile#Nread(fname)
|
call spellfile#Nread(fname)
|
||||||
if getline(2) !~ 'VIMspell'
|
if getline(2) !~ 'VIMspell'
|
||||||
echo 'Sorry, downloading failed'
|
echo 'Download failed'
|
||||||
exe newbufnr . "bwipe!"
|
exe newbufnr . "bwipe!"
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Delete the empty first line and mark the file unmodified.
|
" Delete the empty first line and mark the file unmodified.
|
||||||
1d
|
1d_
|
||||||
set nomod
|
set nomod
|
||||||
|
|
||||||
|
if len(dirlist) == 1
|
||||||
|
let dirchoice = 0
|
||||||
|
else
|
||||||
let msg = "In which directory do you want to write the file:"
|
let msg = "In which directory do you want to write the file:"
|
||||||
for i in range(len(dirlist))
|
for i in range(len(dirlist))
|
||||||
let msg .= "\n" . (i + 1) . '. ' . dirlist[i]
|
let msg .= "\n" . (i + 1) . '. ' . dirlist[i]
|
||||||
endfor
|
endfor
|
||||||
let dirchoice = confirm(msg, dirchoices) - 2
|
let dirchoice = confirm(msg, dirchoices) - 2
|
||||||
|
endif
|
||||||
if dirchoice >= 0
|
if dirchoice >= 0
|
||||||
if exists('*fnameescape')
|
if exists('*fnameescape')
|
||||||
let dirname = fnameescape(dirlist[dirchoice])
|
let dirname = fnameescape(dirlist[dirchoice])
|
||||||
@@ -123,21 +126,17 @@ function! spellfile#LoadFile(lang)
|
|||||||
setlocal fenc=
|
setlocal fenc=
|
||||||
exe "write " . dirname . '/' . fname
|
exe "write " . dirname . '/' . fname
|
||||||
|
|
||||||
" Also download the .sug file, if the user wants to.
|
" Also download the .sug file.
|
||||||
let msg = "Do you want me to try getting the .sug file?\n"
|
g/^/d_
|
||||||
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', '')
|
let fname = substitute(fname, '\.spl$', '.sug', '')
|
||||||
echo 'Downloading ' . fname . '...'
|
echo 'Downloading ' . fname . '...'
|
||||||
call spellfile#Nread(fname)
|
call spellfile#Nread(fname)
|
||||||
if getline(2) =~ 'VIMsug'
|
if getline(2) =~ 'VIMsug'
|
||||||
1d
|
1d_
|
||||||
exe "write " . dirname . '/' . fname
|
exe "write " . dirname . '/' . fname
|
||||||
set nomod
|
set nomod
|
||||||
else
|
else
|
||||||
echo 'Sorry, downloading failed'
|
echo 'Download failed'
|
||||||
" Go back to our own buffer/window, Nread() may have taken us to
|
" Go back to our own buffer/window, Nread() may have taken us to
|
||||||
" another window.
|
" another window.
|
||||||
if newbufnr != winbufnr(0)
|
if newbufnr != winbufnr(0)
|
||||||
@@ -151,7 +150,6 @@ function! spellfile#LoadFile(lang)
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
" Wipe out the buffer we used.
|
" Wipe out the buffer we used.
|
||||||
exe newbufnr . "bwipe"
|
exe newbufnr . "bwipe"
|
||||||
|
@@ -1,15 +1,8 @@
|
|||||||
" Vim plugin for downloading spell files
|
" 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")
|
if exists("loaded_spellfile_plugin") || &cp || exists("#SpellFileMissing")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let loaded_spellfile_plugin = 1
|
let loaded_spellfile_plugin = 1
|
||||||
|
|
||||||
" The function is in the autoload directory.
|
|
||||||
autocmd SpellFileMissing * call spellfile#LoadFile(expand('<amatch>'))
|
autocmd SpellFileMissing * call spellfile#LoadFile(expand('<amatch>'))
|
||||||
|
@@ -2332,10 +2332,13 @@ static void spell_load_lang(char_u *lang)
|
|||||||
|
|
||||||
if (r == FAIL) {
|
if (r == FAIL) {
|
||||||
if (starting) {
|
if (starting) {
|
||||||
// Some startup file sets &spell, but the necessary files don't exist:
|
// Prompt the user at VimEnter if spell files are missing. #3027
|
||||||
// try to prompt the user at VimEnter. Also set spell again. #3027
|
// Plugins aren't loaded yet, so spellfile.vim cannot handle this case.
|
||||||
do_cmdline_cmd(
|
char autocmd_buf[128] = { 0 };
|
||||||
"autocmd VimEnter * call spellfile#LoadFile(&spelllang)|set spell");
|
snprintf(autocmd_buf, sizeof(autocmd_buf),
|
||||||
|
"autocmd VimEnter * call spellfile#LoadFile('%s')|set spell",
|
||||||
|
lang);
|
||||||
|
do_cmdline_cmd(autocmd_buf);
|
||||||
} else {
|
} else {
|
||||||
smsg(
|
smsg(
|
||||||
_("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""),
|
_("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""),
|
||||||
|
Reference in New Issue
Block a user