diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-17 00:53:17 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-06-17 00:53:17 +1200 |
commit | b7a2d67f38b947dfac366487a327c4c10c67aaa5 (patch) | |
tree | 10743f12a469f6b256c53579731296f0a5401c98 /vim/autoload/spellfile_local.vim | |
parent | Merge branch 'release/v6.20.0' (diff) | |
parent | Update dotfiles(7) manual page (diff) | |
download | dotfiles-2af6f6dd662d1e63dd261565aa7bd261194a1f0b.tar.gz (sig) dotfiles-2af6f6dd662d1e63dd261565aa7bd261194a1f0b.zip |
Merge branch 'release/v6.21.0'v6.21.0
* release/v6.21.0:
Update dotfiles(7) manual page
Spelling and capitalisation fixes
Add load guards to Vim plugins not spun out yet
Adjust comma position in broken lines
Overhaul local Vim spellfile word list plugin
Refactor select_old_files.vim to allow count
Enhance load guard or select_old_files.vim
Add <Plug>SelectOldFiles mapping
Add a rough normal mode map to repeat with bang
Refactor and fix arg errors in put_date.vim plugin
Consolidate utc.vim and put_date.vim into latter
Document choice of format for PutDate()
More comment corrections
Diffstat (limited to 'vim/autoload/spellfile_local.vim')
-rw-r--r-- | vim/autoload/spellfile_local.vim | 79 |
1 files changed, 70 insertions, 9 deletions
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, '\\\@<!,[, ]*') + \,"substitute(v:val, '\\\\,', '', 'g')" + \) +endfunction + +function! s:JoinOption(list) abort + return join(map( + \ a:list + \,"substitute(v:val, '\\\\\\@<!,', '\\\\,', 'g')" + \), ',') +endfunction + +function! s:Establish(path) abort + return isdirectory(a:path) + \ || exists('*mkdir') && mkdir(a:path, 'p', 0700) +endfunction + function! spellfile_local#() abort - let spellfile = join([ - \ substitute(expand('%:p'), '[^0-9A-Za-z_.-]', '%', 'g'), - \ substitute(v:lang, '_.*', '', ''), - \ &encoding - \ ], '.') . '.add' - Establish $MYVIM/cache/spell/local - execute 'setlocal spellfile+=$MYVIM/cache/spell/local/'.spellfile - nnoremap <buffer> zG 2zg - xnoremap <buffer> 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 |