diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-05-15 00:30:27 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-05-15 00:30:27 +1200 |
commit | 7152e065b77771718a4dd93a469ff6c060fa2756 (patch) | |
tree | e425c281668eac6b8fa4f7a90a610ea2215cd374 | |
parent | Merge branch 'release/v0.3.0' (diff) | |
download | vim-spellfile-local-7152e065b77771718a4dd93a469ff6c060fa2756.tar.gz vim-spellfile-local-7152e065b77771718a4dd93a469ff6c060fa2756.zip |
Factor out error when no custom dirs set
Failure of testing here
-rw-r--r-- | autoload/spellfile_local.vim | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/autoload/spellfile_local.vim b/autoload/spellfile_local.vim index 618a354..9734988 100644 --- a/autoload/spellfile_local.vim +++ b/autoload/spellfile_local.vim @@ -36,34 +36,36 @@ function! spellfile_local#() abort let dirnames = [] " If we have a list of directories to use as the base for 'spellfile' /spell - " subdirectories, we'll add all of them to the list, and *attempt* to create - " the first one if it doesn't exist--but it's not fatal if we can't; this is - " intended to be suitable for passing in XDG basedirs + " subdirectories, we'll add all of them to the list with /spell suffixed, + " regardless of whether Vim can write to them. " if exists('g:spellfile_local_dirs') && !empty(g:spellfile_local_dirs) for path in g:spellfile_local_dirs - call add(dirnames, path.'/spell') + call add(dirnames, join([path, 'spell'], '/')) endfor - if (!isdirectory(dirnames[0])) - call mkdir(dirnames[0], 'p', 0700) - endif " Failing that, do what Vim does by default: use the first *writeable* entry - " in 'runtimepath', attempting to-create the /spell subdirectory within. If - " none of them are writable, we raise an exception. + " in 'runtimepath'. If none of them are writable, we raise an exception. " else for path in s:OptionSplit(&runtimepath) - if filewritable(path) - let spelldir = path.'/spell' - if isdirectory(spelldir) - \ || mkdir(spelldir, 'p', 0700) - call add(dirnames, spelldir) - break - endif + if filewritable(path) != 2 + continue endif + call add(dirnames, join([path, 'spell'], '/')) + break endfor - throw 'No writable runtime dirs for ''spellfile''' + if empty(dirnames) + echoerr 'No writable runtime dirs for ''spellfile''' + return + endif + endif + + " Attempt to create the first directory in the list if it doesn't exist + " already. Just let the error happen if it does. + " + if !isdirectory(dirnames[0]) + call mkdir(dirnames[0], 'p', 0700) endif " Now we'll actually combine those two together to make a long list of |