0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

runtime(tar): remove dependency on netrw#WinPath, include mapping doc

related: #17124

Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Christian Brabandt
2025-04-16 17:13:28 +02:00
parent 839fd94265
commit 470317f78b
3 changed files with 35 additions and 5 deletions

View File

@@ -14,6 +14,7 @@
" 2025 Mar 02 by Vim Project: escape the filename before using :read " 2025 Mar 02 by Vim Project: escape the filename before using :read
" 2025 Mar 02 by Vim Project: determine the compression using readblob() " 2025 Mar 02 by Vim Project: determine the compression using readblob()
" instead of shelling out to file(1) " 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> " Contains many ideas from Michael Toren's <tar.vim>
" "
@@ -146,7 +147,7 @@ fun! tar#Browse(tarfile)
let lastline= line("$") let lastline= line("$")
call setline(lastline+1,'" tar.vim version '.g:loaded_tar) call setline(lastline+1,'" tar.vim version '.g:loaded_tar)
call setline(lastline+2,'" Browsing tarfile '.a:tarfile) 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 $put =''
keepj sil! 0d keepj sil! 0d
keepj $ keepj $
@@ -615,7 +616,7 @@ fun! tar#Extract()
let tarball = expand("%") let tarball = expand("%")
let tarbase = substitute(tarball,'\..*$','','') let tarbase = substitute(tarball,'\..*$','','')
let extractcmd= netrw#WinPath(g:tar_extractcmd) let extractcmd= s:WinPath(g:tar_extractcmd)
if filereadable(tarbase.".tar") if filereadable(tarbase.".tar")
call system(extractcmd." ".shellescape(tarbase).".tar ".shellescape(fname)) call system(extractcmd." ".shellescape(tarbase).".tar ".shellescape(fname))
if v:shell_error != 0 if v:shell_error != 0
@@ -765,6 +766,25 @@ fun! s:Header(fname)
return "unknown" return "unknown"
endfun 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
" --------------------------------------------------------------------- " ---------------------------------------------------------------------
" tar#Vimuntar: installs a tarball in the user's .vim / vimfiles directory {{{2 " tar#Vimuntar: installs a tarball in the user's .vim / vimfiles directory {{{2
fun! tar#Vimuntar(...) fun! tar#Vimuntar(...)
@@ -786,7 +806,7 @@ fun! tar#Vimuntar(...)
if simplify(curdir) != simplify(vimhome) if simplify(curdir) != simplify(vimhome)
" copy (possibly compressed) tarball to .vim/vimfiles " copy (possibly compressed) tarball to .vim/vimfiles
call system(netrw#WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome)) call system(s:WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome))
exe "cd ".fnameescape(vimhome) exe "cd ".fnameescape(vimhome)
endif endif
@@ -808,7 +828,7 @@ fun! tar#Vimuntar(...)
else else
call vimball#Decompress(tartail,0) call vimball#Decompress(tartail,0)
endif endif
let extractcmd= netrw#WinPath(g:tar_extractcmd) let extractcmd= s:WinPath(g:tar_extractcmd)
call system(extractcmd." ".shellescape(tarbase.".tar")) call system(extractcmd." ".shellescape(tarbase.".tar"))
" set up help " set up help

View File

@@ -1,4 +1,4 @@
*pi_tar.txt* For Vim version 9.1. Last change: 2024 May 11 *pi_tar.txt* For Vim version 9.1. Last change: 2025 Mar 16
+====================+ +====================+
| Tar File Interface | | Tar File Interface |
@@ -74,6 +74,15 @@ Copyright 2005-2017: *tar-copyright*
let g:loaded_tarPlugin= 1 let g:loaded_tarPlugin= 1
let g:loaded_tar = 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* 3. Options *tar-options*

View File

@@ -10681,6 +10681,7 @@ tar-contents pi_tar.txt /*tar-contents*
tar-copyright pi_tar.txt /*tar-copyright* tar-copyright pi_tar.txt /*tar-copyright*
tar-history pi_tar.txt /*tar-history* tar-history pi_tar.txt /*tar-history*
tar-manual pi_tar.txt /*tar-manual* tar-manual pi_tar.txt /*tar-manual*
tar-mappings pi_tar.txt /*tar-mappings*
tar-options pi_tar.txt /*tar-options* tar-options pi_tar.txt /*tar-options*
tar-usage pi_tar.txt /*tar-usage* tar-usage pi_tar.txt /*tar-usage*
tcl if_tcl.txt /*tcl* tcl if_tcl.txt /*tcl*