aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-05-30 00:42:27 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-05-30 00:42:27 +1200
commit53f1a5c423af025ea02ad3ee92099100994b8cb9 (patch)
tree86a4882170aeae47d9d8f4bc05e84b0f8337b7ef
downloadvim-write-mkpath-0.1.0.tar.gz (sig)
vim-write-mkpath-0.1.0.zip
First versionv0.1.0
-rw-r--r--README.md13
-rw-r--r--VERSION1
-rw-r--r--autoload/write_mkpath.vim5
-rw-r--r--doc/write_mkpath.txt20
-rw-r--r--plugin/write_mkpath.vim17
5 files changed, 56 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..aefaaa4
--- /dev/null
+++ b/README.md
@@ -0,0 +1,13 @@
+write\_mkpath.vim
+=================
+
+If `:write!` is issued for a file that has nonexistent path elements, create
+the full path with `mkdir()` before saving.
+
+License
+-------
+
+Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself.
+See `:help license`.
+
+[1]: https://sanctum.geek.nz/
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..6e8bf73
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.1.0
diff --git a/autoload/write_mkpath.vim b/autoload/write_mkpath.vim
new file mode 100644
index 0000000..36d3501
--- /dev/null
+++ b/autoload/write_mkpath.vim
@@ -0,0 +1,5 @@
+function! write_mkpath#(path) abort
+ if v:cmdbang && !isdirectory(a:path)
+ call mkdir(a:path, 'p')
+ endif
+endfunction
diff --git a/doc/write_mkpath.txt b/doc/write_mkpath.txt
new file mode 100644
index 0000000..8d7bcc2
--- /dev/null
+++ b/doc/write_mkpath.txt
@@ -0,0 +1,20 @@
+*write_mkpath.txt* For Vim version 7.0 Last change: 2019 May 28
+
+DESCRIPTION *write_mkpath*
+
+If |:write!| is issued for a file that has nonexistent path elements, create
+the full path with |mkdir()| before saving.
+
+REQUIREMENTS *write_mkpath-requirements*
+
+This plugin only loads if 'compatible' is not set.
+
+AUTHOR *write_mkpath-author*
+
+Written and maintained by Tom Ryder <tom@sanctum.geek.nz>.
+
+LICENSE *write_mkpath-license*
+
+Licensed for distribution under the same terms as Vim itself (see |license|).
+
+ vim:tw=78:ts=8:ft=help:norl:
diff --git a/plugin/write_mkpath.vim b/plugin/write_mkpath.vim
new file mode 100644
index 0000000..4a47d70
--- /dev/null
+++ b/plugin/write_mkpath.vim
@@ -0,0 +1,17 @@
+"
+" write_mkpath: If :write! is issued for a file that has nonexistent path
+" elements, create the full path with mkdir() before saving.
+"
+" Author: Tom Ryder <tom@sanctum.geek.nz>
+" License: Same as Vim itself
+"
+if exists('loaded_write_mkpath') || &compatible || v:version < 700
+ finish
+endif
+
+" Check path to every file before it's saved
+augroup write_mkpath
+ autocmd!
+ autocmd BufWritePre *
+ \ call write_mkpath#(expand('<afile>:p:h'))
+augroup END