1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
set spellfile<
let spelllangs = s:SplitOption(&spelllang)
if !len(spelllangs) || spelllangs[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 = tr(expand('%:p'), '/', '%')
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
|