aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-05-30 16:42:01 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-05-30 16:42:01 +1200
commit37d6dc8b29a20eca098e30556a89cde09e8b59ea (patch)
tree25a776ee55e5bd547106ab3d0830bfc5b2c127ad
parentFirst version (diff)
parentBump VERSION (diff)
downloadvim-write-mkpath-37d6dc8b29a20eca098e30556a89cde09e8b59ea.tar.gz
vim-write-mkpath-37d6dc8b29a20eca098e30556a89cde09e8b59ea.zip
Merge branch 'release/v0.2.0'v0.2.0
* release/v0.2.0: Give credit to DCONWAY for the basis of the idea Extend to respect 'confirm' if set
-rw-r--r--README.md10
-rw-r--r--VERSION2
-rw-r--r--autoload/write_mkpath.vim21
-rw-r--r--doc/write_mkpath.txt15
4 files changed, 42 insertions, 6 deletions
diff --git a/README.md b/README.md
index aefaaa4..ed9be85 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,14 @@
write\_mkpath.vim
=================
-If `:write!` is issued for a file that has nonexistent path elements, create
-the full path with `mkdir()` before saving.
+This plugin supports creation of any missing path elements in the path to a
+buffer's filename before the buffer is written.
+
+If 'confirm' is enabled on `:write` or `:w`, the user will be prompted to
+confirm that Vim should create any missing path elements.
+
+On `:write!` or `:w!`, the path will be created automatically, ignoring the
+value of 'confirm'.
License
-------
diff --git a/VERSION b/VERSION
index 6e8bf73..0ea3a94 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.0
+0.2.0
diff --git a/autoload/write_mkpath.vim b/autoload/write_mkpath.vim
index 36d3501..94fe21a 100644
--- a/autoload/write_mkpath.vim
+++ b/autoload/write_mkpath.vim
@@ -1,5 +1,24 @@
function! write_mkpath#(path) abort
- if v:cmdbang && !isdirectory(a:path)
+
+ " Path exists, we don't need to do anything
+ if isdirectory(a:path)
+ return
+ endif
+
+ " If :write! was issued, we'll try to create the path; failing that, if
+ " 'confirm' is enabled, and the user responds affirmatively to the prompt,
+ " that will do, too. Otherwise, we will allow the write to fail.
+ if v:cmdbang
+ let l:mkpath = 1
+ elseif &confirm
+ let l:mkpath = confirm('Create path '.a:path.'?', "&Yes\n&No") == 1
+ else
+ let l:mkpath = 0
+ endif
+
+ " If we decided to attempt a path creation, do so
+ if l:mkpath
call mkdir(a:path, 'p')
endif
+
endfunction
diff --git a/doc/write_mkpath.txt b/doc/write_mkpath.txt
index 8d7bcc2..8ba3709 100644
--- a/doc/write_mkpath.txt
+++ b/doc/write_mkpath.txt
@@ -2,8 +2,17 @@
DESCRIPTION *write_mkpath*
-If |:write!| is issued for a file that has nonexistent path elements, create
-the full path with |mkdir()| before saving.
+This plugin supports creation of any missing path elements in the path to a
+buffer's filename before the buffer is written.
+
+If 'confirm' is enabled on |:write| or |:w|, the user will be prompted to
+confirm that Vim should create any missing path elements.
+
+On |:write!| or |:w!|, the path will be created automatically, ignoring the
+value of 'confirm'.
+
+The directory creation is done using the |mkdir()| command, with its {path}
+argument set to 'p' to create the elements recursively.
REQUIREMENTS *write_mkpath-requirements*
@@ -12,6 +21,8 @@ This plugin only loads if 'compatible' is not set.
AUTHOR *write_mkpath-author*
Written and maintained by Tom Ryder <tom@sanctum.geek.nz>.
+Inspired by Damian Conway's automkdir.vim plugin:
+<https://github.com/thoughtstream/Damian-Conway-s-Vim-Setup/blob/cbe1fb5/plugin/automkdir.vim>
LICENSE *write_mkpath-license*