Skip to content

Commit 5b97947

Browse files
saccarosiumchrisbra
authored andcommitted
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>
1 parent b3854bf commit 5b97947

9 files changed

Lines changed: 385 additions & 338 deletions

File tree

Filelist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,9 @@ RT_ALL = \
816816
runtime/pack/dist/opt/netrw/LICENSE.txt \
817817
runtime/pack/dist/opt/netrw/README.md \
818818
runtime/pack/dist/opt/netrw/autoload/netrw.vim \
819-
runtime/pack/dist/opt/netrw/autoload/netrw/own.vim \
819+
runtime/pack/dist/opt/netrw/autoload/netrw/fs.vim \
820+
runtime/pack/dist/opt/netrw/autoload/netrw/os.vim \
821+
runtime/pack/dist/opt/netrw/autoload/netrw/msg.vim \
820822
runtime/pack/dist/opt/netrw/autoload/netrwSettings.vim \
821823
runtime/pack/dist/opt/netrw/autoload/netrw_gitignore.vim \
822824
runtime/pack/dist/opt/netrw/doc/netrw.txt \

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9002,6 +9002,7 @@ netrw-ctrl-h pi_netrw.txt /*netrw-ctrl-h*
90029002
netrw-ctrl-l pi_netrw.txt /*netrw-ctrl-l*
90039003
netrw-ctrl-r pi_netrw.txt /*netrw-ctrl-r*
90049004
netrw-ctrl_l pi_netrw.txt /*netrw-ctrl_l*
9005+
netrw-curdir pi_netrw.txt /*netrw-curdir*
90059006
netrw-d pi_netrw.txt /*netrw-d*
90069007
netrw-del pi_netrw.txt /*netrw-del*
90079008
netrw-delete pi_netrw.txt /*netrw-delete*

runtime/pack/dist/opt/netrw/autoload/netrw.vim

Lines changed: 161 additions & 301 deletions
Large diffs are not rendered by default.
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
" FUNCTIONS IN THIS FILE ARE MEANT TO BE USED BY NETRW.VIM AND NETRW.VIM ONLY.
2+
" THESE FUNCTIONS DON'T COMMIT TO ANY BACKWARDS COMPATIBILITY. SO CHANGES AND
3+
" BREAKAGES IF USED OUTSIDE OF NETRW.VIM ARE EXPECTED.
4+
5+
let s:slash = &shellslash ? '/' : '\'
6+
7+
" netrw#fs#PathJoin: Appends a new part to a path taking different systems into consideration {{{
8+
9+
function! netrw#fs#PathJoin(...)
10+
let path = ""
11+
12+
for arg in a:000
13+
if empty(path)
14+
let path = arg
15+
else
16+
let path .= s:slash . arg
17+
endif
18+
endfor
19+
20+
return path
21+
endfunction
22+
23+
" }}}
24+
" netrw#fs#ComposePath: Appends a new part to a path taking different systems into consideration {{{
25+
26+
function! netrw#fs#ComposePath(base, subdir)
27+
if has('amiga')
28+
let ec = a:base[s:Strlen(a:base)-1]
29+
if ec != '/' && ec != ':'
30+
let ret = a:base . '/' . a:subdir
31+
else
32+
let ret = a:base.a:subdir
33+
endif
34+
35+
" COMBAK: test on windows with changing to root directory: :e C:/
36+
elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has('win32')
37+
let ret = a:subdir
38+
39+
elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has('win32')
40+
if a:base =~ '[/\\]$'
41+
let ret = a:base . a:subdir
42+
else
43+
let ret = a:base . '/' . a:subdir
44+
endif
45+
46+
elseif a:base =~ '^\a\{3,}://'
47+
let urlbase = substitute(a:base, '^\(\a\+://.\{-}/\)\(.*\)$', '\1', '')
48+
let curpath = substitute(a:base, '^\(\a\+://.\{-}/\)\(.*\)$', '\2', '')
49+
if a:subdir == '../'
50+
if curpath =~ '[^/]/[^/]\+/$'
51+
let curpath = substitute(curpath, '[^/]\+/$', '', '')
52+
else
53+
let curpath = ''
54+
endif
55+
let ret = urlbase.curpath
56+
else
57+
let ret = urlbase.curpath.a:subdir
58+
endif
59+
60+
else
61+
let ret = substitute(a:base . '/' .a:subdir, '//', '/', 'g')
62+
if a:base =~ '^//'
63+
" keeping initial '//' for the benefit of network share listing support
64+
let ret = '/' . ret
65+
endif
66+
let ret = simplify(ret)
67+
endif
68+
69+
return ret
70+
endfunction
71+
72+
" }}}
73+
" netrw#fs#AbsPath: returns the full path to a directory and/or file {{{
74+
75+
function! netrw#fs#AbsPath(filename)
76+
let filename = a:filename
77+
78+
if filename !~ '^/'
79+
let filename = resolve(getcwd() . '/' . filename)
80+
endif
81+
82+
if filename != "/" && filename =~ '/$'
83+
let filename = substitute(filename, '/$', '', '')
84+
endif
85+
86+
return filename
87+
endfunction
88+
89+
" }}}
90+
" netrw#fs#Cwd: get the current directory. {{{
91+
" Change backslashes to forward slashes, if any.
92+
" If doesc is true, escape certain troublesome characters
93+
94+
function! netrw#fs#Cwd(doesc)
95+
let curdir = substitute(getcwd(), '\\', '/', 'ge')
96+
97+
if curdir !~ '[\/]$'
98+
let curdir .= '/'
99+
endif
100+
101+
if a:doesc
102+
let curdir = fnameescape(curdir)
103+
endif
104+
105+
return curdir
106+
endfunction
107+
108+
" }}}
109+
" netrw#fs#Glob: does glob() if local, remote listing otherwise {{{
110+
" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
111+
" expr : this is the expression to follow the directory. Will use netrw#fs#ComposePath()
112+
" pare =1: remove the current directory from the resulting glob() filelist
113+
" =0: leave the current directory in the resulting glob() filelist
114+
115+
function! netrw#fs#Glob(direntry, expr, pare)
116+
if netrw#CheckIfRemote()
117+
keepalt 1sp
118+
keepalt enew
119+
let keep_liststyle = w:netrw_liststyle
120+
let w:netrw_liststyle = s:THINLIST
121+
if s:NetrwRemoteListing() == 0
122+
keepj keepalt %s@/@@
123+
let filelist = getline(1,$)
124+
q!
125+
else
126+
" remote listing error -- leave treedict unchanged
127+
let filelist = w:netrw_treedict[a:direntry]
128+
endif
129+
let w:netrw_liststyle = keep_liststyle
130+
else
131+
let path= netrw#fs#ComposePath(fnameescape(a:direntry), a:expr)
132+
if has("win32")
133+
" escape [ so it is not detected as wildcard character, see :h wildcard
134+
let path = substitute(path, '[', '[[]', 'g')
135+
endif
136+
let filelist = glob(path, 0, 1, 1)
137+
if a:pare
138+
let filelist = map(filelist,'substitute(v:val, "^.*/", "", "")')
139+
endif
140+
endif
141+
142+
return filelist
143+
endfunction
144+
145+
" }}}
146+
" netrw#fs#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{
147+
148+
function! netrw#fs#WinPath(path)
149+
if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
150+
" remove cygdrive prefix, if present
151+
let path = substitute(a:path, g:netrw_cygdrive . '/\(.\)', '\1:', '')
152+
" remove trailing slash (Win95)
153+
let path = substitute(path, '\(\\\|/\)$', '', 'g')
154+
" remove escaped spaces
155+
let path = substitute(path, '\ ', ' ', 'g')
156+
" convert slashes to backslashes
157+
let path = substitute(path, '/', '\', 'g')
158+
else
159+
let path = a:path
160+
endif
161+
162+
return path
163+
endfunction
164+
165+
" }}}
166+
167+
" vim:ts=8 sts=4 sw=4 et fdm=marker
Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
" FUNCTIONS IN THIS FILES ARE MENT TO BE USE BY NETRW.VIM AND NETRW.VIM ONLY.
2-
" THIS FUNCTIONS DON'T COMMIT TO ANY BACKWARDS COMPATABILITY. SO CHANGES AND
1+
" FUNCTIONS IN THIS FILE ARE MEANT TO BE USED BY NETRW.VIM AND NETRW.VIM ONLY.
2+
" THESE FUNCTIONS DON'T COMMIT TO ANY BACKWARDS COMPATIBILITY. SO CHANGES AND
33
" BREAKAGES IF USED OUTSIDE OF NETRW.VIM ARE EXPECTED.
44

5-
" General: {{{
6-
75
let s:deprecation_msgs = []
86
function! netrw#own#Deprecate(name, version, alternatives)
97
" If running on neovim use vim.deprecate
@@ -29,33 +27,4 @@ function! netrw#own#Deprecate(name, version, alternatives)
2927
call add(s:deprecation_msgs, a:name)
3028
endfunction
3129

32-
function! netrw#own#Open(file) abort
33-
if has('nvim')
34-
call luaeval('vim.ui.open(_A[1]) and nil', [a:file])
35-
else
36-
call dist#vim9#Open(a:file)
37-
endif
38-
endfunction
39-
40-
" }}}
41-
" Path Utilities: {{{
42-
43-
let s:slash = &shellslash ? '/' : '\'
44-
45-
function! netrw#own#PathJoin(...)
46-
let path = ""
47-
48-
for arg in a:000
49-
if empty(path)
50-
let path = arg
51-
else
52-
let path .= s:slash . arg
53-
endif
54-
endfor
55-
56-
return path
57-
endfunction
58-
59-
" }}}
60-
6130
" vim:ts=8 sts=4 sw=4 et fdm=marker
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
" FUNCTIONS IN THIS FILE ARE MEANT TO BE USED BY NETRW.VIM AND NETRW.VIM ONLY.
2+
" THESE FUNCTIONS DON'T COMMIT TO ANY BACKWARDS COMPATIBILITY. SO CHANGES AND
3+
" BREAKAGES IF USED OUTSIDE OF NETRW.VIM ARE EXPECTED.
4+
5+
" netrw#os#Execute: executes a string using "!" {{{
6+
7+
function! netrw#os#Execute(cmd)
8+
if has("win32") && exepath(&shell) !~? '\v[\/]?(cmd|pwsh|powershell)(\.exe)?$' && !g:netrw_cygwin
9+
let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
10+
set shell& shellcmdflag& shellxquote& shellxescape&
11+
set shellquote& shellpipe& shellredir& shellslash&
12+
try
13+
execute a:cmd
14+
finally
15+
let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
16+
endtry
17+
else
18+
execute a:cmd
19+
endif
20+
21+
if v:shell_error
22+
call netrw#ErrorMsg(s:WARNING, "shell signalled an error", 106)
23+
endif
24+
endfunction
25+
26+
" }}}
27+
" netrw#os#Escape: shellescape(), or special windows handling {{{
28+
29+
function! netrw#os#Escape(string, ...)
30+
return has('win32') && empty($SHELL) && &shellslash
31+
\ ? printf('"%s"', substitute(a:string, '"', '""', 'g'))
32+
\ : shellescape(a:string, a:0 > 0 ? a:1 : 0)
33+
endfunction
34+
35+
" }}}
36+
" netrw#os#Open: open file with os viewer (eg. xdg-open) {{{
37+
38+
function! netrw#os#Open(file) abort
39+
if has('nvim')
40+
call luaeval('vim.ui.open(_A[1]) and nil', [a:file])
41+
else
42+
call dist#vim9#Open(a:file)
43+
endif
44+
endfunction
45+
46+
" }}}
47+
48+
" vim:ts=8 sts=4 sw=4 et fdm=marker

runtime/pack/dist/opt/netrw/autoload/netrwSettings.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if &cp || exists("g:loaded_netrwSettings")
1515
finish
1616
endif
1717

18-
let g:loaded_netrwSettings = "v177"
18+
let g:loaded_netrwSettings = "v178"
1919

2020
" NetrwSettings: {{{
2121

runtime/pack/dist/opt/netrw/doc/netrw.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ With a "dirname", the specified directory name is used.
14471447
The "gn" map will take the word below the cursor and use that for
14481448
changing the top of the tree listing.
14491449

1450-
1450+
*netrw-curdir*
14511451
DELETING BOOKMARKS *netrw-mB* {{{2
14521452

14531453
To delete a bookmark, use >

runtime/pack/dist/opt/netrw/plugin/netrwPlugin.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if &cp || exists("g:loaded_netrwPlugin")
1515
finish
1616
endif
1717

18-
let g:loaded_netrwPlugin = "v177"
18+
let g:loaded_netrwPlugin = "v178"
1919

2020
let s:keepcpo = &cpo
2121
set cpo&vim

0 commit comments

Comments
 (0)