From 13d56da45a47f73b55aa5544aafe68d36774b51d Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 17 Jun 2019 00:47:52 +1200 Subject: Overhaul local Vim spellfile word list plugin --- vim/autoload/spellfile_local.vim | 79 +++++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 9 deletions(-) (limited to 'vim/autoload') diff --git a/vim/autoload/spellfile_local.vim b/vim/autoload/spellfile_local.vim index aafe64ef..081b2970 100644 --- a/vim/autoload/spellfile_local.vim +++ b/vim/autoload/spellfile_local.vim @@ -1,11 +1,72 @@ +function! s:SplitOption(string) abort + return map( + \ split(a:string, '\\\@ zG 2zg - xnoremap zG 2zg + + set spellfile< + + let spelllangs = s:SplitOption(&spelllang) + if !len(spelllangs) || &spelllang[0] ==# '' + echoerr 'Blank ''spelllang''' + endif + let spelllang = substitute(spelllangs[0], '_.*', '', '') + + if !len(&encoding) + echoerr 'Blank ''encoding''' + endif + + let spellfiles = s:SplitOption(&spellfile) + if len(spellfiles) != 1 || spellfiles[0] ==# '' + return + endif + + let spelldir = fnamemodify(spellfiles[0], ':h') + if spelldir ==# '' + echoerr 'Blank directory' + endif + + try + let path = substitute(expand('%:p'), '/', '%', 'g') + if path ==# '' + echoerr 'Blank path' + endif + call s:Establish(spelldir.'/path') + call add(spellfiles, spelldir.'/path/'.join([ + \ path + \,spelllang + \,&encoding + \,'add' + \], '.')) + + if &filetype ==# '' + echoerr 'Blank filetype' + endif + call s:Establish(spelldir.'/filetype') + call add(spellfiles, spelldir.'/filetype/'.join([ + \ &filetype + \,spelllang + \,&encoding + \,'add' + \], '.')) + catch + endtry + + let &l:spellfile = s:JoinOption(spellfiles) + endfunction -- cgit v1.2.3