|
|
|
|
|
|
|
|
if !exists('g:spellfile_URL') |
|
|
|
|
|
|
|
|
let g:spellfile_URL = 'https://ftp.nluug.nl/pub/vim/runtime/spell' |
|
|
endif |
|
|
let s:spellfile_URL = '' |
|
|
|
|
|
|
|
|
function! spellfile#LoadFile(lang) |
|
|
|
|
|
try |
|
|
:! |
|
|
catch /\<E12\>/ |
|
|
throw 'Cannot download spellfile in sandbox/modeline. Try ":set spell" from the cmdline.' |
|
|
endtry |
|
|
|
|
|
|
|
|
if !exists(":Nread") |
|
|
if &verbose |
|
|
echomsg 'spellfile#LoadFile(): Nread command is not available.' |
|
|
endif |
|
|
return |
|
|
endif |
|
|
let lang = tolower(a:lang) |
|
|
|
|
|
|
|
|
if s:spellfile_URL != g:spellfile_URL |
|
|
let s:donedict = {} |
|
|
let s:spellfile_URL = g:spellfile_URL |
|
|
endif |
|
|
|
|
|
|
|
|
if has_key(s:donedict, lang . &enc) |
|
|
if &verbose |
|
|
echomsg 'spellfile#LoadFile(): Tried this language/encoding before.' |
|
|
endif |
|
|
return |
|
|
endif |
|
|
let s:donedict[lang . &enc] = 1 |
|
|
|
|
|
|
|
|
let [dirlist, dirchoices] = spellfile#GetDirChoices() |
|
|
if len(dirlist) == 0 |
|
|
let dir_to_create = spellfile#WritableSpellDir() |
|
|
if &verbose || dir_to_create != '' |
|
|
echomsg 'spellfile#LoadFile(): No (writable) spell directory found.' |
|
|
endif |
|
|
if dir_to_create != '' |
|
|
call mkdir(dir_to_create, "p") |
|
|
|
|
|
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 = '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' |
|
|
let enc = 'latin1' |
|
|
endif |
|
|
let fname = a:lang . '.' . enc . '.spl' |
|
|
|
|
|
|
|
|
|
|
|
new |
|
|
let newbufnr = winbufnr(0) |
|
|
setlocal bin fenc= |
|
|
echo 'Downloading ' . fname . '...' |
|
|
call spellfile#Nread(fname) |
|
|
if getline(2) !~ 'VIMspell' |
|
|
|
|
|
|
|
|
|
|
|
if newbufnr != winbufnr(0) |
|
|
let winnr = bufwinnr(newbufnr) |
|
|
if winnr == -1 |
|
|
|
|
|
echomsg "download buffer disappeared, opening a new one" |
|
|
new |
|
|
setlocal bin fenc= |
|
|
else |
|
|
exe winnr . "wincmd w" |
|
|
endif |
|
|
endif |
|
|
if newbufnr == winbufnr(0) |
|
|
|
|
|
keeppatterns g/^/d_ |
|
|
else |
|
|
let newbufnr = winbufnr(0) |
|
|
endif |
|
|
|
|
|
let fname = lang . '.ascii.spl' |
|
|
echo 'Could not find it, trying ' . fname . '...' |
|
|
call spellfile#Nread(fname) |
|
|
if getline(2) !~ 'VIMspell' |
|
|
echo 'Download failed' |
|
|
exe newbufnr . "bwipe!" |
|
|
return |
|
|
endif |
|
|
endif |
|
|
|
|
|
|
|
|
1d_ |
|
|
set nomod |
|
|
|
|
|
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]) |
|
|
else |
|
|
let dirname = escape(dirlist[dirchoice], ' ') |
|
|
endif |
|
|
setlocal fenc= |
|
|
exe "write " . dirname . '/' . fname |
|
|
|
|
|
|
|
|
keeppatterns 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' |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
exe newbufnr . "bwipe" |
|
|
endif |
|
|
endfunc |
|
|
|
|
|
" Read "fname |
|
|
function! spellfile#Nread(fname) |
|
|
|
|
|
if exists("g:netrw_use_errorwindow") |
|
|
let save_ew = g:netrw_use_errorwindow |
|
|
endif |
|
|
let g:netrw_use_errorwindow=0 |
|
|
|
|
|
if g:spellfile_URL =~ '^ftp://' |
|
|
|
|
|
let machine = substitute(g:spellfile_URL, 'ftp://\([^/]*\).*', '\1', '') |
|
|
let dir = substitute(g:spellfile_URL, 'ftp://[^/]*/\(.*\)', '\1', '') |
|
|
exe 'Nread "' . machine . ' anonymous vim7user ' . dir . '/' . a:fname . '"' |
|
|
else |
|
|
exe 'Nread ' g:spellfile_URL . '/' . a:fname |
|
|
endif |
|
|
|
|
|
if exists("save_ew") |
|
|
let g:netrw_use_errorwindow = save_ew |
|
|
else |
|
|
unlet g:netrw_use_errorwindow |
|
|
endif |
|
|
endfunc |
|
|
|
|
|
|
|
|
function! spellfile#GetDirChoices() |
|
|
let dirlist = [] |
|
|
let dirchoices = '&Cancel' |
|
|
for dir in split(globpath(&rtp, 'spell'), "\n") |
|
|
if filewritable(dir) == 2 |
|
|
call add(dirlist, dir) |
|
|
let dirchoices .= "\n&" . len(dirlist) |
|
|
endif |
|
|
endfor |
|
|
return [dirlist, dirchoices] |
|
|
endfunc |
|
|
|
|
|
function! spellfile#WritableSpellDir() |
|
|
|
|
|
return stdpath('data').'/site/spell' |
|
|
endfunction |
|
|
|