diff options
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | autoload/spellfile_local.vim | 42 | ||||
-rw-r--r-- | doc/spellfile_local.txt | 2 | ||||
-rw-r--r-- | plugin/spellfile_local.vim | 4 |
4 files changed, 25 insertions, 25 deletions
@@ -1 +1 @@ -1.0.1 +2.0.0 diff --git a/autoload/spellfile_local.vim b/autoload/spellfile_local.vim index 596d997..dc9d2cc 100644 --- a/autoload/spellfile_local.vim +++ b/autoload/spellfile_local.vim @@ -15,24 +15,24 @@ function! spellfile_local#() abort return endif let lang = split(spelllangs[0], '_')[0] - let encoding = &encoding " Make a list of all the spellfile names for which we want to search in - " every directory; the first is the normal lang.encoding.add, the second is - " filename.lang.encoding.add, and the third, if there's a filetype set, is + " every directory; first is the normal lang.encoding.add, then if there's + " a path set filename.lang.encoding.add, and then if there's a filetype set, " filetype.lang.encoding.add. " - let basenames = [s:Filename([lang, encoding, 'add'])] - let path = expand('<afile>:p') - call add( - \ basenames, - \ s:Filename(['path', path, lang, encoding, 'add']) - \) - let filetype = &filetype - if filetype !=# '' + let basenames = [s:Filename([lang, &encoding, 'add'])] + let path = expand('%:p') + if path !=# '' + call add( + \ basenames, + \ s:Filename(['path', path, lang, &encoding, 'add']) + \) + endif + if &filetype !=# '' call add( \ basenames, - \ s:Filename(['filetype', filetype, lang, encoding, 'add']) + \ s:Filename(['filetype', &filetype, lang, &encoding, 'add']) \) endif @@ -71,8 +71,9 @@ function! spellfile_local#() abort " Attempt to create the first directory in the list if it doesn't exist " already. Just let any error happen and reach the user. " - if !isdirectory(dirnames[0]) - call mkdir(dirnames[0], 'p', 0700) + let dirname = expand(dirnames[0]) + if !isdirectory(dirname) + call mkdir(dirname, 'p', 0700) endif " Now we'll actually combine those two together to make a long list of @@ -89,15 +90,12 @@ function! spellfile_local#() abort endfunction " Escape a path for use as a valid option file name; replace any characters -" not in 'isfname' with percent symbols +" that won't work nicely as filenames with percent signs function! s:Filename(parts) abort - let filename = '' - for char in split(join(a:parts, '.'), '\zs') - let filename .= (char !=# '_' && char !=# '/' && char =~# '^\f$') - \ ? char - \ : '%' - endfor - return filename + let pat = has('win32') || has('win64') + \ ? '\c[^[:fname:]]\|\\' + \ : '\c[^[:fname:]]\|/' + return substitute(join(a:parts, '.'), pat, '%', 'g') endfunction " Join a list of strings into a comma-separated option diff --git a/doc/spellfile_local.txt b/doc/spellfile_local.txt index 37dbf81..e54a73b 100644 --- a/doc/spellfile_local.txt +++ b/doc/spellfile_local.txt @@ -1,4 +1,4 @@ -*spellfile_local.txt* For Vim version 7.0 Last change: 2020 May 15 +*spellfile_local.txt* For Vim version 8.0 Last change: 2023 Apr 6 DESCRIPTION *spellfile_local* diff --git a/plugin/spellfile_local.vim b/plugin/spellfile_local.vim index 0730775..be2956c 100644 --- a/plugin/spellfile_local.vim +++ b/plugin/spellfile_local.vim @@ -6,7 +6,7 @@ " Author: Tom Ryder <tom@sanctum.geek.nz> " License: Same as Vim itself " -if exists('loaded_spellfile_local') || &compatible +if exists('loaded_spellfile_local') || &compatible || v:version < 800 finish endif let loaded_spellfile_local = 1 @@ -17,4 +17,6 @@ let loaded_spellfile_local = 1 augroup spellfile_local autocmd BufFilePost,BufNewFile,BufRead,EncodingChanged,FileType * \ call spellfile_local#() + autocmd OptionSet spelllang + \ call spellfile_local#() augroup END |