mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
spellfile.vim: less pestering
- Always auto-create spell/ directory, don't ask. - Don't ask where to put .spl file if only 1 choice exists. - Always download .sug file, don't ask. - Use blackhole register for :delete and :g//d. - Formatting: expand tabs.
This commit is contained in:
parent
bf2c2b34cf
commit
3462f46cb8
@ -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
|
call mkdir(dir_to_create, "p")
|
||||||
" After creating the directory it should show up in the list.
|
" Now it should show up in the list.
|
||||||
call mkdir(dir_to_create, "p")
|
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'
|
||||||
@ -78,78 +77,77 @@ function! spellfile#LoadFile(lang)
|
|||||||
" Careful: Nread() may have opened a new window for the error message,
|
" Careful: Nread() may have opened a new window for the error message,
|
||||||
" we need to go back to our own buffer and window.
|
" we need to go back to our own buffer and window.
|
||||||
if newbufnr != winbufnr(0)
|
if newbufnr != winbufnr(0)
|
||||||
let winnr = bufwinnr(newbufnr)
|
let winnr = bufwinnr(newbufnr)
|
||||||
if winnr == -1
|
if winnr == -1
|
||||||
" Our buffer has vanished!? Open a new window.
|
" Our buffer has vanished!? Open a new window.
|
||||||
echomsg "download buffer disappeared, opening a new one"
|
echomsg "download buffer disappeared, opening a new one"
|
||||||
new
|
new
|
||||||
setlocal bin fenc=
|
setlocal bin fenc=
|
||||||
else
|
else
|
||||||
exe winnr . "wincmd w"
|
exe winnr . "wincmd w"
|
||||||
endif
|
endif
|
||||||
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
|
||||||
|
|
||||||
let fname = a:lang . '.ascii.spl'
|
let fname = a:lang . '.ascii.spl'
|
||||||
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
|
||||||
|
|
||||||
let msg = "In which directory do you want to write the file:"
|
if len(dirlist) == 1
|
||||||
for i in range(len(dirlist))
|
let dirchoice = 0
|
||||||
let msg .= "\n" . (i + 1) . '. ' . dirlist[i]
|
else
|
||||||
endfor
|
let msg = "In which directory do you want to write the file:"
|
||||||
let dirchoice = confirm(msg, dirchoices) - 2
|
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 dirchoice >= 0
|
||||||
if exists('*fnameescape')
|
if exists('*fnameescape')
|
||||||
let dirname = fnameescape(dirlist[dirchoice])
|
let dirname = fnameescape(dirlist[dirchoice])
|
||||||
else
|
else
|
||||||
let dirname = escape(dirlist[dirchoice], ' ')
|
let dirname = escape(dirlist[dirchoice], ' ')
|
||||||
endif
|
endif
|
||||||
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 fname = substitute(fname, '\.spl$', '.sug', '')
|
||||||
let msg .= "but it uses quite a bit of memory."
|
echo 'Downloading ' . fname . '...'
|
||||||
if confirm(msg, "&No\n&Yes") == 2
|
call spellfile#Nread(fname)
|
||||||
g/^/d
|
if getline(2) =~ 'VIMsug'
|
||||||
let fname = substitute(fname, '\.spl$', '.sug', '')
|
1d_
|
||||||
echo 'Downloading ' . fname . '...'
|
exe "write " . dirname . '/' . fname
|
||||||
call spellfile#Nread(fname)
|
set nomod
|
||||||
if getline(2) =~ 'VIMsug'
|
else
|
||||||
1d
|
echo 'Download failed'
|
||||||
exe "write " . dirname . '/' . fname
|
" Go back to our own buffer/window, Nread() may have taken us to
|
||||||
set nomod
|
" another window.
|
||||||
else
|
if newbufnr != winbufnr(0)
|
||||||
echo 'Sorry, downloading failed'
|
let winnr = bufwinnr(newbufnr)
|
||||||
" Go back to our own buffer/window, Nread() may have taken us to
|
if winnr != -1
|
||||||
" another window.
|
exe winnr . "wincmd w"
|
||||||
if newbufnr != winbufnr(0)
|
endif
|
||||||
let winnr = bufwinnr(newbufnr)
|
endif
|
||||||
if winnr != -1
|
if newbufnr == winbufnr(0)
|
||||||
exe winnr . "wincmd w"
|
set nomod
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
if newbufnr == winbufnr(0)
|
|
||||||
set nomod
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user