runtime(netrw): runtime(netrw): upstream snapshot of v178

relevant commits:
- refactor: netrw#own#Deprecate -> netrw#msg#Deprecate
- refactor: netrw#own#PathJoin -> netrw#fs#PathJoin
- fix: typos
- refactor: netrw#own#Open -> netrw#os#Open
- deprecate!: netrw#WinPath
- refactor: netrw#WinPath -> netrw#fs module
- refactor: s:ShellEscape -> netrw#os module
- refactor: s:NetrwExe -> netrw#os module
- refactor: s:NetrwGlob -> netrw#fs module
- refactor: s:NetrwGetcwd -> netrw#fs module
- refactor: s:NetrwFullPath -> netrw#fs module
- refactor: s:ComposePath -> netrw#fs module

closes: #16718

Signed-off-by: Luca Saccarola <github.e41mv@aleeas.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Luca Saccarola
2025-02-23 20:37:39 +01:00
committed by Christian Brabandt
parent b3854bfc54
commit 5b97947bbd
9 changed files with 385 additions and 338 deletions

View File

@ -816,7 +816,9 @@ RT_ALL = \
runtime/pack/dist/opt/netrw/LICENSE.txt \ runtime/pack/dist/opt/netrw/LICENSE.txt \
runtime/pack/dist/opt/netrw/README.md \ runtime/pack/dist/opt/netrw/README.md \
runtime/pack/dist/opt/netrw/autoload/netrw.vim \ runtime/pack/dist/opt/netrw/autoload/netrw.vim \
runtime/pack/dist/opt/netrw/autoload/netrw/own.vim \ runtime/pack/dist/opt/netrw/autoload/netrw/fs.vim \
runtime/pack/dist/opt/netrw/autoload/netrw/os.vim \
runtime/pack/dist/opt/netrw/autoload/netrw/msg.vim \
runtime/pack/dist/opt/netrw/autoload/netrwSettings.vim \ runtime/pack/dist/opt/netrw/autoload/netrwSettings.vim \
runtime/pack/dist/opt/netrw/autoload/netrw_gitignore.vim \ runtime/pack/dist/opt/netrw/autoload/netrw_gitignore.vim \
runtime/pack/dist/opt/netrw/doc/netrw.txt \ runtime/pack/dist/opt/netrw/doc/netrw.txt \

View File

@ -9002,6 +9002,7 @@ netrw-ctrl-h pi_netrw.txt /*netrw-ctrl-h*
netrw-ctrl-l pi_netrw.txt /*netrw-ctrl-l* netrw-ctrl-l pi_netrw.txt /*netrw-ctrl-l*
netrw-ctrl-r pi_netrw.txt /*netrw-ctrl-r* netrw-ctrl-r pi_netrw.txt /*netrw-ctrl-r*
netrw-ctrl_l pi_netrw.txt /*netrw-ctrl_l* netrw-ctrl_l pi_netrw.txt /*netrw-ctrl_l*
netrw-curdir pi_netrw.txt /*netrw-curdir*
netrw-d pi_netrw.txt /*netrw-d* netrw-d pi_netrw.txt /*netrw-d*
netrw-del pi_netrw.txt /*netrw-del* netrw-del pi_netrw.txt /*netrw-del*
netrw-delete pi_netrw.txt /*netrw-delete* netrw-delete pi_netrw.txt /*netrw-delete*

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,167 @@
" FUNCTIONS IN THIS FILE ARE MEANT TO BE USED BY NETRW.VIM AND NETRW.VIM ONLY.
" THESE FUNCTIONS DON'T COMMIT TO ANY BACKWARDS COMPATIBILITY. SO CHANGES AND
" BREAKAGES IF USED OUTSIDE OF NETRW.VIM ARE EXPECTED.
let s:slash = &shellslash ? '/' : '\'
" netrw#fs#PathJoin: Appends a new part to a path taking different systems into consideration {{{
function! netrw#fs#PathJoin(...)
let path = ""
for arg in a:000
if empty(path)
let path = arg
else
let path .= s:slash . arg
endif
endfor
return path
endfunction
" }}}
" netrw#fs#ComposePath: Appends a new part to a path taking different systems into consideration {{{
function! netrw#fs#ComposePath(base, subdir)
if has('amiga')
let ec = a:base[s:Strlen(a:base)-1]
if ec != '/' && ec != ':'
let ret = a:base . '/' . a:subdir
else
let ret = a:base.a:subdir
endif
" COMBAK: test on windows with changing to root directory: :e C:/
elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has('win32')
let ret = a:subdir
elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has('win32')
if a:base =~ '[/\\]$'
let ret = a:base . a:subdir
else
let ret = a:base . '/' . a:subdir
endif
elseif a:base =~ '^\a\{3,}://'
let urlbase = substitute(a:base, '^\(\a\+://.\{-}/\)\(.*\)$', '\1', '')
let curpath = substitute(a:base, '^\(\a\+://.\{-}/\)\(.*\)$', '\2', '')
if a:subdir == '../'
if curpath =~ '[^/]/[^/]\+/$'
let curpath = substitute(curpath, '[^/]\+/$', '', '')
else
let curpath = ''
endif
let ret = urlbase.curpath
else
let ret = urlbase.curpath.a:subdir
endif
else
let ret = substitute(a:base . '/' .a:subdir, '//', '/', 'g')
if a:base =~ '^//'
" keeping initial '//' for the benefit of network share listing support
let ret = '/' . ret
endif
let ret = simplify(ret)
endif
return ret
endfunction
" }}}
" netrw#fs#AbsPath: returns the full path to a directory and/or file {{{
function! netrw#fs#AbsPath(filename)
let filename = a:filename
if filename !~ '^/'
let filename = resolve(getcwd() . '/' . filename)
endif
if filename != "/" && filename =~ '/$'
let filename = substitute(filename, '/$', '', '')
endif
return filename
endfunction
" }}}
" netrw#fs#Cwd: get the current directory. {{{
" Change backslashes to forward slashes, if any.
" If doesc is true, escape certain troublesome characters
function! netrw#fs#Cwd(doesc)
let curdir = substitute(getcwd(), '\\', '/', 'ge')
if curdir !~ '[\/]$'
let curdir .= '/'
endif
if a:doesc
let curdir = fnameescape(curdir)
endif
return curdir
endfunction
" }}}
" netrw#fs#Glob: does glob() if local, remote listing otherwise {{{
" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
" expr : this is the expression to follow the directory. Will use netrw#fs#ComposePath()
" pare =1: remove the current directory from the resulting glob() filelist
" =0: leave the current directory in the resulting glob() filelist
function! netrw#fs#Glob(direntry, expr, pare)
if netrw#CheckIfRemote()
keepalt 1sp
keepalt enew
let keep_liststyle = w:netrw_liststyle
let w:netrw_liststyle = s:THINLIST
if s:NetrwRemoteListing() == 0
keepj keepalt %s@/@@
let filelist = getline(1,$)
q!
else
" remote listing error -- leave treedict unchanged
let filelist = w:netrw_treedict[a:direntry]
endif
let w:netrw_liststyle = keep_liststyle
else
let path= netrw#fs#ComposePath(fnameescape(a:direntry), a:expr)
if has("win32")
" escape [ so it is not detected as wildcard character, see :h wildcard
let path = substitute(path, '[', '[[]', 'g')
endif
let filelist = glob(path, 0, 1, 1)
if a:pare
let filelist = map(filelist,'substitute(v:val, "^.*/", "", "")')
endif
endif
return filelist
endfunction
" }}}
" netrw#fs#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{
function! netrw#fs#WinPath(path)
if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
" remove cygdrive prefix, if present
let path = substitute(a:path, g:netrw_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
endfunction
" }}}
" vim:ts=8 sts=4 sw=4 et fdm=marker

View File

@ -1,9 +1,7 @@
" FUNCTIONS IN THIS FILES ARE MENT TO BE USE BY NETRW.VIM AND NETRW.VIM ONLY. " FUNCTIONS IN THIS FILE ARE MEANT TO BE USED BY NETRW.VIM AND NETRW.VIM ONLY.
" THIS FUNCTIONS DON'T COMMIT TO ANY BACKWARDS COMPATABILITY. SO CHANGES AND " THESE FUNCTIONS DON'T COMMIT TO ANY BACKWARDS COMPATIBILITY. SO CHANGES AND
" BREAKAGES IF USED OUTSIDE OF NETRW.VIM ARE EXPECTED. " BREAKAGES IF USED OUTSIDE OF NETRW.VIM ARE EXPECTED.
" General: {{{
let s:deprecation_msgs = [] let s:deprecation_msgs = []
function! netrw#own#Deprecate(name, version, alternatives) function! netrw#own#Deprecate(name, version, alternatives)
" If running on neovim use vim.deprecate " If running on neovim use vim.deprecate
@ -29,33 +27,4 @@ function! netrw#own#Deprecate(name, version, alternatives)
call add(s:deprecation_msgs, a:name) call add(s:deprecation_msgs, a:name)
endfunction endfunction
function! netrw#own#Open(file) abort
if has('nvim')
call luaeval('vim.ui.open(_A[1]) and nil', [a:file])
else
call dist#vim9#Open(a:file)
endif
endfunction
" }}}
" Path Utilities: {{{
let s:slash = &shellslash ? '/' : '\'
function! netrw#own#PathJoin(...)
let path = ""
for arg in a:000
if empty(path)
let path = arg
else
let path .= s:slash . arg
endif
endfor
return path
endfunction
" }}}
" vim:ts=8 sts=4 sw=4 et fdm=marker " vim:ts=8 sts=4 sw=4 et fdm=marker

View File

@ -0,0 +1,48 @@
" FUNCTIONS IN THIS FILE ARE MEANT TO BE USED BY NETRW.VIM AND NETRW.VIM ONLY.
" THESE FUNCTIONS DON'T COMMIT TO ANY BACKWARDS COMPATIBILITY. SO CHANGES AND
" BREAKAGES IF USED OUTSIDE OF NETRW.VIM ARE EXPECTED.
" netrw#os#Execute: executes a string using "!" {{{
function! netrw#os#Execute(cmd)
if has("win32") && exepath(&shell) !~? '\v[\/]?(cmd|pwsh|powershell)(\.exe)?$' && !g:netrw_cygwin
let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
set shell& shellcmdflag& shellxquote& shellxescape&
set shellquote& shellpipe& shellredir& shellslash&
try
execute a:cmd
finally
let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
endtry
else
execute a:cmd
endif
if v:shell_error
call netrw#ErrorMsg(s:WARNING, "shell signalled an error", 106)
endif
endfunction
" }}}
" netrw#os#Escape: shellescape(), or special windows handling {{{
function! netrw#os#Escape(string, ...)
return has('win32') && empty($SHELL) && &shellslash
\ ? printf('"%s"', substitute(a:string, '"', '""', 'g'))
\ : shellescape(a:string, a:0 > 0 ? a:1 : 0)
endfunction
" }}}
" netrw#os#Open: open file with os viewer (eg. xdg-open) {{{
function! netrw#os#Open(file) abort
if has('nvim')
call luaeval('vim.ui.open(_A[1]) and nil', [a:file])
else
call dist#vim9#Open(a:file)
endif
endfunction
" }}}
" vim:ts=8 sts=4 sw=4 et fdm=marker

View File

@ -15,7 +15,7 @@ if &cp || exists("g:loaded_netrwSettings")
finish finish
endif endif
let g:loaded_netrwSettings = "v177" let g:loaded_netrwSettings = "v178"
" NetrwSettings: {{{ " NetrwSettings: {{{

View File

@ -1447,7 +1447,7 @@ With a "dirname", the specified directory name is used.
The "gn" map will take the word below the cursor and use that for The "gn" map will take the word below the cursor and use that for
changing the top of the tree listing. changing the top of the tree listing.
*netrw-curdir*
DELETING BOOKMARKS *netrw-mB* {{{2 DELETING BOOKMARKS *netrw-mB* {{{2
To delete a bookmark, use > To delete a bookmark, use >

View File

@ -15,7 +15,7 @@ if &cp || exists("g:loaded_netrwPlugin")
finish finish
endif endif
let g:loaded_netrwPlugin = "v177" let g:loaded_netrwPlugin = "v178"
let s:keepcpo = &cpo let s:keepcpo = &cpo
set cpo&vim set cpo&vim