From 651846f32dbcf16d326ac456a2a7579d20247625 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 7 Jul 2019 00:08:56 +1200 Subject: Rearrange command/function call semantics --- vim/autoload/path.vim | 9 +++++---- vim/vimrc | 15 +++++++-------- 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() +command! -bang -bar -complete=dir -nargs=1 CreatePath + \ call path#Create(expand(), ==# '!') " 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 -- cgit v1.2.3