commit ad0c21a445d1d022741d464d3023629cb6b95bf1
parent 2efc84d005bbfbb65731edc87495278cdb94b778
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu, 17 Jul 2025 16:24:10 +0800
vim-patch:470317f: runtime(tar): remove dependency on netrw#WinPath, include mapping doc
related: vim/vim#17124
https://github.com/vim/vim/commit/470317f78b110b4559cecb26039b5f93447c1bf0
Co-authored-by: Christian Brabandt <cb@256bit.org>
Diffstat:
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/runtime/autoload/tar.vim b/runtime/autoload/tar.vim
@@ -14,6 +14,7 @@
" 2025 Mar 02 by Vim Project: escape the filename before using :read
" 2025 Mar 02 by Vim Project: determine the compression using readblob()
" instead of shelling out to file(1)
+" 2025 Apr 16 by Vim Project: decouple from netrw by adding s:WinPath()
"
" Contains many ideas from Michael Toren's <tar.vim>
"
@@ -146,7 +147,7 @@ fun! tar#Browse(tarfile)
let lastline= line("$")
call setline(lastline+1,'" tar.vim version '.g:loaded_tar)
call setline(lastline+2,'" Browsing tarfile '.a:tarfile)
- call setline(lastline+3,'" Select a file with cursor and press ENTER')
+ call setline(lastline+3,'" Select a file with cursor and press ENTER, "x" to extract a file')
keepj $put =''
keepj sil! 0d
keepj $
@@ -617,7 +618,7 @@ fun! tar#Extract()
let tarball = expand("%")
let tarbase = substitute(tarball,'\..*$','','')
- let extractcmd= netrw#WinPath(g:tar_extractcmd)
+ let extractcmd= s:WinPath(g:tar_extractcmd)
if filereadable(tarbase.".tar")
call system(extractcmd." ".shellescape(tarbase).".tar ".shellescape(fname))
if v:shell_error != 0
@@ -768,6 +769,25 @@ fun! s:Header(fname)
return "unknown"
endfun
+" ---------------------------------------------------------------------
+" s:WinPath: {{{2
+fun! s:WinPath(path)
+ if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
+ " remove cygdrive prefix, if present
+ let path = substitute(a:path, '/cygdrive/\(.\)', '\1:', '')
+ " remove trailing slash (Win95)
+ let path = substitute(path, '\(\\\|/\)$', '', 'g')
+ " remove escaped spaces
+ let path = substitute(path, '\ ', ' ', 'g')
+ " convert slashes to backslashes
+ let path = substitute(path, '/', '\', 'g')
+ else
+ let path = a:path
+ endif
+
+ return path
+endfun
+
" =====================================================================
" Modelines And Restoration: {{{1
let &cpo= s:keepcpo
diff --git a/runtime/doc/pi_tar.txt b/runtime/doc/pi_tar.txt
@@ -57,6 +57,15 @@ Copyright 2005-2017: *tar-copyright*
let g:loaded_tarPlugin= 1
let g:loaded_tar = 1
<
+ *tar-mappings*
+ MAPPINGS~
+
+ The following (buffer-local) mappings are available in a tar buffer:
+
+ <CR> Open selected file for editing, any changes will be
+ written back to the archive.
+ <LeftMouse> same as <CR>
+ x Extract selected file.
==============================================================================
3. Options *tar-options*