aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-07-07 00:08:56 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-07-07 00:18:51 +1200
commit651846f32dbcf16d326ac456a2a7579d20247625 (patch)
tree307fd80094cab8e4171809ae4cf4a63994c8238b
parentHandle path expansion in CreatePath (diff)
downloaddotfiles-651846f32dbcf16d326ac456a2a7579d20247625.tar.gz
dotfiles-651846f32dbcf16d326ac456a2a7579d20247625.zip
Rearrange command/function call semantics
-rw-r--r--vim/autoload/path.vim9
-rw-r--r--vim/vimrc15
2 files changed, 12 insertions, 12 deletions
diff --git a/vim/autoload/path.vim b/vim/autoload/path.vim
index 410cd294..83102138 100644
--- a/vim/autoload/path.vim
+++ b/vim/autoload/path.vim
@@ -2,10 +2,11 @@ function! path#Create(name, ...) abort
if a:0 > 2
echoerr 'Too many arguments'
endif
- let name = expand(a:name)
- if isdirectory(name)
+ if isdirectory(a:name)
return 1
endif
- let prot = a:0 >= 1 ? a:1 : 0755
- return mkdir(name, 'p', prot)
+ let name = a:name
+ let path = 'p'
+ let prot = a:0 == 1 && a:1 ? 0700 : 0755
+ return mkdir(name, path, prot)
endfunction
diff --git a/vim/vimrc b/vim/vimrc
index ddece845..99afc22f 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -107,11 +107,10 @@ endif
" We need a command to reliably establish a full path, whether or not the
" directories already exist. We create a wrapper for the autolated function
" path#Create() with similar calling conventions to mkdir(), but with the ‘p’
-" value for the second parameter {prot} forced on. You can still optionally
-" provide alternative permissions in the second argument.
+" value for the second parameter {prot} forced on.
"
-command! -bar -complete=dir -nargs=+ CreatePath
- \ call path#Create(<f-args>)
+command! -bang -bar -complete=dir -nargs=1 CreatePath
+ \ call path#Create(expand(<q-args>), <q-bang> ==# '!')
" Now that we have a way to create directories if they don’t already exist,
" let’s apply it for the first time to the user runtime directory. Note that
@@ -182,7 +181,7 @@ set backup
execute 'set backupdir^='.escape#Arg(escape#Item(
\ $MYVIM.'/backup'.(has('patch-8.1.251') ? '//' : ''),
\))
-CreatePath $MYVIM/backup 0700
+CreatePath! $MYVIM/backup
" Files in certain directories on Unix-compatible filesystems should not be
" backed up, for security reasons. This is particularly important if editing
@@ -216,10 +215,10 @@ endif
" trailing slashes to the path to prompt Vim to use the full escaped path in
" its name, in order to avoid filename collisions, since the 'directory'
" option has supported that hint for much longer than 'backupdir' has. We
-" apply CreatePath() to attempt to create the path, if needed.
+" apply path#Create() to attempt to create the path, if needed.
"
execute 'set directory^='.escape#Arg(escape#Item($MYVIM.'/swap//'))
-CreatePath $MYVIM/swap 0700
+CreatePath! $MYVIM/swap
" Keep tracked undo history for files permanently, in a dedicated cache
" directory, so that the u/:undo and CTRL-R/:redo commands will work between
@@ -237,7 +236,7 @@ CreatePath $MYVIM/swap 0700
if has('persistent_undo')
set undofile
execute 'set undodir^='.escape#Arg(escape#Item($MYVIM.'/undo//'))
- CreatePath $MYVIM/undo 0700
+ CreatePath! $MYVIM/undo
endif
" Now that we have a bit more confidence in our runtime environment, set up