From b34b8a2b3131c760599f4217a185ebd51d9e4e28 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Jun 2019 18:09:09 +1200 Subject: Throw away the path absolution hooks Too awkward, not worth it, especially the mess it makes of alternate files. --- autoload/write_mkpath.vim | 42 +----------------------------------------- doc/write_mkpath.txt | 9 +++------ plugin/write_mkpath.vim | 4 +--- 3 files changed, 5 insertions(+), 50 deletions(-) diff --git a/autoload/write_mkpath.vim b/autoload/write_mkpath.vim index 6c55e78..8a3ac9d 100644 --- a/autoload/write_mkpath.vim +++ b/autoload/write_mkpath.vim @@ -1,35 +1,6 @@ -" Handle a buffer created for a new file; anchor its filename to be absolute -" if it's relative and the directory path doesn't yet exist; this stops Vim -" trying to save in the wrong place if the user changes directory before -" writing the buffer -function! write_mkpath#New(path) abort - - " We don't have fnameescape(); this old Vim < v7.1.299 is likely too buggy - " to handle the buffer renaming for paths safely, so better not to mess with - " it and instead to stick with suboptimal but consistent behaviour - if !exists('*fnameescape') - return - endif - - " Path exists, or is absolute; we don't need to do anything - if isdirectory(fnamemodify(a:path, ':h')) - \ || s:Absolute(a:path) - return - endif - - " Set filename to absolute path using :file {name}; do it silently so that - " the nice name remains displayed to the user. Record the name of the - " alternate buffer first, so we can put it back after :file messes with it. - execute 'silent file '.fnameescape(getcwd().'/'.a:path) - - " Wipe the unlisted alternate buffer that :file leaves behind - bwipe # - -endfunction - " Handle a :write operation; prompt for directory creation if needed with " 'confirm', force it with :write! -function! write_mkpath#Write(path) abort +function! write_mkpath#(path) abort " Get all directory elements leading up to directory let dir = fnamemodify(a:path, ':h') @@ -56,14 +27,3 @@ function! write_mkpath#Write(path) abort endif endfunction - -" Clumsy and probably wrong helper function to check if a path is absolute -function! s:Absolute(path) abort - if has('unix') - return a:path =~# '^/' " Leading slash on Unix - elseif has('win32') || has('win64') - return a:path =~# '^\u:' " e.g. C: -- I'm not sure this is right - else - echoerr 'Unrecognised operating system' - endif -endfunction diff --git a/doc/write_mkpath.txt b/doc/write_mkpath.txt index 3416629..9424184 100644 --- a/doc/write_mkpath.txt +++ b/doc/write_mkpath.txt @@ -20,12 +20,9 @@ This plugin only loads if 'compatible' is not set. CAVEATS *write_mkpath-caveats* -In Vim 7.0 and 7.1, the path will be created relative to Vim's working -directory at the time of the write operation, which might not be the same as -the working directory when the buffer was first created, e.g. after a |:cd| -change. This is worked around safely in Vim 7.2 and newer by calculating an -absolute path for new buffers with nonexistent relative paths, but filename -escaping bugs in earlier versions preclude the same fix in older versions. +The path will be created relative to Vim's working directory at the time of +the write operation, which might not be the same as the working directory when +the buffer was first created, e.g. after a |:cd| change. AUTHOR *write_mkpath-author* diff --git a/plugin/write_mkpath.vim b/plugin/write_mkpath.vim index c7c9543..ea53191 100644 --- a/plugin/write_mkpath.vim +++ b/plugin/write_mkpath.vim @@ -12,8 +12,6 @@ endif " Check path to every file before it's saved augroup write_mkpath autocmd! - autocmd BufNewFile * - \ call write_mkpath#New(expand('')) autocmd BufWritePre * - \ call write_mkpath#Write(expand('')) + \ call write_mkpath#(expand('')) augroup END -- cgit v1.2.3 From 9659e5828e726dc9f958680a90f8488b3184023b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Jun 2019 18:10:06 +1200 Subject: Wrap and quote attribution in README and :help doc --- README.md | 7 +++++-- doc/write_mkpath.txt | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 20032ed..e93b5bd 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,13 @@ confirm that Vim should create any missing path elements. On `:write!` or `:w!`, the path will be created automatically, ignoring the value of `'confirm'`. +Inspired by Damian Conway's [`automkdir.vim` plugin][1]. + License ------- -Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +Copyright (c) [Tom Ryder][2]. Distributed under the same terms as Vim itself. See `:help license`. -[1]: https://sanctum.geek.nz/ +[1]: https://github.com/thoughtstream/Damian-Conway-s-Vim-Setup/blob/cbe1fb5/plugin/automkdir.vim +[2]: https://sanctum.geek.nz/ diff --git a/doc/write_mkpath.txt b/doc/write_mkpath.txt index 9424184..76823d9 100644 --- a/doc/write_mkpath.txt +++ b/doc/write_mkpath.txt @@ -26,8 +26,8 @@ the buffer was first created, e.g. after a |:cd| change. AUTHOR *write_mkpath-author* -Written and maintained by Tom Ryder . -Inspired by Damian Conway's automkdir.vim plugin: +Written and maintained by Tom Ryder . Inspired by Damian +Conway's `automkdir.vim` plugin: LICENSE *write_mkpath-license* -- cgit v1.2.3 From 4aec5858a6488113689d0301300b24162473f901 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Jun 2019 18:11:43 +1200 Subject: Bump VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 45a1b3f..227cea2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.2 +2.0.0 -- cgit v1.2.3