summaryrefslogtreecommitdiffstats
path: root/runtime/autoload/netrw.vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/autoload/netrw.vim')
-rw-r--r--runtime/autoload/netrw.vim203
1 files changed, 90 insertions, 113 deletions
diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim
index d8de432..e747ce2 100644
--- a/runtime/autoload/netrw.vim
+++ b/runtime/autoload/netrw.vim
@@ -3,7 +3,7 @@
" Maintainer: This runtime file is looking for a new maintainer.
" Date: May 03, 2023
" Version: 173a
-" Last Change:
+" Last Change: {{{1
" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
" 2024 Feb 19 by Vim Project: (announce adoption)
@@ -15,6 +15,15 @@
" 2024 May 13 by Vim Project: prefer scp over pscp
" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
+" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
+" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
+" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
+" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
+" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
+" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
+" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
+" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
+" }}}
" Former Maintainer: Charles E Campbell
" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
@@ -57,11 +66,6 @@ if exists("s:needspatches")
endif
let g:loaded_netrw = "v173"
-if !exists("s:NOTE")
- let s:NOTE = 0
- let s:WARNING = 1
- let s:ERROR = 2
-endif
let s:keepcpo= &cpo
setl cpo&vim
@@ -99,7 +103,7 @@ fun! netrw#ErrorMsg(level,msg,errnum)
endif
" call Decho("level=".level,'~'.expand("<slnum>"))
- if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
+ if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
" use popup window
if type(a:msg) == 3
let msg = [level]+a:msg
@@ -215,6 +219,11 @@ if !exists("s:LONGLIST")
call s:NetrwInit("s:MAXLIST" ,4)
endif
+let s:NOTE = 0
+let s:WARNING = 1
+let s:ERROR = 2
+call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
+
" ---------------------------------------------------------------------
" Default option values: {{{2
let g:netrw_localcopycmdopt = ""
@@ -224,7 +233,10 @@ let g:netrw_localmovecmdopt = ""
" ---------------------------------------------------------------------
" Default values for netrw's global protocol variables {{{2
-if (v:version > 802 || (v:version == 802 && has("patch486"))) && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on") && has("mouse")
+if exists("*popup_atcursor")
+\ && has("syntax")
+\ && exists("g:syntax_on")
+\ && has("mouse")
call s:NetrwInit("g:netrw_use_errorwindow",2)
else
call s:NetrwInit("g:netrw_use_errorwindow",1)
@@ -342,7 +354,6 @@ call s:NetrwInit("s:didstarstar",0)
call s:NetrwInit("g:netrw_dirhistcnt" , 0)
call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
call s:NetrwInit("g:netrw_dirhistmax" , 10)
-call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
call s:NetrwInit("g:netrw_fastbrowse" , 1)
call s:NetrwInit("g:netrw_ftp_browse_reject", '^total\s\+\d\+$\|^Trying\s\+\d\+.*$\|^KERBEROS_V\d rejected\|^Security extensions not\|No such file\|: connect to address [0-9a-fA-F:]*: No route to host$')
if !exists("g:netrw_ftp_list_cmd")
@@ -693,12 +704,11 @@ fun! netrw#Explore(indx,dosplit,style,...)
\ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
\ '~'.expand("<slnum>"))
if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
-" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
- call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
-" call Dret("netrw#Explore : returning from retry")
- return
-" else " Decho
-" call Decho("retry not needed",'~'.expand("<slnum>"))
+ let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
+ if a1 != a:1
+ call netrw#Explore(a:indx, a:dosplit, a:style, a1)
+ return
+ endif
endif
endif
@@ -714,7 +724,6 @@ fun! netrw#Explore(indx,dosplit,style,...)
" -or- file has been modified AND file not hidden when abandoned
" -or- Texplore used
if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
-" call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified",'~'.expand("<slnum>"))
call s:SaveWinVars()
let winsz= g:netrw_winsize
if a:indx > 0
@@ -722,57 +731,41 @@ fun! netrw#Explore(indx,dosplit,style,...)
endif
if a:style == 0 " Explore, Sexplore
-" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
if winsz == 0|let winsz= ""|endif
- exe "noswapfile ".winsz."wincmd s"
-" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
+ exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
- elseif a:style == 1 "Explore!, Sexplore!
-" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
+ elseif a:style == 1 " Explore!, Sexplore!
let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
if winsz == 0|let winsz= ""|endif
- exe "keepalt noswapfile ".winsz."wincmd v"
-" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
+ exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
elseif a:style == 2 " Hexplore
-" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
if winsz == 0|let winsz= ""|endif
- exe "keepalt noswapfile bel ".winsz."wincmd s"
-" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
+ exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
elseif a:style == 3 " Hexplore!
-" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
if winsz == 0|let winsz= ""|endif
- exe "keepalt noswapfile abo ".winsz."wincmd s"
-" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
+ exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
elseif a:style == 4 " Vexplore
-" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
if winsz == 0|let winsz= ""|endif
- exe "keepalt noswapfile lefta ".winsz."wincmd v"
-" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
+ exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
elseif a:style == 5 " Vexplore!
-" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
if winsz == 0|let winsz= ""|endif
- exe "keepalt noswapfile rightb ".winsz."wincmd v"
-" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
+ exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
elseif a:style == 6 " Texplore
call s:SaveBufVars()
-" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
exe "keepalt tabnew ".fnameescape(curdir)
-" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
call s:RestoreBufVars()
endif
call s:RestoreWinVars()
-" else " Decho
-" call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6",'~'.expand("<slnum>"))
endif
NetrwKeepj norm! 0
@@ -4496,7 +4489,15 @@ fun! s:NetrwGetWord()
call cursor(line("."),filestart+1)
NetrwKeepj norm! ma
endif
- let rega= @a
+
+ let dict={}
+ " save the unnamed register and register 0-9 and a
+ let dict.a=[getreg('a'), getregtype('a')]
+ for i in range(0, 9)
+ let dict[i] = [getreg(i), getregtype(i)]
+ endfor
+ let dict.unnamed = [getreg(''), getregtype('')]
+
let eofname= filestart + b:netrw_cpf + 1
if eofname <= col("$")
call cursor(line("."),filestart+b:netrw_cpf+1)
@@ -4504,8 +4505,10 @@ fun! s:NetrwGetWord()
else
NetrwKeepj norm! "ay$
endif
+
let dirname = @a
- let @a = rega
+ call s:RestoreRegister(dict)
+
" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
let dirname= substitute(dirname,'\s\+$','','e')
" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
@@ -5573,13 +5576,12 @@ endfun
" ---------------------------------------------------------------------
" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
fun! netrw#BrowseXVis()
-" call Dfunc("netrw#BrowseXVis()")
- let akeep = @a
+ let dict={}
+ let dict.a=[getreg('a'), getregtype('a')]
norm! gv"ay
let gxfile= @a
- let @a = akeep
+ call s:RestoreRegister(dict)
call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
-" call Dret("netrw#BrowseXVis")
endfun
" ---------------------------------------------------------------------
@@ -6887,11 +6889,7 @@ fun! s:NetrwMarkFile(islocal,fname)
let ykeep = @@
let curbufnr= bufnr("%")
- if a:fname =~ '^\a'
- let leader= '\<'
- else
- let leader= ''
- endif
+ let leader= '\(^\|\s\)\zs'
if a:fname =~ '\a$'
let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
else
@@ -7154,7 +7152,7 @@ fun! s:NetrwMarkFileCopy(islocal,...)
endif
" copy marked files while within the same directory (ie. allow renaming)
- if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
+ if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
" only one marked file
" call Decho("case: only one marked file",'~'.expand("<slnum>"))
@@ -7231,7 +7229,7 @@ fun! s:NetrwMarkFileCopy(islocal,...)
" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
if v:shell_error != 0
- if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
+ if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
call netrw#ErrorMsg(s:ERROR,"copy failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",101)
else
call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
@@ -7500,7 +7498,13 @@ fun! s:NetrwMarkFileExe(islocal,enbloc)
NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
break
else
- echo ret
+ if ret !=# ''
+ echo "\n"
+ " skip trailing new line
+ echo ret[0:-2]
+ else
+ echo ret
+ endif
endif
endfor
@@ -9779,7 +9783,13 @@ fun! s:NetrwWideListing()
" fpl: filenames per line
" fpc: filenames per column
setl ma noro
- let keepa= @a
+ let dict={}
+ " save the unnamed register and register 0-9 and a
+ let dict.a=[getreg('a'), getregtype('a')]
+ for i in range(0, 9)
+ let dict[i] = [getreg(i), getregtype(i)]
+ endfor
+ let dict.unnamed = [getreg(''), getregtype('')]
" call Decho("setl ma noro",'~'.expand("<slnum>"))
let b:netrw_cpf= 0
if line("$") >= w:netrw_bannercnt
@@ -9787,7 +9797,8 @@ fun! s:NetrwWideListing()
exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
NetrwKeepj call histdel("/",-1)
else
- let @a= keepa
+ " restore stored registers
+ call s:RestoreRegister(dict)
" call Dret("NetrwWideListing")
return
endif
@@ -9839,7 +9850,7 @@ fun! s:NetrwWideListing()
exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
exe "setl ".g:netrw_bufsettings
- let @a= keepa
+ call s:RestoreRegister(dict)
" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
" call Dret("NetrwWideListing")
return
@@ -9851,7 +9862,6 @@ fun! s:NetrwWideListing()
sil! nunmap <buffer> b
endif
endif
-
endfun
" ---------------------------------------------------------------------
@@ -10172,7 +10182,8 @@ fun! s:SetupNetrwStatusLine(statline)
endif
" set up User9 highlighting as needed
- let keepa= @a
+ let dict={}
+ let dict.a=[getreg('a'), getregtype('a')]
redir @a
try
hi User9
@@ -10184,7 +10195,7 @@ fun! s:SetupNetrwStatusLine(statline)
endif
endtry
redir END
- let @a= keepa
+ call s:RestoreRegister(dict)
endif
" set up status line (may use User9 highlighting)
@@ -11435,7 +11446,7 @@ fun! s:NetrwLocalRmFile(path,fname,all)
let all= a:all
let ok = ""
NetrwKeepj norm! 0
- let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
+ let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
@@ -11444,7 +11455,7 @@ fun! s:NetrwLocalRmFile(path,fname,all)
if !all
echohl Statement
call inputsave()
- let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
+ let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
call inputrestore()
echohl NONE
if ok == ""
@@ -11468,7 +11479,7 @@ fun! s:NetrwLocalRmFile(path,fname,all)
if !all
echohl Statement
call inputsave()
- let ok= input("Confirm *recursive* deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
+ let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
call inputrestore()
let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
if ok == ""
@@ -11628,6 +11639,13 @@ fun! netrw#WinPath(path)
endfun
" ---------------------------------------------------------------------
+" s:StripTrailingSlash: removes trailing slashes from a path {{{2
+fun! s:StripTrailingSlash(path)
+ " remove trailing slash
+ return substitute(a:path, '[/\\]$', '', 'g')
+endfun
+
+" ---------------------------------------------------------------------
" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
" cb : bl2mf=0 add marked files to buffer list
" cB : bl2mf=1 use bufferlist to mark files
@@ -11994,6 +12012,16 @@ fun! s:RestoreCursorline()
" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
endfun
+" s:RestoreRegister: restores all registers given in the dict {{{2
+fun! s:RestoreRegister(dict)
+ for [key, val] in items(a:dict)
+ if key == 'unnamed'
+ let key = ''
+ endif
+ call setreg(key, val[0], val[1])
+ endfor
+endfun
+
" ---------------------------------------------------------------------
" s:NetrwDelete: Deletes a file. {{{2
" Uses Steve Hall's idea to insure that Windows paths stay
@@ -12801,54 +12829,3 @@ unlet s:keepcpo
" Modelines: {{{1
" ===============
" vim:ts=8 fdm=marker
-" doing autoload/netrw.vim version v172g ~57
-" varname<g:netrw_dirhistcnt> value=0 ~1
-" varname<s:THINLIST> value=0 ~1
-" varname<s:LONGLIST> value=1 ~1
-" varname<s:WIDELIST> value=2 ~1
-" varname<s:TREELIST> value=3 ~1
-" varname<s:MAXLIST> value=4 ~1
-" varname<g:netrw_use_errorwindow> value=2 ~1
-" varname<g:netrw_http_xcmd> value=-q -O ~1
-" varname<g:netrw_http_put_cmd> value=curl -T ~1
-" varname<g:netrw_keepj> value=keepj ~1
-" varname<g:netrw_rcp_cmd> value=rcp ~1
-" varname<g:netrw_rsync_cmd> value=rsync ~1
-" varname<g:netrw_rsync_sep> value=/ ~1
-" varname<g:netrw_scp_cmd> value=scp -q ~1
-" varname<g:netrw_sftp_cmd> value=sftp ~1
-" varname<g:netrw_ssh_cmd> value=ssh ~1
-" varname<g:netrw_alto> value=0 ~1
-" varname<g:netrw_altv> value=1 ~1
-" varname<g:netrw_banner> value=1 ~1
-" varname<g:netrw_browse_split> value=0 ~1
-" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
-" varname<g:netrw_chgwin> value=-1 ~1
-" varname<g:netrw_clipboard> value=1 ~1
-" varname<g:netrw_compress> value=gzip ~1
-" varname<g:netrw_ctags> value=ctags ~1
-" varname<g:netrw_cursor> value=2 ~1
-" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
-" varname<g:netrw_cygdrive> value=/cygdrive ~1
-" varname<s:didstarstar> value=0 ~1
-" varname<g:netrw_dirhistcnt> value=0 ~1
-" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
-" varname<g:netrw_dirhistmax> value=10 ~1
-" varname<g:netrw_errorlvl> value=0 ~1
-" varname<g:netrw_fastbrowse> value=1 ~1
-" varname<g:netrw_ftp_browse_reject> value=^total\s\+\d\+$\|^Trying\s\+\d\+.*$\|^KERBEROS_V\d rejected\|^Security extensions not\|No such file\|: connect to address [0-9a-fA-F:]*: No route to host$ ~1
-" varname<g:netrw_ftpmode> value=binary ~1
-" varname<g:netrw_hide> value=1 ~1
-" varname<g:netrw_keepdir> value=1 ~1
-" varname<g:netrw_list_hide> value= ~1
-" varname<g:netrw_localmkdir> value=mkdir ~1
-" varname<g:netrw_remote_mkdir> value=mkdir ~1
-" varname<g:netrw_liststyle> value=0 ~1
-" varname<g:netrw_markfileesc> value=*./[\~ ~1
-" varname<g:netrw_maxfilenamelen> value=32 ~1
-" varname<g:netrw_menu> value=1 ~1
-" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
-" varname<g:netrw_mousemaps> value=1 ~1
-" varname<g:netrw_retmap> value=0 ~1
-" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
-" varname<g:netrw_preview> value=0 ~1