blob: a15ca1c9247bf6a8bccbc002ecd6377a838afa45 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Luca Saccarolaa7d45612024-10-21 21:27:03 +02007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
8" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Christian Brabandt0f5effb2024-09-15 19:17:23 +020026" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
yasudac18a9d52024-09-19 18:09:51 +020027" 2024 Sep 19 by Vim Project: mf-selection highlight uses wrong pattern (#15700)
Peter Aronoffbe551da2024-09-22 11:29:40 +020028" 2024 Sep 21 by Vim Project: remove extraneous closing bracket (#15718)
Luca Saccarolaa7d45612024-10-21 21:27:03 +020029" 2024 Oct 21 by Vim Project: remove netrwFileHandlers (#15895)
Konfekt3d7e5672024-10-27 22:16:49 +010030" 2024 Oct 27 by Vim Project: clean up gx mapping (#15721)
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +010031" 2024 Oct 30 by Vim Project: fix filetype detection for remote files (#15961)
Christian Brabandt9f320692024-10-30 18:36:20 +010032" 2024 Oct 30 by Vim Project: fix x mapping on cygwin (#13687)
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010033" 2024 Oct 31 by Vim Project: add netrw#Launch() and netrw#Open() (#15962)
Tom Benham4d618002024-10-31 10:47:23 +010034" 2024 Oct 31 by Vim Project: fix E874 when browsing remote dir (#15964)
Christian Brabandta063b222024-11-07 14:30:30 +010035" 2024 Nov 07 by Vim Project: use keeppatterns to prevent polluting the search history
Travis Sheltone34d0e32024-07-30 21:08:56 +020036" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010037" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000038" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010039" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000040" Permission is hereby granted to use and distribute this code,
41" with or without modifications, provided that this copyright
42" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000043" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000044" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000045" expressed or implied. By using this plugin, you agree that
46" in no event will the copyright holder be liable for any damages
47" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010048"
49" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
50" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
51"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020052"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000053"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000054" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000055" (James 1:22 RSV)
56" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000057" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000058if &cp || exists("g:loaded_netrw")
59 finish
60endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020061
62" Check that vim has patches that netrw requires.
63" Patches needed for v7.4: 1557, and 213.
64" (netrw will benefit from vim's having patch#656, too)
65let s:needspatches=[1557,213]
66if exists("s:needspatches")
67 for ptch in s:needspatches
68 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
69 if !exists("s:needpatch{ptch}")
70 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
71 endif
72 let s:needpatch{ptch}= 1
73 finish
74 endif
75 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020076endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020077
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010078let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000079
Bram Moolenaar1afcace2005-11-25 19:54:28 +000080let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010081setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020082"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010083"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010084"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000085
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000086" ======================
87" Netrw Variables: {{{1
88" ======================
89
Bram Moolenaar071d4272004-06-13 20:20:40 +000090" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020091" netrw#ErrorMsg: {{{2
92" 0=note = s:NOTE
93" 1=warning = s:WARNING
94" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010095" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
96" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
97" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010098" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020099fun! netrw#ErrorMsg(level,msg,errnum)
100" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
101
102 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200103" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200104 return
105 endif
106
107 if a:level == 1
108 let level= "**warning** (netrw) "
109 elseif a:level == 2
110 let level= "**error** (netrw) "
111 else
112 let level= "**note** (netrw) "
113 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100114" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200115
Damienb4d11642024-08-15 22:00:45 +0200116 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200117 " use popup window
118 if type(a:msg) == 3
119 let msg = [level]+a:msg
120 else
121 let msg= level.a:msg
122 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200123 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200124 let s:popuperr_text= ""
125 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200126 " (default) netrw creates a one-line window to show error/warning
127 " messages (reliably displayed)
128
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100129 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200130 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100131" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200132
133 " getting messages out reliably is just plain difficult!
134 " This attempt splits the current window, creating a one line window.
135 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100136" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200137 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100138" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200139 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100140 if type(a:msg) == 3
141 for msg in a:msg
142 NetrwKeepj call setline(line("$")+1,level.msg)
143 endfor
144 else
145 NetrwKeepj call setline(line("$")+1,level.a:msg)
146 endif
147 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200148 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100149" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200150 bo 1split
151 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200152 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200153 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100154 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100155" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200156 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100157 if type(a:msg) == 3
158 for msg in a:msg
159 NetrwKeepj call setline(line("$")+1,level.msg)
160 endfor
161 else
162 NetrwKeepj call setline(line("$"),level.a:msg)
163 endif
164 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200165 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100166" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200167 if &fo !~ '[ta]'
168 syn clear
169 syn match netrwMesgNote "^\*\*note\*\*"
170 syn match netrwMesgWarning "^\*\*warning\*\*"
171 syn match netrwMesgError "^\*\*error\*\*"
172 hi link netrwMesgWarning WarningMsg
173 hi link netrwMesgError Error
174 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100175" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200176 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200177
178 else
179 " (optional) netrw will show messages using echomsg. Even if the
180 " message doesn't appear, at least it'll be recallable via :messages
181" redraw!
182 if a:level == s:WARNING
183 echohl WarningMsg
184 elseif a:level == s:ERROR
185 echohl Error
186 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100187
188 if type(a:msg) == 3
189 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100190 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100191 endfor
192 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100193 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100194 endif
195
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100196" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200197 echohl None
198 endif
199
200" call Dret("netrw#ErrorMsg")
201endfun
202
203" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100204" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100205" Loosely, varname = value.
206fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100207" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100208 if !exists(a:varname)
209 if type(a:value) == 0
210 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200211 elseif type(a:value) == 1 && a:value =~ '^[{[]'
212 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100213 elseif type(a:value) == 1
214 exe "let ".a:varname."="."'".a:value."'"
215 else
216 exe "let ".a:varname."=".a:value
217 endif
218 endif
219endfun
220
221" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000222" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200223call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000224if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100225 call s:NetrwInit("s:THINLIST",0)
226 call s:NetrwInit("s:LONGLIST",1)
227 call s:NetrwInit("s:WIDELIST",2)
228 call s:NetrwInit("s:TREELIST",3)
229 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000230endif
231
Damien7c754112024-08-15 21:58:57 +0200232let s:NOTE = 0
233let s:WARNING = 1
234let s:ERROR = 2
235call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
236
Bram Moolenaar9964e462007-05-05 17:54:07 +0000237" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200238" Default option values: {{{2
239let g:netrw_localcopycmdopt = ""
240let g:netrw_localcopydircmdopt = ""
241let g:netrw_localmkdiropt = ""
242let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200243
244" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000245" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200246if exists("*popup_atcursor")
247\ && has("syntax")
248\ && exists("g:syntax_on")
249\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200250 call s:NetrwInit("g:netrw_use_errorwindow",2)
251else
252 call s:NetrwInit("g:netrw_use_errorwindow",1)
253endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200254
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000255if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100256 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000257 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100258 elseif executable("curl")
259 let g:netrw_dav_cmd = "curl"
260 else
261 let g:netrw_dav_cmd = ""
262 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000263endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000264if !exists("g:netrw_fetch_cmd")
265 if executable("fetch")
266 let g:netrw_fetch_cmd = "fetch -o"
267 else
268 let g:netrw_fetch_cmd = ""
269 endif
270endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100271if !exists("g:netrw_file_cmd")
272 if executable("elinks")
273 call s:NetrwInit("g:netrw_file_cmd","elinks")
274 elseif executable("links")
275 call s:NetrwInit("g:netrw_file_cmd","links")
276 endif
277endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000278if !exists("g:netrw_ftp_cmd")
279 let g:netrw_ftp_cmd = "ftp"
280endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200281let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200282if !exists("g:netrw_ftp_options")
283 let g:netrw_ftp_options= "-i -n"
284endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000285if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100286 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100287 let g:netrw_http_cmd = "wget"
288 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100289 elseif executable("curl")
290 let g:netrw_http_cmd = "curl"
291 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200292 elseif executable("elinks")
293 let g:netrw_http_cmd = "elinks"
294 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000295 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100296 let g:netrw_http_cmd = "fetch"
297 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200298 elseif executable("links")
299 let g:netrw_http_cmd = "links"
300 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000301 else
302 let g:netrw_http_cmd = ""
303 endif
304endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100305call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100306call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100307call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
308call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200309call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200310if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200311 if executable("scp")
312 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
313 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200314 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200315 else
316 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
317 endif
318endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100319call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
320call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000321
Nir Lichtman1e34b952024-05-08 19:19:34 +0200322if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000323 \ && exists("g:netrw_use_nt_rcp")
324 \ && g:netrw_use_nt_rcp
325 \ && executable( $SystemRoot .'/system32/rcp.exe')
326 let s:netrw_has_nt_rcp = 1
327 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000328else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000329 let s:netrw_has_nt_rcp = 0
330 let s:netrw_rcpmode = ''
331endif
332
333" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000334" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000335" Cygwin Detection ------- {{{3
336if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200337 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
338 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000339 else
340 let g:netrw_cygwin= 0
341 endif
342endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000343" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100344call s:NetrwInit("g:netrw_alto" , &sb)
345call s:NetrwInit("g:netrw_altv" , &spr)
346call s:NetrwInit("g:netrw_banner" , 1)
347call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200348call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100349call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200350call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100351call s:NetrwInit("g:netrw_compress" , "gzip")
352call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200353if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
354 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
355 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000356endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200357call s:NetrwInit("g:netrw_cursor" , 2)
358let s:netrw_usercul = &cursorline
359let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200360"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100361call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000362" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200363call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200364call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200365call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100366call s:NetrwInit("g:netrw_dirhistmax" , 10)
367call s:NetrwInit("g:netrw_fastbrowse" , 1)
368call 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$')
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000369if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000370 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
371 let g:netrw_ftp_list_cmd = "ls -lF"
372 let g:netrw_ftp_timelist_cmd = "ls -tlF"
373 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000374 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000375 let g:netrw_ftp_list_cmd = "dir"
376 let g:netrw_ftp_timelist_cmd = "dir"
377 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000378 endif
379endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100380call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000381" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100382call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000383if !exists("g:netrw_ignorenetrc")
384 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
385 let g:netrw_ignorenetrc= 1
386 else
387 let g:netrw_ignorenetrc= 0
388 endif
389endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100390call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000391if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000392 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100393 if exists("g:netrw_list_cmd_options")
394 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
395 else
396 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
397 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000398 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200399 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100400 if exists("g:netrw_list_cmd_options")
401 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
402 else
403 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
404 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000405 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100406" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000407 let g:netrw_list_cmd= ""
408 endif
409endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100410call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000411" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200412if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200413 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200414 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
415endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100416if !exists("g:netrw_localcmdshell")
417 let g:netrw_localcmdshell= ""
418endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000419if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200420 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000421 if g:netrw_cygwin
422 let g:netrw_localcopycmd= "cp"
423 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000424 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200425 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000426 endif
427 elseif has("unix") || has("macunix")
428 let g:netrw_localcopycmd= "cp"
429 else
430 let g:netrw_localcopycmd= ""
431 endif
432endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100433if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200434 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100435 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200436 let g:netrw_localcopydircmd = "cp"
437 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100438 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000439 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200440 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100441 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200442 elseif has("unix")
443 let g:netrw_localcopydircmd = "cp"
444 let g:netrw_localcopydircmdopt= " -R"
445 elseif has("macunix")
446 let g:netrw_localcopydircmd = "cp"
447 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100448 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200449 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100450 endif
451endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200452if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100453 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200454 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
455endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200456if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200457 if g:netrw_cygwin
458 call s:NetrwInit("g:netrw_localmkdir","mkdir")
459 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000460 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200461 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200462 endif
463else
464 call s:NetrwInit("g:netrw_localmkdir","mkdir")
465endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200466call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200467if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200468 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200469 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
470endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000471if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200472 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000473 if g:netrw_cygwin
474 let g:netrw_localmovecmd= "mv"
475 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000476 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200477 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000478 endif
479 elseif has("unix") || has("macunix")
480 let g:netrw_localmovecmd= "mv"
481 else
482 let g:netrw_localmovecmd= ""
483 endif
484endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100485" following serves as an example for how to insert a version&patch specific test
486"if v:version < 704 || (v:version == 704 && !has("patch1107"))
487"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100488call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
489" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000490if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000491 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000492endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000493if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000494 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
495endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000496" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100497call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
498call s:NetrwInit("g:netrw_maxfilenamelen", 32)
499call s:NetrwInit("g:netrw_menu" , 1)
500call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200501call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100502call s:NetrwInit("g:netrw_retmap" , 0)
503if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
504 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200505elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100506 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
507else
508 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000509endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100510call s:NetrwInit("g:netrw_preview" , 0)
511call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100512call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100513call s:NetrwInit("g:netrw_sshport" , "-p")
514call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
515call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
516call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100517call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
518" Default values - q-s ---------- {{{3
519call s:NetrwInit("g:netrw_quickhelp",0)
520let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100521 \ "(create new) %:file d:directory",
522 \ "(windows split&open) o:horz v:vert p:preview",
523 \ "i:style qf:file info O:obtain r:reverse",
524 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
525 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
526 \ "(history) qb:list u:go up U:go down",
527 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100528" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
529call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100530if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
531 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
532else
533 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
534endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100535call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
536call s:NetrwInit("g:netrw_sort_options" , "")
537call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000538if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100539 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200540 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100541 else
542 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000543 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000544endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100545call s:NetrwInit("g:netrw_special_syntax" , 0)
546call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100547call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100548call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000549" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100550call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200551if !exists("g:netrw_xstrlen")
552 if exists("g:Align_xstrlen")
553 let g:netrw_xstrlen= g:Align_xstrlen
554 elseif exists("g:drawit_xstrlen")
555 let g:netrw_xstrlen= g:drawit_xstrlen
556 elseif &enc == "latin1" || !has("multi_byte")
557 let g:netrw_xstrlen= 0
558 else
559 let g:netrw_xstrlen= 1
560 endif
561endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100562call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200563call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100564call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200565if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000566" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000567" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100568call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200569if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200570 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200571else
Bram Moolenaarff034192013-04-24 18:51:19 +0200572 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200573endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200574call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100575call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
576call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100577if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100578 let s:treedepthstring= "│ "
579else
580 let s:treedepthstring= "| "
581endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200582call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000583
584" BufEnter event ignored by decho when following variable is true
585" Has a side effect that doau BufReadPost doesn't work, so
586" files read by network transfer aren't appropriately highlighted.
587"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588
Bram Moolenaaradc21822011-04-01 18:03:16 +0200589" ======================
590" Netrw Initialization: {{{1
591" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200592if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100593" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100594 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200595" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100596 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100597 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
598 au VimEnter * let s:initbeval= &beval
599"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100600" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
601" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
602" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
603" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
604" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
605" if exists("g:syntax_on") | call Decho("did not install beval events: g:syntax_on exists","~".expand("<slnum>")) | endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200606endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200607au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200608
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200609if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100610 com! -nargs=* NetrwKeepj keepj <args>
611else
612 let g:netrw_keepj= ""
613 com! -nargs=* NetrwKeepj <args>
614endif
615
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000616" ==============================
617" Netrw Utility Functions: {{{1
618" ==============================
619
Bram Moolenaaradc21822011-04-01 18:03:16 +0200620" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100621" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100622if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100623" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100624 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100625 if &ft != "netrw"
626 return ""
627 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200628 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
629 " popup error window is still showing
630 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
631 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
632 " text under mouse hasn't changed; only close window when it changes
633 call popup_close(s:popuperr_id)
634 unlet s:popuperr_text
635 else
636 let s:popuperr_text= v:beval_text
637 endif
638 let mesg= ""
639 elseif !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
Bram Moolenaar8d043172014-01-23 14:24:41 +0100640 let mesg= ""
641 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
642 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
643 elseif getline(v:beval_lnum) =~ '^"\s*/'
644 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
645 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100646 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100647 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
648 let mesg = "S: edit sorting sequence"
649 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
650 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
651 elseif v:beval_text == "Quick" || v:beval_text == "Help"
652 let mesg = "Help: press <F1>"
653 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
654 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
655 else
656 let mesg= ""
657 endif
658 return mesg
659 endfun
660"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100661" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
662" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
663" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
664" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
665" if exists("g:netrw_nobeval") |call Decho("did not load netrw#BalloonHelp(): g:netrw_nobeval exists","~".expand("<slnum>")) |endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200666endif
667
Bram Moolenaar071d4272004-06-13 20:20:40 +0000668" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200669" netrw#Explore: launch the local browser in the directory of the current file {{{2
670" indx: == -1: Nexplore
671" == -2: Pexplore
672" == +: this is overloaded:
673" * If Nexplore/Pexplore is in use, then this refers to the
674" indx'th item in the w:netrw_explore_list[] of items which
675" matched the */pattern **/pattern *//pattern **//pattern
676" * If Hexplore or Vexplore, then this will override
677" g:netrw_winsize to specify the qty of rows or columns the
678" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100679" dosplit==0: the window will be split iff the current file has been modified and hidden not set
Bram Moolenaarff034192013-04-24 18:51:19 +0200680" dosplit==1: the window will be split before running the local browser
681" style == 0: Explore style == 1: Explore!
682" == 2: Hexplore style == 3: Hexplore!
683" == 4: Vexplore style == 5: Vexplore!
684" == 6: Texplore
685fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100686" call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." modifiable=".&modifiable." a:0=".a:0." win#".winnr()." buf#".bufnr("%")." ft=".&ft)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100687" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200688 if !exists("b:netrw_curdir")
689 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100690" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200691 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100692
693 " record current file for Rexplore's benefit
694 if &ft != "netrw"
695 let w:netrw_rexfile= expand("%:p")
696 endif
697
698 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200699 let curdir = simplify(b:netrw_curdir)
700 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200701 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200702 let curdir= substitute(curdir,'\','/','g')
703 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100704" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100705
706 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
707 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
708 " try Explore again.
709 if a:0 > 0
710" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100711 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
712 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
713 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
714 \ '~'.expand("<slnum>"))
715 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200716 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
717 if a1 != a:1
718 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
719 return
720 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100721 endif
722 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200723
724 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200725 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100726" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100727 sil! let keepregstar = @*
728 sil! let keepregplus = @+
729 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200730 sil! let keepregslash= @/
731
Bram Moolenaar8d043172014-01-23 14:24:41 +0100732 " if dosplit
733 " -or- file has been modified AND file not hidden when abandoned
734 " -or- Texplore used
735 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200736 call s:SaveWinVars()
737 let winsz= g:netrw_winsize
738 if a:indx > 0
739 let winsz= a:indx
740 endif
741
742 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200743 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200744 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200745 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200746
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200747 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200748 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200749 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200750 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200751
752 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200753 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200754 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200755 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200756
757 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200758 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200759 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200760 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200761
762 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200763 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200764 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200765 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200766
767 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200768 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200769 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200770 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200771
772 elseif a:style == 6 " Texplore
773 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200774 exe "keepalt tabnew ".fnameescape(curdir)
775 call s:RestoreBufVars()
776 endif
777 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100779 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200780
781 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
790 if dirname !~ '/$'
791 let dirname= dirname."/"
792 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200798 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200800 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100803" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 let dirname= a:1
805 endif
806 else
807 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100808" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200809 call s:NetrwClearExplore()
810" call Dret("netrw#Explore : cleared list")
811 return
812 endif
813
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100814" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200815 if dirname =~ '\.\./\=$'
816 let dirname= simplify(fnamemodify(dirname,':p:h'))
817 elseif dirname =~ '\.\.' || dirname == '.'
818 let dirname= simplify(fnamemodify(dirname,':p'))
819 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100820" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200821
822 if dirname =~ '^\*//'
823 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100824" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200825 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
826 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100827" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200828 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
829
830 elseif dirname =~ '^\*\*//'
831 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100832" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200833 let pattern= substitute(dirname,'^\*\*//','','')
834 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100835" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200836
837 elseif dirname =~ '/\*\*/'
838 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100839" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200840 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200841 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200842 let b:netrw_curdir = prefixdir
843 else
844 let b:netrw_curdir= getcwd().'/'.prefixdir
845 endif
846 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
847 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100848" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
849" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200850
851 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200852 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200853 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100854" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200855
856 elseif dirname=~ '^\*\*/'
857 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
858 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100859" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200860
861 else
862 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100863" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200864 endif
865
866 if starpat == 0 && a:indx >= 0
867 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100868" call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname.">, handles Explore Hexplore Vexplore Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200869 if dirname == ""
870 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100871" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200872 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200873 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200874 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200875 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200876 if dirname == ""
877 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200878 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100879 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100880 " depending on whether backslashes have been converted to forward slashes by earlier code).
881 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200882 let dirname= b:netrw_curdir."/".dirname
883 endif
884 elseif dirname !~ '^/'
885 let dirname= b:netrw_curdir."/".dirname
886 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100887" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200888 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100889" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
890" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200891 endif
892 if exists("w:netrw_bannercnt")
893 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
894 " If one wants to return the same place in the netrw window, use :Rex instead.
895 exe w:netrw_bannercnt
896 endif
897
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100898" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200899 " ---------------------------------------------------------------------
900 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
901" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100902" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200903" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100904" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200905" endif
906 " ---------------------------------------------------------------------
907
908 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
909 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
910 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
911 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
912 elseif a:indx <= 0
913 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100914" call Decho("case a:indx<=0: Nexplore, Pexplore, <s-down>, <s-up> starpat=".starpat." a:indx=".a:indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200915 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100916" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200917 let s:didstarstar= 1
918 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
919 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
920 endif
921
922 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100923" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200924 if !exists("w:netrw_explore_indx")
925 let w:netrw_explore_indx= 0
926 endif
927
928 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100929" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200930
931 if indx == -1
932 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100933" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200934 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100935 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200936 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100937" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100938 if @* != keepregstar | sil! let @* = keepregstar | endif
939 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100940 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200941 sil! let @/ = keepregslash
942" call Dret("netrw#Explore")
943 return
944 endif
945 let indx= w:netrw_explore_indx
946 if indx < 0 | let indx= 0 | endif
947 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
948 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100949" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200950 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
951 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100952" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200953 endwhile
954 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100955" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200956
957 elseif indx == -2
958 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100959" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200960 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100961 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200962 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100963" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100964 if @* != keepregstar | sil! let @* = keepregstar | endif
965 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100966 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200967 sil! let @/ = keepregslash
968" call Dret("netrw#Explore")
969 return
970 endif
971 let indx= w:netrw_explore_indx
972 if indx < 0 | let indx= 0 | endif
973 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
974 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100975" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200976 while indx >= 0 && curfile == w:netrw_explore_list[indx]
977 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100978" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200979 endwhile
980 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100981" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200982
983 else
984 " Explore -- initialize
985 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100986" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100987 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200988 let w:netrw_explore_indx= 0
989 if !exists("b:netrw_curdir")
990 let b:netrw_curdir= getcwd()
991 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100992" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200993
994 " switch on starpat to build the w:netrw_explore_list of files
995 if starpat == 1
996 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100997" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
998" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200999 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001000 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001001 catch /^Vim\%((\a\+)\)\=:E480/
1002 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1003" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1004 return
1005 endtry
1006 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1007 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1008
1009 elseif starpat == 2
1010 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001011" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1012" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001013 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001014 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001015 catch /^Vim\%((\a\+)\)\=:E480/
1016 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1017 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001018 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001019" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001020 if @* != keepregstar | sil! let @* = keepregstar | endif
1021 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001022 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001023 sil! let @/ = keepregslash
1024" call Dret("netrw#Explore : no files matched pattern")
1025 return
1026 endtry
1027 let s:netrw_curdir = b:netrw_curdir
1028 let w:netrw_explore_list = getqflist()
1029 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1030 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1031
1032 elseif starpat == 3
1033 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001034" call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001035 let filepat= substitute(dirname,'^\*/','','')
1036 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001037" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1038" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001039 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1040 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1041
1042 elseif starpat == 4
1043 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001044" call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001045 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1046 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1047 endif " switch on starpat to build w:netrw_explore_list
1048
1049 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001050" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1051" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001052
1053 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001054 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001055 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001056" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001057 if @* != keepregstar | sil! let @* = keepregstar | endif
1058 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001059 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001060 sil! let @/ = keepregslash
1061" call Dret("netrw#Explore : no files matched")
1062 return
1063 endif
1064 endif " if indx ... endif
1065
1066 " NetrwStatusLine support - for exploring support
1067 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001068" call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001069
1070 " wrap the indx around, but issue a note
1071 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001072" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001073 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1074 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001075 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001076 endif
1077
1078 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001079" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001080 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001081" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001082
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001083" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001084 call netrw#LocalBrowseCheck(newdir)
1085 if !exists("w:netrw_liststyle")
1086 let w:netrw_liststyle= g:netrw_liststyle
1087 endif
1088 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001089 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001090 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001091 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001092 endif
1093 let w:netrw_explore_mtchcnt = indx + 1
1094 let w:netrw_explore_bufnr = bufnr("%")
1095 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001096 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001097" call Decho("....explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001098
1099 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001100" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001101 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001102 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your vim needs the +path_extra feature for Exploring with **!",44)
Bram Moolenaarff034192013-04-24 18:51:19 +02001103 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001104 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001105" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001106 if @* != keepregstar | sil! let @* = keepregstar | endif
1107 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001108 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001109 sil! let @/ = keepregslash
1110" call Dret("netrw#Explore : missing +path_extra")
1111 return
1112 endif
1113
1114 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001115" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001116 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1117 sil! unlet w:netrw_treedict
1118 sil! unlet w:netrw_treetop
1119 endif
1120 let newdir= dirname
1121 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001122 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001123 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001124 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001125 endif
1126 endif
1127
1128 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001129" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1130" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001131 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001132" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001133 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001134 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001135" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001136 let s:explore_prvdir = b:netrw_curdir
1137 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001138 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001139 if b:netrw_curdir !~ '/$'
1140 let dirlen= dirlen + 1
1141 endif
1142 let prvfname= ""
1143 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001144" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001145 if fname =~ '^'.b:netrw_curdir
1146 if s:explore_match == ""
1147 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1148 else
1149 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1150 endif
1151 elseif fname !~ '^/' && fname != prvfname
1152 if s:explore_match == ""
1153 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1154 else
1155 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1156 endif
1157 endif
1158 let prvfname= fname
1159 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001160" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001161 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1162 exe "2match netrwMarkFile /".s:explore_match."/"
1163 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001164 endif
1165 echo "<s-up>==Pexplore <s-down>==Nexplore"
1166 else
1167 2match none
1168 if exists("s:explore_match") | unlet s:explore_match | endif
1169 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001170" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001171 endif
1172
Bram Moolenaara6878372014-03-22 21:02:50 +01001173 " since Explore may be used to initialize netrw's browser,
1174 " there's no danger of a late FocusGained event on initialization.
1175 " Consequently, set s:netrw_events to 2.
1176 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001177 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001178" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001179 if @* != keepregstar | sil! let @* = keepregstar | endif
1180 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001181 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001182 sil! let @/ = keepregslash
1183" call Dret("netrw#Explore : @/<".@/.">")
1184endfun
1185
1186" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001187" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001188" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1189" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1190" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1191" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1192" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001193fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001194" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195 let curwin= winnr()
1196
Bram Moolenaara6878372014-03-22 21:02:50 +01001197 if a:0 > 0 && a:1 != ""
1198 " if a netrw window is already on the left-side of the tab
1199 " and a directory has been specified, explore with that
1200 " directory.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001201 let a1 = expand(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01001202 exe "1wincmd w"
1203 if &ft == "netrw"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001204 exe "Explore ".fnameescape(a1)
1205 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001206 let s:lexplore_win= curwin
1207 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001208 if exists("t:netrw_lexposn")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 unlet t:netrw_lexposn
1210 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001211 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001212 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001213 exe curwin."wincmd w"
1214 else
1215 let a1= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001216 endif
1217
Bram Moolenaar8d043172014-01-23 14:24:41 +01001218 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001219 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001220 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001221 else
1222 let lexwinnr= 0
1223 endif
1224
1225 if lexwinnr > 0
1226 " close down netrw explorer window
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227 exe lexwinnr."wincmd w"
1228 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001229 let t:netrw_lexposn = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001230 close
1231 if lexwinnr < curwin
1232 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001233 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001234 if lexwinnr != curwin
1235 exe curwin."wincmd w"
1236 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001237 unlet t:netrw_lexbufnr
1238
1239 else
1240 " open netrw explorer window
1241 exe "1wincmd w"
1242 let keep_altv = g:netrw_altv
1243 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001244 if a:count != 0
1245 let netrw_winsize = g:netrw_winsize
1246 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001247 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001248 let curfile= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001249 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
1250 if a:0 > 0 && a1 != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001251 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001252 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001253 elseif curfile =~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02001254 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001255 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02001256 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001257 endif
1258 if a:count != 0
1259 let g:netrw_winsize = netrw_winsize
1260 endif
1261 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001262 let g:netrw_altv = keep_altv
1263 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001264 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1265 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001266 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001267 set bh=wipe
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 if exists("t:netrw_lexposn")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001269 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001270 unlet t:netrw_lexposn
1271 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001272 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001273
1274 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001275 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001276 if a:rightside
1277 let g:netrw_chgwin= 1
1278 else
1279 let g:netrw_chgwin= 2
1280 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001281 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001282
Bram Moolenaar8d043172014-01-23 14:24:41 +01001283endfun
1284
1285" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001286" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001287" supports :NetrwClean -- remove netrw from first directory on runtimepath
1288" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001289fun! netrw#Clean(sys)
1290" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001291
1292 if a:sys
1293 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1294 else
1295 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1296 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001297" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001298 let diddel= 0
1299 let diddir= ""
1300
1301 if choice == 1
1302 for dir in split(&rtp,',')
1303 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001304" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001305 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1306 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1307 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1308 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1309 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1310 if s:NetrwDelete(dir."/syntax/netrwlist.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrwlist.vim",55) |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00001311 let diddir= dir
1312 let diddel= diddel + 1
1313 if !a:sys|break|endif
1314 endif
1315 endfor
1316 endif
1317
1318 echohl WarningMsg
1319 if diddel == 0
1320 echomsg "netrw is either not installed or not removable"
1321 elseif diddel == 1
1322 echomsg "removed one copy of netrw from <".diddir.">"
1323 else
1324 echomsg "removed ".diddel." copies of netrw"
1325 endif
1326 echohl None
1327
Bram Moolenaara6878372014-03-22 21:02:50 +01001328" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001329endfun
1330
Bram Moolenaar5c736222010-01-06 20:54:52 +01001331" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001332" netrw#MakeTgt: make a target out of the directory name provided {{{2
1333fun! netrw#MakeTgt(dname)
1334" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1335 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001336 let svpos = winsaveview()
1337" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001338 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1339" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001340 if s:netrwmftgt_islocal
1341 let netrwmftgt= simplify(a:dname)
1342 else
1343 let netrwmftgt= a:dname
1344 endif
1345 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1346 " re-selected target, so just clear it
1347 unlet s:netrwmftgt s:netrwmftgt_islocal
1348 else
1349 let s:netrwmftgt= netrwmftgt
1350 endif
1351 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001352 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001353 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001354" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1355 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001356" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001357endfun
1358
Bram Moolenaara6878372014-03-22 21:02:50 +01001359" ---------------------------------------------------------------------
1360" netrw#Obtain: {{{2
1361" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001362" islocal=0 obtain from remote source
1363" =1 obtain from local source
1364" fname : a filename or a list of filenames
1365" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001366fun! netrw#Obtain(islocal,fname,...)
1367" call Dfunc("netrw#Obtain(islocal=".a:islocal." fname<".((type(a:fname) == 1)? a:fname : string(a:fname)).">) a:0=".a:0)
Bram Moolenaarff034192013-04-24 18:51:19 +02001368 " NetrwStatusLine support - for obtaining support
1369
1370 if type(a:fname) == 1
1371 let fnamelist= [ a:fname ]
1372 elseif type(a:fname) == 3
1373 let fnamelist= a:fname
1374 else
1375 call netrw#ErrorMsg(s:ERROR,"attempting to use NetrwObtain on something not a filename or a list",62)
Bram Moolenaara6878372014-03-22 21:02:50 +01001376" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001377 return
1378 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001379" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001380 if a:0 > 0
1381 let tgtdir= a:1
1382 else
1383 let tgtdir= getcwd()
1384 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001385" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001386
1387 if exists("b:netrw_islocal") && b:netrw_islocal
1388 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001389" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001390 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1391 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001392 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001393 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001394" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001395 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001396" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001397 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001398 if v:shell_error != 0
1399 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001400" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001401 return
1402 endif
1403 endfor
1404 else
1405 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001406" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1407 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1408" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001409 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001410 if v:shell_error != 0
1411 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001412" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001413 return
1414 endif
1415 endif
1416 elseif !exists("b:netrw_curdir")
1417 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1418 else
1419 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1420 endif
1421
1422 else
1423 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001424" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001425 if type(a:fname) == 1
1426 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1427 endif
1428 call s:NetrwMethod(b:netrw_curdir)
1429
1430 if b:netrw_method == 4
1431 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001432" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001433 if exists("g:netrw_port") && g:netrw_port != ""
1434 let useport= " ".g:netrw_scpport." ".g:netrw_port
1435 else
1436 let useport= ""
1437 endif
1438 if b:netrw_fname =~ '/'
1439 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1440 else
1441 let path= ""
1442 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001443 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001444 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".filelist." ".s:ShellEscape(tgtdir,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001445
1446 elseif b:netrw_method == 2
1447 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001448" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001449 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001450 let tmpbufnr= bufnr("%")
1451 setl ff=unix
1452 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001453 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001454" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001455 endif
1456
1457 if exists("b:netrw_fname") && b:netrw_fname != ""
1458 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001459" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001460 endif
1461
1462 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001463 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001464" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001465 endif
1466 for fname in fnamelist
1467 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001468" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001469 endfor
1470 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001471 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001472 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001473 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001474 endif
1475 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1476 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1477 let debugkeep= &debug
1478 setl debug=msg
1479 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1480 let &debug= debugkeep
1481 endif
1482
1483 elseif b:netrw_method == 3
1484 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001485" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001486 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001487 let tmpbufnr= bufnr("%")
1488 setl ff=unix
1489
1490 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001491 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001492" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001493 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001494 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001495" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001496 endif
1497
1498 if exists("g:netrw_uid") && g:netrw_uid != ""
1499 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001500 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001501" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001502 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001503 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001504 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001505" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001506 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001507 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001508" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001509 endif
1510 endif
1511
1512 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001513 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001514" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001515 endif
1516
1517 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001518 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001519" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001520 endif
1521
1522 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001523 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001524" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001525 endif
1526
1527 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001528 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001529" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001530 endif
1531 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001532 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001533 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001534" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001535
1536 " perform ftp:
1537 " -i : turns off interactive prompting from ftp
1538 " -n unix : DON'T use <.netrc>, even though it exists
1539 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001540 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1541 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001542 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001543 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1544 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001545" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001546 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001547 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001548 endif
1549 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001550
1551 elseif b:netrw_method == 9
1552 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001553" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001554 if a:fname =~ '/'
1555 let localfile= substitute(a:fname,'^.*/','','')
1556 else
1557 let localfile= a:fname
1558 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001559 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1).s:ShellEscape(localfile)." ".s:ShellEscape(tgtdir))
Bram Moolenaar13600302014-05-22 18:26:40 +02001560
Bram Moolenaarff034192013-04-24 18:51:19 +02001561 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001562 " probably a badly formed url; protocol not recognized
1563" call Dret("netrw#Obtain : unsupported method")
1564 return
1565
1566 else
1567 " protocol recognized but not supported for Obtain (yet?)
1568 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001569 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001570 endif
1571" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001572 return
1573 endif
1574
1575 " restore status line
1576 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001577 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001578 endif
1579
1580 endif
1581
1582 " cleanup
1583 if exists("tmpbufnr")
1584 if bufnr("%") != tmpbufnr
1585 exe tmpbufnr."bw!"
1586 else
1587 q!
1588 endif
1589 endif
1590
Bram Moolenaara6878372014-03-22 21:02:50 +01001591" call Dret("netrw#Obtain")
1592endfun
1593
1594" ---------------------------------------------------------------------
1595" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1596fun! netrw#Nread(mode,fname)
1597" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001598 let svpos= winsaveview()
1599" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001600 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001601" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1602 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001603
1604 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1605 if exists("w:netrw_bannercnt")
1606 " start with cursor just after the banner
1607 exe w:netrw_bannercnt
1608 endif
1609 endif
1610" call Dret("netrw#Nread")
1611endfun
1612
1613" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001614" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1615" Options get restored by s:NetrwOptionsRestore()
1616"
1617" Option handling:
1618" * save user's options (s:NetrwOptionsSave)
1619" * set netrw-safe options (s:NetrwOptionsSafe)
1620" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1621" * restore user's options (s:netrwOPtionsRestore)
1622" - restore a user option when != safe option (s:NetrwRestoreSetting)
1623" vt: (variable type) normally its either "w:" or "s:"
1624fun! s:NetrwOptionsSave(vt)
1625" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1626" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001627" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt." hid=".&hid,'~'.expand("<slnum>"))
1628" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001629
1630 if !exists("{a:vt}netrw_optionsave")
1631 let {a:vt}netrw_optionsave= 1
1632 else
1633" call Dret("s:NetrwOptionsSave : options already saved")
1634 return
1635 endif
1636" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1637
1638 " Save current settings and current directory
1639" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1640 let s:yykeep = @@
1641 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1642 let {a:vt}netrw_aikeep = &l:ai
1643 let {a:vt}netrw_awkeep = &l:aw
1644 let {a:vt}netrw_bhkeep = &l:bh
1645 let {a:vt}netrw_blkeep = &l:bl
1646 let {a:vt}netrw_btkeep = &l:bt
1647 let {a:vt}netrw_bombkeep = &l:bomb
1648 let {a:vt}netrw_cedit = &cedit
1649 let {a:vt}netrw_cikeep = &l:ci
1650 let {a:vt}netrw_cinkeep = &l:cin
1651 let {a:vt}netrw_cinokeep = &l:cino
1652 let {a:vt}netrw_comkeep = &l:com
1653 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001654 let {a:vt}netrw_cuckeep = &l:cuc
1655 let {a:vt}netrw_culkeep = &l:cul
1656" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001657 let {a:vt}netrw_diffkeep = &l:diff
1658 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001659 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1660 let {a:vt}netrw_ffkeep = &l:ff
1661 endif
1662 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1663 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001664 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001665 let {a:vt}netrw_hidkeep = &l:hidden
1666 let {a:vt}netrw_imkeep = &l:im
1667 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001668 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001669 let {a:vt}netrw_lskeep = &l:ls
1670 let {a:vt}netrw_makeep = &l:ma
1671 let {a:vt}netrw_magickeep = &l:magic
1672 let {a:vt}netrw_modkeep = &l:mod
1673 let {a:vt}netrw_nukeep = &l:nu
1674 let {a:vt}netrw_rnukeep = &l:rnu
1675 let {a:vt}netrw_repkeep = &l:report
1676 let {a:vt}netrw_rokeep = &l:ro
1677 let {a:vt}netrw_selkeep = &l:sel
1678 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001679 if !g:netrw_use_noswf
1680 let {a:vt}netrw_swfkeep = &l:swf
1681 endif
1682 let {a:vt}netrw_tskeep = &l:ts
1683 let {a:vt}netrw_twkeep = &l:tw " textwidth
1684 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1685 let {a:vt}netrw_wrapkeep = &l:wrap
1686 let {a:vt}netrw_writekeep = &l:write
1687
1688 " save a few selected netrw-related variables
1689" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1690 if g:netrw_keepdir
1691 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001692" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001693 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001694 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001695 sil! let {a:vt}netrw_starkeep = @*
1696 sil! let {a:vt}netrw_pluskeep = @+
1697 endif
1698 sil! let {a:vt}netrw_slashkeep= @/
1699
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001700" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001701" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
1702" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1703endfun
1704
1705" ---------------------------------------------------------------------
1706" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1707" Use s:NetrwSaveOptions() to save user settings
1708" Use s:NetrwOptionsRestore() to restore user settings
1709fun! s:NetrwOptionsSafe(islocal)
1710" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1711" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1712" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
1713 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1714 call s:NetrwSetSafeSetting("&l:ai",0)
1715 call s:NetrwSetSafeSetting("&l:aw",0)
1716 call s:NetrwSetSafeSetting("&l:bl",0)
1717 call s:NetrwSetSafeSetting("&l:bomb",0)
1718 if a:islocal
1719 call s:NetrwSetSafeSetting("&l:bt","nofile")
1720 else
1721 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1722 endif
1723 call s:NetrwSetSafeSetting("&l:ci",0)
1724 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001725 if g:netrw_fastbrowse > a:islocal
1726 call s:NetrwSetSafeSetting("&l:bh","hide")
1727 else
1728 call s:NetrwSetSafeSetting("&l:bh","delete")
1729 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001730 call s:NetrwSetSafeSetting("&l:cino","")
1731 call s:NetrwSetSafeSetting("&l:com","")
1732 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1733 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1734 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001735 if &go =~ 'a' | set go-=a | endif
1736 if &go =~ 'A' | set go-=A | endif
1737 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001738 call s:NetrwSetSafeSetting("&l:hid",0)
1739 call s:NetrwSetSafeSetting("&l:im",0)
1740 setl isk+=@ isk+=* isk+=/
1741 call s:NetrwSetSafeSetting("&l:magic",1)
1742 if g:netrw_use_noswf
1743 call s:NetrwSetSafeSetting("swf",0)
1744 endif
1745 call s:NetrwSetSafeSetting("&l:report",10000)
1746 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1747 call s:NetrwSetSafeSetting("&l:spell",0)
1748 call s:NetrwSetSafeSetting("&l:tw",0)
1749 call s:NetrwSetSafeSetting("&l:wig","")
1750 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001751
1752 " set up cuc and cul based on g:netrw_cursor and listing style
1753 " COMBAK -- cuc cul related
1754 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001755
1756 " allow the user to override safe options
1757" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1758 if &ft == "netrw"
1759" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1760 keepalt NetrwKeepj doau FileType netrw
1761 endif
1762
1763" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1764" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
1765" call Dret("s:NetrwOptionsSafe")
1766endfun
1767
1768" ---------------------------------------------------------------------
1769" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1770fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001771 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001772 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1773 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1774 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001775 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001776 else
1777 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001778 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001779 return
1780 endif
1781 unlet {a:vt}netrw_optionsave
1782
1783 if exists("+acd")
1784 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001785 let curdir = getcwd()
1786 let &l:acd = {a:vt}netrw_acdkeep
1787 unlet {a:vt}netrw_acdkeep
1788 if &l:acd
1789 call s:NetrwLcd(curdir)
1790 endif
1791 endif
1792 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001793 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1794 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1795 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1796 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1797 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1798 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1799 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1800 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1801 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1802 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1803 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1804 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1805 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1806 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1807 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001808 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001809 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1810 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001811 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001812 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001813 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1814 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001815 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001816 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1817 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001818 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001819 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1820 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001821 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1822 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1823 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1824 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001825 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001826 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1827 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1828 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001829 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1830 call s:NetrwRestoreSetting("s:yykeep","@@")
1831 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1832 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1833 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1834 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1835
Bram Moolenaara6878372014-03-22 21:02:50 +01001836 if exists("{a:vt}netrw_swfkeep")
1837 if &directory == ""
1838 " user hasn't specified a swapfile directory;
1839 " netrw will temporarily set the swapfile directory
1840 " to the current directory as returned by getcwd().
1841 let &l:directory= getcwd()
1842 sil! let &l:swf = {a:vt}netrw_swfkeep
1843 setl directory=
1844 unlet {a:vt}netrw_swfkeep
1845 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001846 if !g:netrw_use_noswf
1847 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1848 sil! let &l:swf= {a:vt}netrw_swfkeep
1849 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001850 unlet {a:vt}netrw_swfkeep
1851 endif
1852 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001853 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001854 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1855 if exists("{a:vt}netrw_dirkeep")
1856 call s:NetrwLcd(dirkeep)
1857 unlet {a:vt}netrw_dirkeep
1858 endif
1859 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001860 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001861 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1862 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001863 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001864 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001865
Bram Moolenaara6878372014-03-22 21:02:50 +01001866 " Moved the filetype detect here from NetrwGetFile() because remote files
1867 " were having their filetype detect-generated settings overwritten by
1868 " NetrwOptionRestore.
1869 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001870 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001871 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001872endfun
1873
1874" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001875" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1876" but only when the options' value and the safe setting differ
1877" Doing this means that netrw will not come up as having changed a
1878" setting last when it really didn't actually change it.
1879"
1880" Called from s:NetrwOptionsSafe
1881" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1882fun! s:NetrwSetSafeSetting(setting,safesetting)
1883" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001884
Bram Moolenaar85850f32019-07-19 22:05:51 +02001885 if a:setting =~ '^&'
1886" call Decho("fyi: a:setting starts with &")
1887 exe "let settingval= ".a:setting
1888" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001889
Bram Moolenaar85850f32019-07-19 22:05:51 +02001890 if settingval != a:safesetting
1891" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1892 if type(a:safesetting) == 0
1893 exe "let ".a:setting."=".a:safesetting
1894 elseif type(a:safesetting) == 1
1895 exe "let ".a:setting."= '".a:safesetting."'"
1896 else
1897 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1898 endif
1899 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001900 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001901
Bram Moolenaar85850f32019-07-19 22:05:51 +02001902" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001903endfun
1904
1905" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001906" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1907" but only if the setting value differs from the associated keepvar.
1908" Doing this means that netrw will not come up as having changed a
1909" setting last when it really didn't actually change it.
1910"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001911" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001912" keepvars are set up by s:NetrwOptionsSave
1913fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001914""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001915
Bram Moolenaar85850f32019-07-19 22:05:51 +02001916 " typically called from s:NetrwOptionsRestore
1917 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1918 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001919 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001920 if exists(a:keepvar)
1921 exe "let keepvarval= ".a:keepvar
1922 exe "let setting= ".a:setting
1923
1924"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1925"" call Decho("fyi: keepvarval=".keepvarval)
1926"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1927
1928 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001929"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001930 if type(a:setting) == 0
1931 exe "let ".a:setting."= ".keepvarval
1932 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001933 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001934 else
1935 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1936 endif
1937 endif
1938
1939 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001940 endif
1941
Bram Moolenaar85850f32019-07-19 22:05:51 +02001942"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001943endfun
1944
1945" ---------------------------------------------------------------------
1946" NetrwStatusLine: {{{2
1947fun! NetrwStatusLine()
1948
1949" vvv NetrwStatusLine() debugging vvv
1950" let g:stlmsg=""
1951" if !exists("w:netrw_explore_bufnr")
1952" let g:stlmsg="!X<explore_bufnr>"
1953" elseif w:netrw_explore_bufnr != bufnr("%")
1954" let g:stlmsg="explore_bufnr!=".bufnr("%")
1955" endif
1956" if !exists("w:netrw_explore_line")
1957" let g:stlmsg=" !X<explore_line>"
1958" elseif w:netrw_explore_line != line(".")
1959" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1960" endif
1961" if !exists("w:netrw_explore_list")
1962" let g:stlmsg=" !X<explore_list>"
1963" endif
1964" ^^^ NetrwStatusLine() debugging ^^^
1965
1966 if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr("%") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list")
1967 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001968 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001969 let &laststatus = s:netrw_users_ls
1970 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1971 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1972 return ""
1973 else
1974 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1975 endif
1976endfun
1977
Bram Moolenaar85850f32019-07-19 22:05:51 +02001978" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001979" Netrw Transfer Functions: {{{1
1980" ===============================
1981
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001983" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001984" mode: =0 read remote file and insert before current line
1985" =1 read remote file and insert after current line
1986" =2 replace with remote file
1987" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001988fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001989" call Dfunc("netrw#NetRead(mode=".a:mode.",...) a:0=".a:0." ".g:loaded_netrw.((a:0 > 0)? " a:1<".a:1.">" : ""))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001990
Bram Moolenaar5c736222010-01-06 20:54:52 +01001991 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001992 call s:NetrwOptionsSave("w:")
1993 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001994 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001995 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1996 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1997 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001998" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001999
Bram Moolenaar5c736222010-01-06 20:54:52 +01002000 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002001 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002002 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002003 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002004 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002005 elseif a:mode == 2 " replace with remote file
2006 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002007 elseif a:mode == 3 " skip read of file (leave as temporary)
2008 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002009 else
2010 exe a:mode
2011 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002012 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002013 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002014" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002015
Bram Moolenaar5c736222010-01-06 20:54:52 +01002016 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002017 let tmpfile= s:GetTempfile("")
2018 if tmpfile == ""
2019" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002020 return
2021 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002022
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002023 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002024
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002025 " attempt to repeat with previous host-file-etc
2026 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002027" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002028 let choice = b:netrw_lastfile
2029 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002030
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002031 else
2032 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002033" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002034
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002035 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002036 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002037 echomsg 'NetRead Usage:'
2038 echomsg ':Nread machine:path uses rcp'
2039 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2040 echomsg ':Nread "machine id password path" uses ftp'
2041 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2042 echomsg ':Nread fetch://machine/path uses fetch'
2043 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2044 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002045 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002046 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002047 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2048 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2049 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2050 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002051 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002052 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002053
Bram Moolenaar9964e462007-05-05 17:54:07 +00002054 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002055 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002056" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002057 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002058 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002059 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002060 else
2061 " case "... ... ..."
2062 let choice = strpart(choice,1,strlen(choice)-1)
2063 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002064
Bram Moolenaar9964e462007-05-05 17:54:07 +00002065 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002066 let wholechoice = wholechoice . " " . choice
2067 let ichoice = ichoice + 1
2068 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002069 if !exists("g:netrw_quiet")
2070 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2071 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002072" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002073 return
2074 endif
2075 let choice= a:{ichoice}
2076 endwhile
2077 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2078 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 endif
2080 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002082" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002083 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002084
Bram Moolenaar5c736222010-01-06 20:54:52 +01002085 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002086 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002087 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002088" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002089 return
2090 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002091 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002092
Bram Moolenaar8d043172014-01-23 14:24:41 +01002093 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002094" call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02002095 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002096" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002097 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002098" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002099 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002101
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002102 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002103 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002104 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002105 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2106 echo "(netrw) Processing your read request..."
2107 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002108
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002109 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002110 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002111 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002112" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002113 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002115 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002116 " ER: the tmpfile is full path: rcp sees C:\... as host C
2117 if s:netrw_has_nt_rcp == 1
2118 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2119 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2120 else
2121 " Any way needed it machine contains a '.'
2122 let uid_machine = g:netrw_machine .'.'. $USERNAME
2123 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002125 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2126 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2127 else
2128 let uid_machine = g:netrw_machine
2129 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002131 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".s:ShellEscape(uid_machine.":".b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002132 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002133 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002134
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002135 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002136 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002137 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002138" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002139 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002140 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002141 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002142 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002143 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002144" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002145 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002146 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002147" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002148 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002149 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002150" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002151 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002152 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002153 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002154 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002155 endif
2156 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar83bab712005-08-01 21:58:57 +00002157 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002158 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002159 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002160 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002161 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002162 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002163 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002164 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002165 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2166 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002167 q!
2168 endif
2169 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002170 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002172
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002173 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002174 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002175 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2176 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002177" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002178 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002179 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002180 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002181 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002182 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002183 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002184" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002185 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002186 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002187" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002188 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002189
Bram Moolenaar97d62492012-11-15 21:28:22 +01002190 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002191 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002192 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002193" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002194 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002195 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002196 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002197" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002198 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002199 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002200" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002201 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002202 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002203
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002204 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002205 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002206" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002207 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002208 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002209 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002210" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002211 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002212 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002213" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002214
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002215 " perform ftp:
2216 " -i : turns off interactive prompting from ftp
2217 " -n unix : DON'T use <.netrc>, even though it exists
2218 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002219 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002220 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002221 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2222 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002223" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002224 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002225 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002226 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002227 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002228 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002229 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002231
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002232 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002233 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002235" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002237 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002238 else
2239 let useport= ""
2240 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002241 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2242 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002243 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002244 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2245 else
2246 let tmpfile_get = tmpfile
2247 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002248 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".escape(s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1),' ')." ".s:ShellEscape(tmpfile_get,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002249 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002250 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002251
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002252 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002253 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002254 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002255" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002256 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002257 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002258 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002259 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002260" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002261 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002262 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002263
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002264 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2265 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002266" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002267 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002268 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".s:ShellEscape(tmpfile,1))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002269 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002270 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002271 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002272 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002273
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002274 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002275 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002276" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002277 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2278 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002279" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2280" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2281 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.netrw_html,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002282 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002283" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002284 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002285 endif
2286 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002287" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002288 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002289
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002290 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002291 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002292 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002293" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002294
Bram Moolenaar5c736222010-01-06 20:54:52 +01002295 if !executable(g:netrw_dav_cmd)
2296 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2297" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2298 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002299 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002300 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002301 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_dav_cmd." ".s:ShellEscape("dav://".g:netrw_machine.b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002302 else
2303 " Construct execution string (four lines) which will be passed through filter
2304 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2305 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002306 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002307 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002308 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002309 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002310 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002311 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002312 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002313 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002314 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002315 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2316 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002317
Bram Moolenaar5c736222010-01-06 20:54:52 +01002318 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002319 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002320 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002321 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002322 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002323 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002324 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002325
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002326 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002327 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002328 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002329" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002330 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".s:ShellEscape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002331 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002332 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002333
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002334 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002335 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002336 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002337 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002338" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002339 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002340 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002341 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002342 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002343" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002344 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002345 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002346 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002347 let netrw_option= "http"
2348 else
2349 let netrw_option= "ftp"
2350 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002351" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002352
Bram Moolenaar446cb832008-06-24 21:56:24 +00002353 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002354 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002355 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002356 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002357 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002358
Bram Moolenaar446cb832008-06-24 21:56:24 +00002359 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002360 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002361" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002362 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002363
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002364 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002365 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002366 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002367" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2368 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002369 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002370 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002371
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002372 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002373 " NetRead: (file) NetRead Method #10 {{{3
2374 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002375" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2376 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002377 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2378 let b:netrw_lastfile = choice
2379
2380 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002381 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002382 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002383 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002384 endif
2385 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002386
Bram Moolenaar5c736222010-01-06 20:54:52 +01002387 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002388 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002389" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002390 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 unlet b:netrw_fname
2392 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002393 if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002394" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002395 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002396 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002397 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002398
Bram Moolenaar9964e462007-05-05 17:54:07 +00002399" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002400endfun
2401
2402" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002403" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002404fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002405" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002406
Bram Moolenaar5c736222010-01-06 20:54:52 +01002407 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002408 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002409 call s:NetrwOptionsSave("w:")
2410 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002411
Bram Moolenaar5c736222010-01-06 20:54:52 +01002412 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002413 let tmpfile= s:GetTempfile("")
2414 if tmpfile == ""
2415" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002416 return
2417 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002418
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002419 if a:0 == 0
2420 let ichoice = 0
2421 else
2422 let ichoice = 1
2423 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002424
Bram Moolenaar9964e462007-05-05 17:54:07 +00002425 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002426" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002427 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002428 " For binary writes, always write entire file.
2429 " (line numbers don't really make sense for that).
2430 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002431" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002432 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002433 elseif g:netrw_cygwin
2434 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002435 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002436" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002437 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002438 else
2439 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002440" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002441 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002442 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002443
Bram Moolenaar9964e462007-05-05 17:54:07 +00002444 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002445 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002446 " on the temporary file's name. Deletion of the temporary file during
2447 " cleanup then causes an error message.
2448 0file!
2449 endif
2450
Bram Moolenaar5c736222010-01-06 20:54:52 +01002451 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002452 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002453
Bram Moolenaar9964e462007-05-05 17:54:07 +00002454 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002455 " attempt to repeat with previous host-file-etc
2456 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002457" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002458 let choice = b:netrw_lastfile
2459 let ichoice= ichoice + 1
2460 else
2461 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002462
Bram Moolenaar8d043172014-01-23 14:24:41 +01002463 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002464 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002465 echomsg 'NetWrite Usage:"'
2466 echomsg ':Nwrite machine:path uses rcp'
2467 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2468 echomsg ':Nwrite "machine id password path" uses ftp'
2469 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2470 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2471 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2472 echomsg ':Nwrite rcp://machine/path uses rcp'
2473 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2474 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2475 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002476 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002477 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002478
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002479 elseif match(choice,"^\"") != -1
2480 if match(choice,"\"$") != -1
2481 " case "..."
2482 let choice=strpart(choice,1,strlen(choice)-2)
2483 else
2484 " case "... ... ..."
2485 let choice = strpart(choice,1,strlen(choice)-1)
2486 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002487
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002488 while match(choice,"\"$") == -1
2489 let wholechoice= wholechoice . " " . choice
2490 let ichoice = ichoice + 1
2491 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002492 if !exists("g:netrw_quiet")
2493 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2494 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002495" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002496 return
2497 endif
2498 let choice= a:{ichoice}
2499 endwhile
2500 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2501 endif
2502 endif
2503 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002504 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002505" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002506
Bram Moolenaar9964e462007-05-05 17:54:07 +00002507 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002508 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002509 if !exists("b:netrw_method") || b:netrw_method < 0
2510" call Dfunc("netrw#NetWrite : unsupported method")
2511 return
2512 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002513
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002514 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002515 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002516 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002517 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2518 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002519" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002520 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002521
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002522 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002523 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002524 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002525" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002526 if s:netrw_has_nt_rcp == 1
2527 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2528 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2529 else
2530 let uid_machine = g:netrw_machine .'.'. $USERNAME
2531 endif
2532 else
2533 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2534 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2535 else
2536 let uid_machine = g:netrw_machine
2537 endif
2538 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002539 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(uid_machine.":".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002540 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002541
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002542 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002543 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002544 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002545" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002546 let netrw_fname = b:netrw_fname
2547
2548 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2549 let bhkeep = &l:bh
2550 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002551 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002552 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002553
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002554" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002555 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002556 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002557" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002558 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002559 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002560" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002561 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002562 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002563" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002564 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002565 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002567" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2568 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 endif
2570 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2571 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002572 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002573 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002574 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002575 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002577
2578 " remove enew buffer (quietly)
2579 let filtbuf= bufnr("%")
2580 exe curbuf."b!"
2581 let &l:bh = bhkeep
2582 exe filtbuf."bw!"
2583
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002585
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002586 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002587 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002588 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002589 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002590" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002591 let netrw_fname = b:netrw_fname
2592 let bhkeep = &l:bh
2593
2594 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2595 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002596 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002597 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002598 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002599
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002600 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002601 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002602" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002603 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002604 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002605" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002606 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002607 if exists("g:netrw_uid") && g:netrw_uid != ""
2608 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002609 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002610" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002611 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002612 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002613 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002614" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002615 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002616 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002618 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002619 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002620 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002621" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002622 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002623 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002624" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002625 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002626 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002627" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002628 " save choice/id/password for future use
2629 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002630
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002631 " perform ftp:
2632 " -i : turns off interactive prompting from ftp
2633 " -n unix : DON'T use <.netrc>, even though it exists
2634 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002635 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002636 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002637 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2638 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002639 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002640 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002641 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002642 let mod=1
2643 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644
2645 " remove enew buffer (quietly)
2646 let filtbuf= bufnr("%")
2647 exe curbuf."b!"
2648 let &l:bh= bhkeep
2649 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002650
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002651 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002652 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002653 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002654" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002655 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002656 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002657 else
2658 let useport= ""
2659 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002660 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002661 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002662
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002663 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002664 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002665 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002666" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002667 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2668 if executable(curl)
2669 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002670 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_put_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(url,1) )
Bram Moolenaar8d043172014-01-23 14:24:41 +01002671 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002672 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002673 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002674
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002675 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002676 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002677 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002678" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002679
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002680 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002681 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2682 let bhkeep = &l:bh
2683
2684 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2685 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002686 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002687 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002688
Bram Moolenaarff034192013-04-24 18:51:19 +02002689 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002690 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002691 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002692 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002693 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002694 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002695 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002696 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002697 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002698 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002699
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002700 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002701 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002702 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002703
2704 " remove enew buffer (quietly)
2705 let filtbuf= bufnr("%")
2706 exe curbuf."b!"
2707 let &l:bh = bhkeep
2708 exe filtbuf."bw!"
2709
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002710 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002711
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002712 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002713 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002714 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002715" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002716 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002717 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002718
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002719 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002720 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002721 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002722" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002723 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2725 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2726 else
2727 let uid_machine = g:netrw_machine
2728 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002729
2730 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2731 let bhkeep = &l:bh
2732 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002733 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002734 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002735
Bram Moolenaarff034192013-04-24 18:51:19 +02002736 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002737 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002738" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002739 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002740 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002741 let filtbuf= bufnr("%")
2742 exe curbuf."b!"
2743 let &l:bh = bhkeep
2744 exe filtbuf."bw!"
2745 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002746
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002747 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002748 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002749 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002750 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002751 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002753 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002754
Bram Moolenaar5c736222010-01-06 20:54:52 +01002755 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002756" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002757 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002758" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002759 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002760 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002761 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002762
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002763 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002764 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002765 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002766" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02002767 elseif !exists("leavemod")
2768 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002769" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002770 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002771" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002773
Bram Moolenaar9964e462007-05-05 17:54:07 +00002774" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002775endfun
2776
2777" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002778" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002779" uses NetRead to get a copy of the file into a temporarily file,
2780" then sources that file,
2781" then removes that file.
2782fun! netrw#NetSource(...)
2783" call Dfunc("netrw#NetSource() a:0=".a:0)
2784 if a:0 > 0 && a:1 == '?'
2785 " give help
2786 echomsg 'NetSource Usage:'
2787 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2788 echomsg ':Nsource fetch://machine/path uses fetch'
2789 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002790 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002791 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2792 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2793 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2794 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2795 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002796 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002797 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002798 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002799 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002800" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002801 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002802" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002803 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002804" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002805 if delete(s:netrw_tmpfile)
2806 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2807 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002808 unlet s:netrw_tmpfile
2809 else
2810 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2811 endif
2812 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002813 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002814 endif
2815" call Dret("netrw#NetSource")
2816endfun
2817
Bram Moolenaar8d043172014-01-23 14:24:41 +01002818" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002819" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2820" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002821fun! netrw#SetTreetop(iscmd,...)
2822" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2823" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002824
Bram Moolenaar85850f32019-07-19 22:05:51 +02002825 " iscmd==0: netrw#SetTreetop called using gn mapping
2826 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2827" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002828 " clear out the current tree
2829 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002830" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002831 let inittreetop= w:netrw_treetop
2832 unlet w:netrw_treetop
2833 endif
2834 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002835" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002836 unlet w:netrw_treedict
2837 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002838" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002839
Bram Moolenaar85850f32019-07-19 22:05:51 +02002840 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002841 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002842" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002843 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002844 if isdirectory(s:NetrwFile(a:1))
2845" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002846 let treedir = a:1
2847 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002848 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002849 let treedir = b:netrw_curdir."/".a:1
2850 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002851" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002852 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002853 " normally the cursor is left in the message window.
2854 " However, here this results in the directory being listed in the message window, which is not wanted.
2855 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002856 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002857 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002858 let treedir = "."
2859 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002860 endif
2861 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002862" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002863
2864 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002865 let islocal= expand("%") !~ '^\a\{3,}://'
2866" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002867
2868 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002869 if islocal
2870 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2871 else
2872 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2873 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002874
Bram Moolenaara6878372014-03-22 21:02:50 +01002875" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002876endfun
2877
Bram Moolenaar9964e462007-05-05 17:54:07 +00002878" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002879" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002880" readcmd == %r : replace buffer with newly read file
2881" == 0r : read file at top of buffer
2882" == r : read file after current line
2883" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002884fun! s:NetrwGetFile(readcmd, tfile, method)
2885" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002886
2887 " readcmd=='t': simply do nothing
2888 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002889" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01002890" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002891 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002892 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002893
Bram Moolenaar9964e462007-05-05 17:54:07 +00002894 " get name of remote filename (ie. url and all)
2895 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002897
Bram Moolenaar9964e462007-05-05 17:54:07 +00002898 if exists("*NetReadFixup")
2899 " for the use of NetReadFixup (not otherwise used internally)
2900 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002901 endif
2902
Bram Moolenaar9964e462007-05-05 17:54:07 +00002903 if a:readcmd[0] == '%'
2904 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002905" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002906
2907 " rename the current buffer to the temp file (ie. tfile)
2908 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002909 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002910 else
2911 let tfile= a:tfile
2912 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002913 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002914
2915 " edit temporary file (ie. read the temporary file in)
2916 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002917" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002918 call zip#Browse(tfile)
2919 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002920" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002921 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002922 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002923" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002924 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002925 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002926" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002927 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002928 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002929" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002930 call tar#Browse(tfile)
2931 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002932" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002933 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002934 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002935" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002936 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002937 endif
2938
2939 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002940 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002941
Bram Moolenaar71badf92023-04-22 22:40:14 +01002942 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002943 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002944 " Note that isk must not include a "/" for scripts.vim
2945 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002946" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2947" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002948" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002949" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2950 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002951 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002952 filetype detect
2953" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002954 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002955" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002956 let line1 = 1
2957 let line2 = line("$")
2958
Bram Moolenaar8d043172014-01-23 14:24:41 +01002959 elseif !&ma
2960 " attempting to read a file after the current line in the file, but the buffer is not modifiable
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002961 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002962" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002963 return
2964
Bram Moolenaar9964e462007-05-05 17:54:07 +00002965 elseif s:FileReadable(a:tfile)
2966 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002967" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002968 let curline = line(".")
2969 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002970" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002971 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002972 let line1= curline + 1
2973 let line2= line("$") - lastline + 1
2974
2975 else
2976 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2978" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002979 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002980" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002981 return
2982 endif
2983
2984 " User-provided (ie. optional) fix-it-up command
2985 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002986" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002987 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002988" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002989" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002990 endif
2991
Bram Moolenaaradc21822011-04-01 18:03:16 +02002992 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002993 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002994 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002995 endif
2996
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002997" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002998
2999 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003000" redraw!
3001
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003002" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003003" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003004endfun
3005
Bram Moolenaar9964e462007-05-05 17:54:07 +00003006" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003007" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003008" Input:
3009" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3010" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003011" b:netrw_method= 1: rcp
3012" 2: ftp + <.netrc>
3013" 3: ftp + machine, id, password, and [path]filename
3014" 4: scp
3015" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003016" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003017" 7: rsync
3018" 8: fetch
3019" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003020" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003021" g:netrw_machine= hostname
3022" b:netrw_fname = filename
3023" g:netrw_port = optional port number (for ftp)
3024" g:netrw_choice = copy of input url (choice)
3025fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003026" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003027
Bram Moolenaar251e1912011-06-19 05:09:16 +02003028 " sanity check: choice should have at least three slashes in it
3029 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3030 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3031 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003032" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003033 return
3034 endif
3035
Bram Moolenaar5c736222010-01-06 20:54:52 +01003036 " record current g:netrw_machine, if any
3037 " curmachine used if protocol == ftp and no .netrc
3038 if exists("g:netrw_machine")
3039 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003040" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003041 else
3042 let curmachine= "N O T A HOST"
3043 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003044 if exists("g:netrw_port")
3045 let netrw_port= g:netrw_port
3046 endif
3047
3048 " insure that netrw_ftp_cmd starts off every method determination
3049 " with the current g:netrw_ftp_cmd
3050 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003051
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003052 " initialization
3053 let b:netrw_method = 0
3054 let g:netrw_machine = ""
3055 let b:netrw_fname = ""
3056 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003057 let g:netrw_choice = a:choice
3058
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003059 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003060 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003061 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3062 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003063 " rcpurm : rcp://[user@]host/filename Use rcp
3064 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003065 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003066 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003067 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003068 " rsyncurm : rsync://host[:port]/path Use rsync
3069 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3070 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003071 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003072 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3073 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003074 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3075 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003076 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003077 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003078 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003079 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003080 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003081 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003082 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003083 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003084
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003085" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003086 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003087 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003088 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003089" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003090 let b:netrw_method = 1
3091 let userid = substitute(a:choice,rcpurm,'\1',"")
3092 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3093 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003094 if userid != ""
3095 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003097
Bram Moolenaaradc21822011-04-01 18:03:16 +02003098 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003099 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003100" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003101 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003102 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3103 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3104 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003105
Bram Moolenaar15146672011-10-20 22:22:38 +02003106 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003107 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003108" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 let b:netrw_method = 5
3110 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3111 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003112 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003113
Bram Moolenaaradc21822011-04-01 18:03:16 +02003114 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003115 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003116" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003117 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003118 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003119 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3120 else
3121 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3122 endif
3123 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003124
Bram Moolenaaradc21822011-04-01 18:03:16 +02003125 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003127" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003128 let b:netrw_method = 7
3129 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3130 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003131
Bram Moolenaaradc21822011-04-01 18:03:16 +02003132 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003133 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003134" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003135 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003136 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3137 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3138 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003139" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003140 if userid != ""
3141 let g:netrw_uid= userid
3142 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003143
Bram Moolenaaradc21822011-04-01 18:03:16 +02003144 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003145 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003146 call NetUserPass("ftp:".g:netrw_machine)
3147 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003148 " if there's a change in hostname, require password re-entry
3149 unlet s:netrw_passwd
3150 endif
3151 if exists("netrw_port")
3152 unlet netrw_port
3153 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003154 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003155
Bram Moolenaar446cb832008-06-24 21:56:24 +00003156 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003157 let b:netrw_method = 3
3158 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003159 let host= substitute(g:netrw_machine,'\..*$','','')
3160 if exists("s:netrw_hup[host]")
3161 call NetUserPass("ftp:".host)
3162
Nir Lichtman1e34b952024-05-08 19:19:34 +02003163 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003164" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3165" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003166 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003167 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003168" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003169 endif
3170 let b:netrw_method= 2
3171 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003172" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003173 let b:netrw_method= 2
3174 else
3175 if !exists("g:netrw_uid") || g:netrw_uid == ""
3176 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003177 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003179 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003180 endif
3181 let b:netrw_method= 3
3182 endif
3183 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003184
Bram Moolenaaradc21822011-04-01 18:03:16 +02003185 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003186 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003187" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003188 let b:netrw_method = 8
3189 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3190 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3191 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3192 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003193
Bram Moolenaaradc21822011-04-01 18:03:16 +02003194 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003195 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003196" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003198 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3199 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003200 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003201 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003202 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003203
Bram Moolenaaradc21822011-04-01 18:03:16 +02003204 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003205 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003206" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003207 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003208 let b:netrw_method = 3
3209 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3210 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003211
Bram Moolenaar9964e462007-05-05 17:54:07 +00003212 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003213 let b:netrw_method = 2
3214 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3215 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3216 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003217
Bram Moolenaaradc21822011-04-01 18:03:16 +02003218 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003219 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003220" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003221 let b:netrw_method = 9
3222 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3223 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003224
Bram Moolenaaradc21822011-04-01 18:03:16 +02003225 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003226 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003227" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003228 let b:netrw_method = 1
3229 let userid = substitute(a:choice,rcphf,'\2',"")
3230 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3231 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003232" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3233" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3234" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3235" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003236 if userid != ""
3237 let g:netrw_uid= userid
3238 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003239
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003240 " Method#10: file://user@hostname/...path-to-file {{{3
3241 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003242" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003243 let b:netrw_method = 10
3244 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003245" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003246
Bram Moolenaaradc21822011-04-01 18:03:16 +02003247 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003248 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003249 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003250 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003251 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003252 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003254 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003255
Bram Moolenaar81695252004-12-29 20:58:21 +00003256 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003257 " remove any leading [:#] from port number
3258 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3259 elseif exists("netrw_port")
3260 " retain port number as implicit for subsequent ftp operations
3261 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003262 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003263
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003264" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3265" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3266" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3267" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003268" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003269" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003270" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003271" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003272" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003273" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003274" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003275" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277
Bram Moolenaar9964e462007-05-05 17:54:07 +00003278" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003279" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003280" Usage: :call NetUserPass() -- will prompt for userid and password
3281" :call NetUserPass("uid") -- will prompt for password
3282" :call NetUserPass("uid","password") -- sets global userid and password
3283" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3284" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285fun! NetUserPass(...)
3286
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003287" call Dfunc("NetUserPass() a:0=".a:0)
3288
3289 if !exists('s:netrw_hup')
3290 let s:netrw_hup= {}
3291 endif
3292
Bram Moolenaar071d4272004-06-13 20:20:40 +00003293 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003294 " case: no input arguments
3295
3296 " change host and username if not previously entered; get new password
3297 if !exists("g:netrw_machine")
3298 let g:netrw_machine= input('Enter hostname: ')
3299 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003301 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302 let g:netrw_uid= input('Enter username: ')
3303 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003304 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003305 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003306
3307 " set up hup database
3308 let host = substitute(g:netrw_machine,'\..*$','','')
3309 if !exists('s:netrw_hup[host]')
3310 let s:netrw_hup[host]= {}
3311 endif
3312 let s:netrw_hup[host].uid = g:netrw_uid
3313 let s:netrw_hup[host].passwd = s:netrw_passwd
3314
3315 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003316 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003317
3318 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003319 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003320 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003321" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003322 let host = substitute(a:1,'^ftp:','','')
3323 let host = substitute(host,'\..*','','')
3324 if exists("s:netrw_hup[host]")
3325 let g:netrw_uid = s:netrw_hup[host].uid
3326 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003327" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3328" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003329 else
3330 let g:netrw_uid = input("Enter UserId: ")
3331 let s:netrw_passwd = inputsecret("Enter Password: ")
3332 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003333
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003334 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003335 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003336" call Decho("case a:0=1: a:1<".a:1."> (get host from input argument, not an url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003337 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003338 if g:netrw_machine =~ '[0-9.]\+'
3339 let host= g:netrw_machine
3340 else
3341 let host= substitute(g:netrw_machine,'\..*$','','')
3342 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003343 else
3344 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003345 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003346 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003347" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003348 if exists("g:netrw_passwd")
3349 " ask for password if one not previously entered
3350 let s:netrw_passwd= g:netrw_passwd
3351 else
3352 let s:netrw_passwd = inputsecret("Enter Password: ")
3353 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003354 endif
3355
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003356" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003357 if exists("host")
3358 if !exists('s:netrw_hup[host]')
3359 let s:netrw_hup[host]= {}
3360 endif
3361 let s:netrw_hup[host].uid = g:netrw_uid
3362 let s:netrw_hup[host].passwd = s:netrw_passwd
3363 endif
3364
3365 elseif a:0 == 2
3366 let g:netrw_uid = a:1
3367 let s:netrw_passwd = a:2
3368
3369 elseif a:0 == 3
3370 " enter hostname, user-id, and password into the hup dictionary
3371 let host = substitute(a:1,'^\a\+:','','')
3372 let host = substitute(host,'\..*$','','')
3373 if !exists('s:netrw_hup[host]')
3374 let s:netrw_hup[host]= {}
3375 endif
3376 let s:netrw_hup[host].uid = a:2
3377 let s:netrw_hup[host].passwd = a:3
3378 let g:netrw_uid = s:netrw_hup[host].uid
3379 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003380" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3381" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003382 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003383
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003384" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003386
Bram Moolenaar85850f32019-07-19 22:05:51 +02003387" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003388" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003389" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003390
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003391" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003392" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3393fun! s:ExplorePatHls(pattern)
3394" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3395 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003396" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003397 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003398" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003399 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3400" call Dret("s:ExplorePatHls repat<".repat.">")
3401 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003402endfun
3403
3404" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003405" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003406" 0: (user: <mb>) bookmark current directory
3407" 1: (user: <gb>) change to the bookmarked directory
3408" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003409" 3: (browsing) records current directory history
3410" 4: (user: <u>) go up (previous) directory, using history
3411" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003412" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003413fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003414" call Dfunc("s:NetrwBookHistHandler(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." histcnt=".g:netrw_dirhistcnt." histmax=".g:netrw_dirhistmax)
Bram Moolenaarff034192013-04-24 18:51:19 +02003415 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3416" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3417 return
3418 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003419
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003420 let ykeep = @@
3421 let curbufnr = bufnr("%")
3422
Bram Moolenaar9964e462007-05-05 17:54:07 +00003423 if a:chg == 0
3424 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003425" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003426 if exists("s:netrwmarkfilelist_{curbufnr}")
3427 call s:NetrwBookmark(0)
3428 echo "bookmarked marked files"
3429 else
3430 call s:MakeBookmark(a:curdir)
3431 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003432 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003433
KSR-Yasudaf4498252023-10-06 03:34:17 +09003434 try
3435 call s:NetrwBookHistSave()
3436 catch
3437 endtry
3438
Bram Moolenaar9964e462007-05-05 17:54:07 +00003439 elseif a:chg == 1
3440 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003441" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003442 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003443" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003444 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003445 else
3446 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3447 endif
3448
3449 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003450" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003451 let didwork= 0
3452 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003453" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003454 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003455" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003456 let cnt= 1
3457 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003458" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003459 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003460 let didwork = 1
3461 let cnt = cnt + 1
3462 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003463 endif
3464
3465 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003466 " Note: history is saved only when PerformListing is done;
3467 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3468 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003469 let first = 1
3470 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003471 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003472 while ( first || cnt != g:netrw_dirhistcnt )
3473" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003474 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003475" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003476 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003477 let didwork= 1
3478 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003479 let histcnt = histcnt + 1
3480 let first = 0
3481 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003482 if cnt < 0
3483 let cnt= cnt + g:netrw_dirhistmax
3484 endif
3485 endwhile
3486 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003487 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003488 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003489 if didwork
3490 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3491 endif
3492
3493 elseif a:chg == 3
3494 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003495" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003496 if !exists("g:netrw_dirhistcnt") || !exists("g:netrw_dirhist_{g:netrw_dirhistcnt}") || g:netrw_dirhist_{g:netrw_dirhistcnt} != a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003497 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003498 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3499 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003500 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003501" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003502 endif
3503
3504 elseif a:chg == 4
3505 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003506" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003507 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003508 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3509 if g:netrw_dirhistcnt < 0
3510 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003511 endif
3512 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003513 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003514 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003515 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3516" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003517 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003518 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003519" call Decho("setl ma noro",'~'.expand("<slnum>"))
3520 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003521 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003522" call Decho("setl nomod",'~'.expand("<slnum>"))
3523" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003524 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003525" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3526 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003527 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003528 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003529 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003530 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003531 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003532 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003533 echo "Sorry, no predecessor directory exists yet"
3534 endif
3535
3536 elseif a:chg == 5
3537 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003538" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003539 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003540 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3541 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3542" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003543 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003544" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003545 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003546 sil! NetrwKeepj %d _
3547" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3548" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003549 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003550" call Decho("(set nomod) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003551 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003552" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3553 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003554 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003555 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3556 if g:netrw_dirhistcnt < 0
3557 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003558 endif
3559 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003560 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003561 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003562 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003563 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003564 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003565
3566 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003567" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003568 if exists("s:netrwmarkfilelist_{curbufnr}")
3569 call s:NetrwBookmark(1)
3570 echo "removed marked files from bookmarks"
3571 else
3572 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003573 let iremove = v:count
3574 let dremove = g:netrw_bookmarklist[iremove - 1]
3575" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003576 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003577" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3578 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3579 echo "removed ".dremove." from g:netrw_bookmarklist"
3580" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003581 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003582" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003583
3584 try
3585 call s:NetrwBookHistSave()
3586 catch
3587 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003588 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003589 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003590 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003591 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003592" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003593endfun
3594
3595" ---------------------------------------------------------------------
3596" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003597" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003598" Sister function: s:NetrwBookHistSave()
3599fun! s:NetrwBookHistRead()
3600" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003601 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003602" call Dret("s:NetrwBookHistRead - nothing read (suppressed due to dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a").")")
Bram Moolenaarff034192013-04-24 18:51:19 +02003603 return
3604 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003605 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003606
3607 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003608 if !exists("s:netrw_initbookhist")
3609 let home = s:NetrwHome()
3610 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003611 if filereadable(s:NetrwFile(savefile))
3612" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003613 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003614 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003615
3616 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003617 if g:netrw_dirhistmax > 0
3618 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003619 if filereadable(s:NetrwFile(savefile))
3620" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003621 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003622 endif
3623 let s:netrw_initbookhist= 1
3624 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003625 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003626 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003627
Bram Moolenaar97d62492012-11-15 21:28:22 +01003628 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003629" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3630" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003631" call Dret("s:NetrwBookHistRead")
3632endfun
3633
3634" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003635" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003636" Sister function: s:NetrwBookHistRead()
3637" I used to do this via viminfo but that appears to
3638" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003639" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3640" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003641" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003642fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003643" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003644 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003645" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003646 return
3647 endif
3648
Bram Moolenaar5c736222010-01-06 20:54:52 +01003649 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003650" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003651 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003652
3653 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003654 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003655" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003656 if g:netrw_use_noswf
3657 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3658 else
3659 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3660 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003661 setl nocin noai noci magic nospell nohid wig= noaw
3662 setl ma noro write
3663 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003664 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003665
Bram Moolenaar85850f32019-07-19 22:05:51 +02003666 " rename enew'd file: .netrwhist -- no attempt to merge
3667 " record dirhistmax and current dirhistcnt
3668 " save history
3669" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003670 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003671 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003672 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3673 if g:netrw_dirhistmax > 0
3674 let lastline = line("$")
3675 let cnt = g:netrw_dirhistcnt
3676 let first = 1
3677 while ( first || cnt != g:netrw_dirhistcnt )
3678 let lastline= lastline + 1
3679 if exists("g:netrw_dirhist_{cnt}")
3680 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3681" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3682 endif
3683 let first = 0
3684 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3685 if cnt < 0
3686 let cnt= cnt + g:netrw_dirhistmax
3687 endif
3688 endwhile
3689 exe "sil! w! ".savefile
3690" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3691 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003692
Bram Moolenaar85850f32019-07-19 22:05:51 +02003693 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003694 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003695 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003696" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003697 " merge and write .netrwbook
3698 let savefile= s:NetrwHome()."/.netrwbook"
3699
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003700 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003701 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003702 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003703 for bdm in booklist
3704 if index(g:netrw_bookmarklist,bdm) == -1
3705 call add(g:netrw_bookmarklist,bdm)
3706 endif
3707 endfor
3708 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003709 endif
3710
3711 " construct and save .netrwbook
3712 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003713 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003714" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003715 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003716
3717 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003718 let bgone= bufnr("%")
3719 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003720 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003721
3722" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003723endfun
3724
3725" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003726" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3727" list of the contents of a local or remote directory. It is assumed that the
3728" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3729" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003730" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003731fun! s:NetrwBrowse(islocal,dirname)
3732 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003733" call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
Bram Moolenaar85850f32019-07-19 22:05:51 +02003734" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3735" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3736" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003737
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003738 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3739 " This is useful when one edits a local file, then :e ., then :Rex
3740 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3741 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003742" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003743 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003744
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003745 " s:NetrwBrowse : initialize history {{{3
3746 if !exists("s:netrw_initbookhist")
3747 NetrwKeepj call s:NetrwBookHistRead()
3748 endif
3749
3750 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003751 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003752 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003753" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003754 else
3755 let dirname= a:dirname
3756 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003757
Bram Moolenaar85850f32019-07-19 22:05:51 +02003758 " repoint t:netrw_lexbufnr if appropriate
3759 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3760" call Decho("set repointlexbufnr to true!")
3761 let repointlexbufnr= 1
3762 endif
3763
3764 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003765 if exists("s:netrw_skipbrowse")
3766 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003767" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." filename<".expand("%")."> win#".winnr()." ft<".&ft.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01003768" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003769 return
3770 endif
3771 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003772 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003773" call Dret("s:NetrwBrowse : missing shellescape()")
3774 return
3775 endif
3776 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003777 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003778" call Dret("s:NetrwBrowse : missing fnameescape()")
3779 return
3780 endif
3781
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003782 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003783 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003784
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003785 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003786 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3787 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3788" call Decho("clearing marked files",'~'.expand("<slnum>"))
3789 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3790 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003791 endif
3792
3793 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003794 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003795" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3796" call Decho("NetrwKeepj lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003797 if s:NetrwLcd(dirname)
3798" call Dret("s:NetrwBrowse : lcd failure")
3799 return
3800 endif
3801 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003802" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003803
Bram Moolenaar5c736222010-01-06 20:54:52 +01003804 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003805 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003806" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003807 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003808" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003809 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003810 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003811 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003812" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003813
3814 " remove any filetype indicator from end of dirname, except for the
3815 " "this is a directory" indicator (/).
3816 " There shouldn't be one of those here, anyway.
3817 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003818" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003819 call s:RemotePathAnalysis(dirname)
3820
3821 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3822 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003823 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003824 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003825" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003826 let b:netrw_curdir = dirname
3827 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003828 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003829 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3830 sil call netrw#NetRead(2,url)
3831 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003832" call Decho("url<".url.">",'~'.expand("<slnum>"))
3833" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3834" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003835 if s:path =~ '.bz2'
3836 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3837 elseif s:path =~ '.gz'
3838 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3839 elseif s:path =~ '.gz'
3840 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3841 else
3842 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3843 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003844 endif
3845
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003846 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003847 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003848 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003849" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003850 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003851" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003852
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853" call Dret("s:NetrwBrowse : file<".s:fname.">")
3854 return
3855 endif
3856
Bram Moolenaaradc21822011-04-01 18:03:16 +02003857 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003858 call s:UseBufWinVars()
3859
3860 " set up some variables {{{3
3861 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003862 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003863 let s:last_sort_by = g:netrw_sort_by
3864
3865 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003866 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003867
Bram Moolenaar97d62492012-11-15 21:28:22 +01003868 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003869" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003870 let svpos = winsaveview()
3871" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003872 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003873
Bram Moolenaar446cb832008-06-24 21:56:24 +00003874 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003875 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3876 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3877" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3878" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3879 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3880 else
3881" " call Decho("2match none",'~'.expand("<slnum>"))
3882 2match none
3883 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003884 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003885 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003886 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003887" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003888 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003889" call Decho("(set noma nomod nowrap) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003890" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003891 return
3892 endif
3893
3894 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003895" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003896 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003897 if b:netrw_curdir =~ '[/\\]$'
3898 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3899 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003900 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003901 let b:netrw_curdir= b:netrw_curdir."/"
3902 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003903 if b:netrw_curdir == ''
3904 if has("amiga")
3905 " On the Amiga, the empty string connotes the current directory
3906 let b:netrw_curdir= getcwd()
3907 else
3908 " under unix, when the root directory is encountered, the result
3909 " from the preceding substitute is an empty string.
3910 let b:netrw_curdir= '/'
3911 endif
3912 endif
3913 if !a:islocal && b:netrw_curdir !~ '/$'
3914 let b:netrw_curdir= b:netrw_curdir.'/'
3915 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003916" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003917
3918 " ------------
3919 " (local only) {{{3
3920 " ------------
3921 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003922" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003923
3924 " Set up ShellCmdPost handling. Append current buffer to browselist
3925 call s:LocalFastBrowser()
3926
3927 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3928 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003929" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3930" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003931 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003932 if s:NetrwLcd(b:netrw_curdir)
3933" call Dret("s:NetrwBrowse : lcd failure")
3934 return
3935 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003936 endif
3937 endif
3938
3939 " --------------------------------
3940 " remote handling: {{{3
3941 " --------------------------------
3942 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003943" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003944
Bram Moolenaar97d62492012-11-15 21:28:22 +01003945 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003946" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003947 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003948 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003949" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003950 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3951 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3952 if dirname !~ '/$'
3953 let dirname= dirname.'/'
3954 endif
3955 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003956" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003957 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003958 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003959" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003960 endif
3961
3962 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3963 if dirname !~ dirpat
3964 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003965 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003966 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003967 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003968" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003969 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003970" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003971" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3972 return
3973 endif
3974 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003975" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003976 endif " (additional remote handling)
3977
Bram Moolenaar85850f32019-07-19 22:05:51 +02003978 " -------------------------------
3979 " Perform Directory Listing: {{{3
3980 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003981 NetrwKeepj call s:NetrwMaps(a:islocal)
3982 NetrwKeepj call s:NetrwCommands(a:islocal)
3983 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003984
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003985 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003986 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003987" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3988
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003989 " If there is a rexposn: restore position with rexposn
3990 " Otherwise : set rexposn
3991 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003992" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
3993 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3994 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3995 NetrwKeepj exe w:netrw_bannercnt
3996 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003997 else
3998 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3999 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004000 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004001 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004002" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004003 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004004 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004005
Bram Moolenaar85850f32019-07-19 22:05:51 +02004006 " repoint t:netrw_lexbufnr if appropriate
4007 if exists("repointlexbufnr")
4008 let t:netrw_lexbufnr= bufnr("%")
4009" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4010 endif
4011
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004012 " restore position
4013 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004014" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4015 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004016 endif
4017
Bram Moolenaara6878372014-03-22 21:02:50 +01004018 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004019 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4020 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004021" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4022" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004023" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004024 return
4025endfun
4026
4027" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004028" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4029" may not apply correctly; ie. netrw's idea of the current directory may
4030" differ from vim's. This function insures that netrw's idea of the current
4031" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004032" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004033fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004034" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4035" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4036" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4037" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4038" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004039
4040 " clean up any leading treedepthstring
4041 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4042 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004043" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004044 else
4045 let fname= a:fname
4046 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004047
4048 if g:netrw_keepdir
4049 " vim's idea of the current directory possibly may differ from netrw's
4050 if !exists("b:netrw_curdir")
4051 let b:netrw_curdir= getcwd()
4052 endif
4053
Nir Lichtman1e34b952024-05-08 19:19:34 +02004054 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004055 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004056 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004057 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004058" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004059 else
4060 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004061 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004062" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004063 endif
4064
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004065 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004066 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004067 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004068" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004069 else
4070 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004071 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004072" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004073 endif
4074 else
4075 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004076 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004077" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4078" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4079" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004080 endif
4081
Bram Moolenaar85850f32019-07-19 22:05:51 +02004082" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004083 return ret
4084endfun
4085
4086" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004087" s:NetrwFileInfo: supports qf (query for file information) {{{2
4088fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004089" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004090 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004091 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004092 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004093 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004094 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004095 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004096 let lsopt= "-lsadh --si"
4097 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004098" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004099 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004100
4101 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004102 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004103" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004104
Bram Moolenaara6878372014-03-22 21:02:50 +01004105 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004106 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004107" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004108
4109 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004110 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004111" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004112
Bram Moolenaar446cb832008-06-24 21:56:24 +00004113 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004115 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004116" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004117 endif
4118 else
4119 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004120" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4121 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004122 let fname= substitute(a:fname,".$","","")
4123 else
4124 let fname= a:fname
4125 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004126 let t = getftime(s:NetrwFile(fname))
4127 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004128 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004129 let sz= s:NetrwHumanReadable(sz)
4130 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004131 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4132" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004133 endif
4134 else
4135 echo "sorry, \"qf\" not supported yet for remote files"
4136 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004137 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004138" call Dret("s:NetrwFileInfo")
4139endfun
4140
4141" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004142" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4143fun! s:NetrwFullPath(filename)
4144" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4145 let filename= a:filename
4146 if filename !~ '^/'
4147 let filename= resolve(getcwd().'/'.filename)
4148 endif
4149 if filename != "/" && filename =~ '/$'
4150 let filename= substitute(filename,'/$','','')
4151 endif
4152" " call Dret("s:NetrwFullPath <".filename.">")
4153 return filename
4154endfun
4155
4156" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004157" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004158" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004159" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004160" Nov 09, 2020: tst952 shows that when user does :set hidden that NetrwGetBuffer will come up with a [No Name] buffer (hid fix)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004161fun! s:NetrwGetBuffer(islocal,dirname)
4162" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004163" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." hid=".&hid,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004164" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4165" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004166 let dirname= a:dirname
4167
4168 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004169" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004170 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004171" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004172 let s:netrwbuf= {}
4173 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004174" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4175" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4176
4177 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4178 let bufnum = -1
4179
4180 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4181 if has_key(s:netrwbuf,"NetrwTreeListing")
4182 let bufnum= s:netrwbuf["NetrwTreeListing"]
4183 else
4184 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4185 endif
4186" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4187 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004188 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004189 let bufnum= -1
4190 endif
4191 elseif bufnr("NetrwTreeListing") != -1
4192 let bufnum= bufnr("NetrwTreeListing")
4193" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4194 else
4195" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4196 let bufnum= -1
4197 endif
4198
4199 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004200 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004201" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004202 if !bufexists(bufnum)
4203 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4204 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004205 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004206
Bram Moolenaar446cb832008-06-24 21:56:24 +00004207 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004208" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004209 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004210 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004211" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4212
Bram Moolenaar71badf92023-04-22 22:40:14 +01004213 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004214 " IF the buffer already has the desired name
4215 " AND it is empty
4216 let curbuf = bufname("%")
4217 if curbuf == '.'
4218 let curbuf = getcwd()
4219 endif
4220" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004221" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004222" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4223" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4224" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4225" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4226 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004227" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4228 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004229 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004230" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004231 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004232 " Aug 14, 2021: was thinking about looking for a [No Name] buffer here and using it, but that might cause problems
Bram Moolenaar446cb832008-06-24 21:56:24 +00004233
4234 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004235 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004236" call Decho("--get enew buffer and name it (bufnum#".bufnum."<0 OR bufexists(".bufnum.")=".bufexists(bufnum)."==0)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004237 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004238" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004239 " name the buffer
4240 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4241 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004242" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004243 let w:netrw_treebufnr = bufnr("%")
4244 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004245 if g:netrw_use_noswf
4246 setl nobl bt=nofile noswf
4247 else
4248 setl nobl bt=nofile
4249 endif
4250 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4251 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4252 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4253 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004254" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004255 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004256 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004257 " enter the new buffer into the s:netrwbuf dictionary
4258 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4259" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4260" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004261 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004262" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004263
4264 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004265" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004266 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004267 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004268 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004269
4270 if &ft == "netrw"
4271" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4272 exe "sil! NetrwKeepj noswapfile b ".bufnum
4273" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004274 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004275" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4276 call s:NetrwEditBuf(bufnum)
4277" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004278 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004279" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004280 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004281 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004282 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004283
4284 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004285 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004286
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004287 if line("$") <= 1 && getline(1) == ""
4288 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004289 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004290" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4291" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004292" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4293 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004294
Bram Moolenaar97d62492012-11-15 21:28:22 +01004295 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004296" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004297 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004298 sil NetrwKeepj %d _
4299" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4300" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004301" call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but refreshing due to g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004302 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004303
Bram Moolenaar446cb832008-06-24 21:56:24 +00004304 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004305" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4306" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004307 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004308 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004309 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004310" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4311" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004312" call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004313 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004314
Bram Moolenaar446cb832008-06-24 21:56:24 +00004315 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004316" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4317" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4318" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004319 return 1
4320 endif
4321 endif
4322
4323 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4324 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4325 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4326 " med 1 D H
4327 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004328" call Decho("--do netrw settings: make this buffer#".bufnr("%")." not-a-file, modifiable, not line-numbered, etc--",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004329 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004330 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004331 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004332
4333 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004334" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4335" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4336 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004337
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004338" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4339" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4340" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004341 return 0
4342endfun
4343
4344" ---------------------------------------------------------------------
4345" s:NetrwGetcwd: get the current directory. {{{2
4346" Change backslashes to forward slashes, if any.
4347" If doesc is true, escape certain troublesome characters
4348fun! s:NetrwGetcwd(doesc)
4349" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4350 let curdir= substitute(getcwd(),'\\','/','ge')
4351 if curdir !~ '[\/]$'
4352 let curdir= curdir.'/'
4353 endif
4354 if a:doesc
4355 let curdir= fnameescape(curdir)
4356 endif
4357" call Dret("NetrwGetcwd <".curdir.">")
4358 return curdir
4359endfun
4360
4361" ---------------------------------------------------------------------
4362" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4363fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004364" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4365" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4366 let keepsol= &l:sol
4367 setl nosol
4368
Bram Moolenaar446cb832008-06-24 21:56:24 +00004369 call s:UseBufWinVars()
4370
4371 " insure that w:netrw_liststyle is set up
4372 if !exists("w:netrw_liststyle")
4373 if exists("g:netrw_liststyle")
4374 let w:netrw_liststyle= g:netrw_liststyle
4375 else
4376 let w:netrw_liststyle= s:THINLIST
4377 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004378" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004379 endif
4380
4381 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4382 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004383" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004384 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004385 let dirname= "./"
4386 let curline= getline('.')
4387
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004388 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004389 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004390 let s:netrw_skipbrowse= 1
4391 echo 'Pressing "s" also works'
4392
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004393 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004394 let s:netrw_skipbrowse= 1
4395 echo 'Press "S" to edit sorting sequence'
4396
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004397 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004398 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004399 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004400
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004401 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004402 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004403 let s:netrw_skipbrowse= 1
4404 echo 'Pressing "a" also works'
4405
4406 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004407 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004408 endif
4409
4410 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004411" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004412 NetrwKeepj norm! 0
4413 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004414
4415 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004416" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004417 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004418 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4419
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004420 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004421" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004422 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004423 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004424
4425 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004426" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004427 let dirname= getline('.')
4428
4429 if !exists("b:netrw_cpf")
4430 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004431 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004432 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004433" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004434 endif
4435
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004436" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004437 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004438" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4439" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004441 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004442 else
4443 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004444 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004445 endif
Enno3146d632024-07-04 19:44:42 +02004446
4447 let dict={}
4448 " save the unnamed register and register 0-9 and a
4449 let dict.a=[getreg('a'), getregtype('a')]
4450 for i in range(0, 9)
4451 let dict[i] = [getreg(i), getregtype(i)]
4452 endfor
4453 let dict.unnamed = [getreg(''), getregtype('')]
4454
Bram Moolenaarc236c162008-07-13 17:41:49 +00004455 let eofname= filestart + b:netrw_cpf + 1
4456 if eofname <= col("$")
4457 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004458 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004459 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004460 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004461 endif
Enno3146d632024-07-04 19:44:42 +02004462
Bram Moolenaar446cb832008-06-24 21:56:24 +00004463 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004464 call s:RestoreRegister(dict)
4465
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004466" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004467 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004468" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004469 endif
4470
4471 " symlinks are indicated by a trailing "@". Remove it before further processing.
4472 let dirname= substitute(dirname,"@$","","")
4473
4474 " executables are indicated by a trailing "*". Remove it before further processing.
4475 let dirname= substitute(dirname,"\*$","","")
4476
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004477 let &l:sol= keepsol
4478
Bram Moolenaar446cb832008-06-24 21:56:24 +00004479" call Dret("s:NetrwGetWord <".dirname.">")
4480 return dirname
4481endfun
4482
4483" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004484" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4485" g:netrw_bufsettings will be used after the listing is produced.
4486" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004487fun! s:NetrwListSettings(islocal)
4488" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004489" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004491" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4492 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4493 setl bt=nofile nobl ma nonu nowrap noro nornu
4494 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004495 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004496 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004497 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004498" call Dredir("ls!","s:NetrwListSettings")
4499" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004500 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004501 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004502 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004503 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004504 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004505 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004506 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004507" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508" call Dret("s:NetrwListSettings")
4509endfun
4510
4511" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004512" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004513" islocal=0: remote browsing
4514" =1: local browsing
4515fun! s:NetrwListStyle(islocal)
4516" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004517
Bram Moolenaar97d62492012-11-15 21:28:22 +01004518 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004519 let fname = s:NetrwGetWord()
4520 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004521 let svpos = winsaveview()
4522" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004523 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004524" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4525" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4526" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004527
Bram Moolenaar85850f32019-07-19 22:05:51 +02004528 " repoint t:netrw_lexbufnr if appropriate
4529 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4530" call Decho("set repointlexbufnr to true!")
4531 let repointlexbufnr= 1
4532 endif
4533
Bram Moolenaar446cb832008-06-24 21:56:24 +00004534 if w:netrw_liststyle == s:THINLIST
4535 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004536" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004537 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4538
4539 elseif w:netrw_liststyle == s:LONGLIST
4540 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004541" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004542 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4543
4544 elseif w:netrw_liststyle == s:WIDELIST
4545 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004546" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004547 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4548
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004549 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004550" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004551 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4552
4553 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004554 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004555 let g:netrw_liststyle = s:THINLIST
4556 let w:netrw_liststyle = g:netrw_liststyle
4557 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4558 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004559 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004560" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004561
4562 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004563" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4564 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004565 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004566" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004567 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004568" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004569
4570 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004571" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004572 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004573 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004574
Bram Moolenaar85850f32019-07-19 22:05:51 +02004575 " repoint t:netrw_lexbufnr if appropriate
4576 if exists("repointlexbufnr")
4577 let t:netrw_lexbufnr= bufnr("%")
4578" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4579 endif
4580
Bram Moolenaar13600302014-05-22 18:26:40 +02004581 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004582" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4583 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004584 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004585
4586" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4587endfun
4588
4589" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004590" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4591fun! s:NetrwBannerCtrl(islocal)
4592" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4593
Bram Moolenaar97d62492012-11-15 21:28:22 +01004594 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004595 " toggle the banner (enable/suppress)
4596 let g:netrw_banner= !g:netrw_banner
4597
4598 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004599 let svpos= winsaveview()
4600" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004601 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4602
4603 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004604 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4605 let fname= s:NetrwGetWord()
4606 sil NetrwKeepj $
4607 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4608" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4609 if result <= 0 && exists("w:netrw_bannercnt")
4610 exe "NetrwKeepj ".w:netrw_bannercnt
4611 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004612 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004613 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004614" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4615endfun
4616
4617" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004618" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4619"
4620" No bang: enters files/directories into Netrw's bookmark system
4621" No argument and in netrw buffer:
4622" if there are marked files: bookmark marked files
4623" otherwise : bookmark file/directory under cursor
4624" No argument and not in netrw buffer: bookmarks current open file
4625" Has arguments: globs them individually and bookmarks them
4626"
4627" With bang: deletes files/directories from Netrw's bookmark system
4628fun! s:NetrwBookmark(del,...)
4629" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4630 if a:0 == 0
4631 if &ft == "netrw"
4632 let curbufnr = bufnr("%")
4633
4634 if exists("s:netrwmarkfilelist_{curbufnr}")
4635 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004636" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004637 let svpos = winsaveview()
4638" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004639 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004640 for fname in s:netrwmarkfilelist_{curbufnr}
4641 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4642 endfor
4643 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4644 call s:NetrwUnmarkList(curbufnr,curdir)
4645 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004646" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4647 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004648 else
4649 let fname= s:NetrwGetWord()
4650 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4651 endif
4652
4653 else
4654 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004655" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004656 let fname= expand("%")
4657 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4658 endif
4659
4660 else
4661 " bookmark specified files
4662 " attempts to infer if working remote or local
4663 " by deciding if the current file begins with an url
4664 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004665 let islocal= expand("%") !~ '^\a\{3,}://'
4666" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004667 let i = 1
4668 while i <= a:0
4669 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004670 if v:version > 704 || (v:version == 704 && has("patch656"))
4671 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004672 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004673 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004674 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004675 else
4676 let mbfiles= [a:{i}]
4677 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004678" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004679 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004680" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004681 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4682 endfor
4683 let i= i + 1
4684 endwhile
4685 endif
4686
4687 " update the menu
4688 call s:NetrwBookmarkMenu()
4689
4690" call Dret("s:NetrwBookmark")
4691endfun
4692
4693" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004694" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4695" .2.[cnt] for bookmarks, and
4696" .3.[cnt] for history
4697" (see s:NetrwMenu())
4698fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004699 if !exists("s:netrw_menucnt")
4700 return
4701 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004702" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004703
4704 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004705 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004706 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004707" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004708 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4709 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004710 endif
4711 if !exists("s:netrw_initbookhist")
4712 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004713 endif
4714
4715 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004716 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004717 let cnt= 1
4718 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004719" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004720 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004721
4722 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004723 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004724
4725 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004726 exe 'sil! menu '.g:NetrwMenuPriority.".8.2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete.'.bmd.' '.cnt."mB"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004727 let cnt= cnt + 1
4728 endfor
4729
4730 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004731
4732 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004733 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004734 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004735 let first = 1
4736 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004737 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004738 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004739 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004740 if exists("g:netrw_dirhist_{cnt}")
4741 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004742" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004743 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4744 endif
4745 let first = 0
4746 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4747 if cnt < 0
4748 let cnt= cnt + g:netrw_dirhistmax
4749 endif
4750 endwhile
4751 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004752
Bram Moolenaar9964e462007-05-05 17:54:07 +00004753 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004754" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004755endfun
4756
4757" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004758" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4759" directory and a new directory name. Also, if the
4760" "new directory name" is actually a file,
4761" NetrwBrowseChgDir() edits the file.
4762fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004763" call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." win#".winnr()." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004764" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004765
Bram Moolenaar97d62492012-11-15 21:28:22 +01004766 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004767 if !exists("b:netrw_curdir")
4768 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4769 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004770 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004771" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4772" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004773" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004774" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004775 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004776 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004777" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004778
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004779 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004780" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004781 call s:SavePosn(s:netrw_posn)
4782 NetrwKeepj call s:NetrwOptionsSave("s:")
4783 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004784 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004785 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004786 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004787 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004788 endif
4789 let newdir = a:newdir
4790 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004791 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004792" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004793" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004794" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004795
4796 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004797" call Decho('(s:NetrwBrowseChgDir) ignore [return]s when done in banner (g:netrw_banner='.g:netrw_banner.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004798 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004799" call Decho("win#".winnr()." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." line(.)#".line('.')." line($)#".line("#"),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004800 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004801 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004802" call Decho("#1: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004803 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004804" call Decho("#2: quickhelp=".g:netrw_quickhelp." ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004805 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004806 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004807 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004808 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004809" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004810 endif
4811 endif
4812" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004813" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004814 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004815
Bram Moolenaar446cb832008-06-24 21:56:24 +00004816 " set up o/s-dependent directory recognition pattern
4817 if has("amiga")
4818 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004819 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004820 let dirpat= '[\/]$'
4821 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004822" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004823
4824 if dirname !~ dirpat
4825 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004826 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004827 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004828" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004829 endif
4830
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004831" call Decho("[newdir<".newdir."> ".((newdir =~ dirpat)? "=~" : "!~")." dirpat<".dirpat.">] && [islocal=".a:islocal."] && [newdir is ".(isdirectory(s:NetrwFile(newdir))? "" : "not ")."a directory]",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004832 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004833 " ------------------------------
4834 " NetrwBrowseChgDir: edit a file {{{3
4835 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004836" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004837
Bram Moolenaar97d62492012-11-15 21:28:22 +01004838 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004839 let s:rexposn_{bufnr("%")}= winsaveview()
4840" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004841" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4842" call Decho("edit-a-file: w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a')." w:netrw_treedict:".(exists("w:netrw_treedict")? "exists" : 'n/a')." newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004843
Bram Moolenaar446cb832008-06-24 21:56:24 +00004844 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004845" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4846" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004847" let newdir = s:NetrwTreePath(s:netrw_treetop)
4848" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004849 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004850 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4851" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4852 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004853 if dirname =~ '/$'
4854 let dirname= dirname.newdir
4855 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004856 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004857 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004858" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4859" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004860 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004861" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004862 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004863 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004864 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004865 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004866" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004867 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004868 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004869" call Decho("edit-a-file: (a:0=".a:0."<1) set up windows for editing<".fnameescape(dirname)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004870 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004871 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004872 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004873" " call Decho("edit-a-file: s:didsplit does not exist; g:netrw_browse_split=".string(g:netrw_browse_split)." win#".winnr()." g:netrw_chgwin=".g:netrw_chgwin",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004874 if type(g:netrw_browse_split) == 3
4875 " open file in server
4876 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004877" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004878 call s:NetrwServerEdit(a:islocal,dirname)
4879" call Dret("s:NetrwBrowseChgDir")
4880 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004881
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004882 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004883 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004884" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004885 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4886 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004887 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004888 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004889 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004890 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004891
Bram Moolenaar446cb832008-06-24 21:56:24 +00004892 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004893 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004894" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004895 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4896 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004897 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004898 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004899 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004900 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004901
Bram Moolenaar446cb832008-06-24 21:56:24 +00004902 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004903 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004904" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004905 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004906 if !exists("b:netrw_curdir")
4907 let b:netrw_curdir= getcwd()
4908 endif
4909 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004910
Bram Moolenaar446cb832008-06-24 21:56:24 +00004911 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004912 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004913" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004914 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004915 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004916" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004917 return
4918 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004919 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004920
Bram Moolenaar9964e462007-05-05 17:54:07 +00004921 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004922 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004923" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004924 call s:NetrwMenu(0)
4925 " optional change to window
4926 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004927" call Decho("edit-a-file: changing window to #".g:netrw_chgwin.": (due to g:netrw_chgwin)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004928 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004929 " if g:netrw_chgwin is set to one more than the last window, then
4930 " vertically split the last window to make that window available.
4931 let curwin= winnr()
4932 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4933 vs
4934 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004935 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004936 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004937 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004938 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004939 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004940
Bram Moolenaar9964e462007-05-05 17:54:07 +00004941 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004942
Bram Moolenaar446cb832008-06-24 21:56:24 +00004943 " the point where netrw actually edits the (local) file
4944 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004945 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004946 if !&mod
4947 " if e the new file would fail due to &mod, then don't change any of the flags
4948 let dolockout= 1
4949 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004950 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004951" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004952 " some like c-^ to return to the last edited file
4953 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004954 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4955 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004956 call s:NetrwEditFile("e","",dirname)
4957" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004958 " COMBAK -- cuc cul related
4959 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004960 if &hidden || &bufhidden == "hide"
4961 " file came from vim's hidden storage. Don't "restore" options with it.
4962 let dorestore= 0
4963 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004964 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004965" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004966 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004967
4968 " handle g:Netrw_funcref -- call external-to-netrw functions
4969 " This code will handle g:Netrw_funcref as an individual function reference
4970 " or as a list of function references. It will ignore anything that's not
4971 " a function reference. See :help Funcref for information about function references.
4972 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004973" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004974 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004975" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004976 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004977 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004978" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004979 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004980 if type(Fncref) == 2
4981 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004982 endif
4983 endfor
4984 endif
4985 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004986 endif
4987
4988 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004989 " ----------------------------------------------------
4990 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4991 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004992" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004993 let dirname = newdir
4994 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004995 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004996 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004997
4998 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004999 " ---------------------------------------------
5000 " NetrwBrowseChgDir: refresh the directory list {{{3
5001 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005002" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005003 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005004 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005005
5006 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005007 " --------------------------------------
5008 " NetrwBrowseChgDir: go up one directory {{{3
5009 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005010" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005011
5012 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5013 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005014" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5015" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005016 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005017 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005018 endif
5019
5020 if has("amiga")
5021 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005022" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005023 if a:islocal
5024 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5025 let dirname= substitute(dirname,'/$','','')
5026 else
5027 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5028 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005029" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005030
Nir Lichtman1e34b952024-05-08 19:19:34 +02005031 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005032 " windows
5033 if a:islocal
5034 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5035 if dirname == ""
5036 let dirname= '/'
5037 endif
5038 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005039 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005040 endif
5041 if dirname =~ '^\a:$'
5042 let dirname= dirname.'/'
5043 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005044" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005045
Bram Moolenaar446cb832008-06-24 21:56:24 +00005046 else
5047 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005048" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../" and unix or cygwin','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005049 if a:islocal
5050 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5051 if dirname == ""
5052 let dirname= '/'
5053 endif
5054 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005055 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005056 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005057" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005058 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005059 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005060 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005061
5062 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005063 " --------------------------------------
5064 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5065 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005066" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005067 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5068" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005069 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005070 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005071" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5072 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005073 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005074 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005075" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005076 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005077 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005078" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005079
5080 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005081" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005082 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005083" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005084 let haskey= 1
5085 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005086" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005087 endif
5088
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005089 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005090" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005091 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005092 if has_key(w:netrw_treedict,treedir."/")
5093 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005094" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005095 let haskey = 1
5096 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005097" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005098 endif
5099 endif
5100
5101 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005102" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005103 if !haskey && treedir =~ '/$'
5104 let treedir= substitute(treedir,'/$','','')
5105 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005106" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005107 let haskey = 1
5108 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005109" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005110 endif
5111 endif
5112
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005113" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005114 if haskey
5115 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005116" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005117 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005118" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5119" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005120 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005121 else
5122 " go down one directory
5123 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005124" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5125" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005126 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005127 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005128" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005129 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005130
5131 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005132 " ----------------------------------------
5133 " NetrwBrowseChgDir: Go down one directory {{{3
5134 " ----------------------------------------
5135 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005136" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005137 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005138 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005139 endif
5140
Bram Moolenaar97d62492012-11-15 21:28:22 +01005141 " --------------------------------------
5142 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5143 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005144 if dorestore
5145 " dorestore is zero'd when a local file was hidden or bufhidden;
5146 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005147" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005148 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005149" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005150" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005151 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005152 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005153" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005154 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005155" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5156" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005157 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005158" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005159 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005160" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5161" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005162 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005163" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005164 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005165 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005166 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005167 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005168
Bram Moolenaar446cb832008-06-24 21:56:24 +00005169" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5170 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005171endfun
5172
5173" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005174" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5175" for thin, long, and wide: cursor placed just after banner
5176" for tree, keeps cursor on current filename
5177fun! s:NetrwBrowseUpDir(islocal)
5178" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005179 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5180 " this test needed because occasionally this function seems to be incorrectly called
5181 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005182 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005183 " directories.
5184" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5185 return
5186 endif
5187
Bram Moolenaara6878372014-03-22 21:02:50 +01005188 norm! 0
5189 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005190" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005191 let curline= getline(".")
5192 let swwline= winline() - 1
5193 if exists("w:netrw_treetop")
5194 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005195 elseif exists("b:netrw_curdir")
5196 let w:netrw_treetop= b:netrw_curdir
5197 else
5198 let w:netrw_treetop= getcwd()
5199 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005200 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005201 let curfile = getline(".")
5202 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005203 if a:islocal
5204 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5205 else
5206 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5207 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005208" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5209" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5210 if w:netrw_treetop == '/'
5211 keepj call search('^\M'.curfile,"w")
5212 elseif curfile == '../'
5213 keepj call search('^\M'.curfile,"wb")
5214 else
5215" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5216 while 1
5217 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5218 let treepath= s:NetrwTreePath(w:netrw_treetop)
5219" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5220 if treepath == curpath
5221 break
5222 endif
5223 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005224 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005225
Bram Moolenaara6878372014-03-22 21:02:50 +01005226 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005227" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005228 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005229 if exists("b:netrw_curdir")
5230 let curdir= b:netrw_curdir
5231 else
5232 let curdir= expand(getcwd())
5233 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005234 if a:islocal
5235 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5236 else
5237 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5238 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005239 call s:RestorePosn(s:netrw_posn)
5240 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005241 let curdir= '\<'. escape(curdir, '~'). '/'
5242 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005243 endif
5244" call Dret("s:NetrwBrowseUpDir")
5245endfun
5246
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005247func s:redir()
5248 " set up redirection (avoids browser messages)
5249 " by default if not set, g:netrw_suppress_gx_mesg is true
5250 if get(g:, 'netrw_suppress_gx_mesg', 1)
5251 if &srr =~# "%s"
5252 return printf(&srr, has("win32") ? "nul" : "/dev/null")
5253 else
5254 return &srr .. (has("win32") ? "nul" : "/dev/null")
5255 endif
5256 endif
5257 return ''
5258endfunc
5259
5260if has('unix')
5261 if has('win32unix')
5262 " Cygwin provides cygstart
5263 if executable('cygstart')
5264 fun! netrw#Launch(args)
5265 exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
5266 endfun
5267 elseif !empty($MSYSTEM) && executable('start')
5268 " MSYS2/Git Bash comes by default without cygstart; see
5269 " https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
5270 " Instead it provides /usr/bin/start script running `cmd.exe //c start`
5271 " Adding "" //b` sets void title, hides cmd window and blocks path conversion
5272 " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
5273 fun! netrw#Launch(args)
5274 exe 'silent !start "" //b' a:args s:redir() | redraw!
5275 endfun
5276 else
5277 " imitate /usr/bin/start script for other environments and hope for the best
5278 fun! netrw#Launch(args)
5279 exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
5280 endfun
5281 endif
5282 elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
5283 fun! netrw#Launch(args)
5284 let args = a:args
5285 exe 'silent !' ..
5286 \ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
5287 \ 'cmd.exe /c start "" /b ' .. args :
5288 \ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
5289 \ | redraw!
5290 endfun
5291 else
5292 fun! netrw#Launch(args)
5293 exe ':silent ! nohup' a:args s:redir() '&' | redraw!
5294 endfun
5295 endif
5296elseif has('win32')
5297 fun! netrw#Launch(args)
5298 exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
5299 \ 'start "" /b' a:args s:redir() | redraw!
5300 endfun
5301else
5302 fun! netrw#Launch(dummy)
5303 echom 'No common launcher found'
5304 endfun
5305endif
5306
5307" Git Bash
5308if has('win32unix')
5309 " (cyg)start suffices
5310 let s:os_viewer = ''
5311" Windows / WSL
5312elseif executable('explorer.exe')
5313 let s:os_viewer = 'explorer.exe'
5314" Linux / BSD
5315elseif executable('xdg-open')
5316 let s:os_viewer = 'xdg-open'
5317" MacOS
5318elseif executable('open')
5319 let s:os_viewer = 'open'
5320endif
5321
5322fun! s:viewer()
5323 if exists('g:netrw_browsex_viewer') && executable(g:netrw_browsex_viewer)
5324 " extract any viewing options. Assumes that they're set apart by spaces.
5325 " call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
5326 if g:netrw_browsex_viewer =~ '\s'
5327 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5328 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5329 let oviewer = ''
5330 let cnt = 1
5331 while !executable(viewer) && viewer != oviewer
5332 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5333 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5334 let cnt = cnt + 1
5335 let oviewer = viewer
5336 " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5337 endwhile
5338 else
5339 let viewer = g:netrw_browsex_viewer
5340 let viewopt = ""
5341 endif
5342 " call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5343 return viewer .. ' ' .. viewopt
5344 else
5345 if !exists('s:os_viewer')
5346 call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
5347 else
5348 return s:os_viewer
5349 endif
5350 endif
5351endfun
5352
5353fun! netrw#Open(file) abort
5354 call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
5355endf
5356
5357if !exists('g:netrw_regex_url')
5358 let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
5359endif
5360
Bram Moolenaara6878372014-03-22 21:02:50 +01005361" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005362" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005363" given filename; typically this means given their extension.
5364" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005365fun! netrw#BrowseX(fname,remote)
Bram Moolenaar91359012019-11-30 17:57:03 +01005366 if a:remote == 0 && isdirectory(a:fname)
5367 " if its really just a local directory, then do a "gf" instead
Bram Moolenaar29634562020-01-09 21:46:04 +01005368 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005369 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5370 " remote directory, not a webpage access, looks like an attempt to do a directory listing
Bram Moolenaar91359012019-11-30 17:57:03 +01005371 norm! gf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005372 endif
5373
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005374 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5375 let remote = a:remote
5376 else
5377 let remote = 0
5378 endif
5379
Bram Moolenaar97d62492012-11-15 21:28:22 +01005380 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005381 let screenposn = winsaveview()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005382
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005383 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5384 let awkeep = &aw
5385 set noaw
5386
Bram Moolenaar5c736222010-01-06 20:54:52 +01005387 " special core dump handler
5388 if a:fname =~ '/core\(\.\d\+\)\=$'
5389 if exists("g:Netrw_corehandler")
5390 if type(g:Netrw_corehandler) == 2
5391 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005392 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005393 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005394 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005395 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005396 if type(Fncref) == 2
5397 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005398 endif
5399 endfor
5400 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005401 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005402 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005403 let &aw= awkeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005404 return
5405 endif
5406 endif
5407
Bram Moolenaar446cb832008-06-24 21:56:24 +00005408 " set up the filename
5409 " (lower case the extension, make a local copy of a remote file)
5410 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005411 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005412 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005413 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005414 if exten =~ "[\\/]"
5415 let exten= ""
5416 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005417
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005418 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005419 " create a local copy
Bram Moolenaarff034192013-04-24 18:51:19 +02005420 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005421 call netrw#NetRead(3,a:fname)
5422 " attempt to rename tempfile
5423 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005424 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02005425 if s:netrw_tmpfile != newname && newname != ""
5426 if rename(s:netrw_tmpfile,newname) == 0
5427 " renaming succeeded
Bram Moolenaar85850f32019-07-19 22:05:51 +02005428 let fname= newname
5429 else
5430 " renaming failed
Bram Moolenaar85850f32019-07-19 22:05:51 +02005431 let fname= s:netrw_tmpfile
5432 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005433 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005434 let fname= s:netrw_tmpfile
5435 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005436 else
5437 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005438 " special ~ handler for local
5439 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005440 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005441 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005442 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005443
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005444 " although shellescape(..., 1) is used in netrw#Open(), it's insufficient
5445 call netrw#Open(escape(fname, '#%'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005446
Bram Moolenaar446cb832008-06-24 21:56:24 +00005447 " cleanup: remove temporary file,
5448 " delete current buffer if success with handler,
5449 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005450 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005451 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005452" if remote == 1 && fname != a:fname
Bram Moolenaarc236c162008-07-13 17:41:49 +00005453" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005454" endif
5455
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005456 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005457 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005458 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005459 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005460 endif
Christian Brabandt9f320692024-10-30 18:36:20 +01005461 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005462 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005463 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005464 let @@ = ykeep
5465 let &aw= awkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005466endfun
5467
5468" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005469" netrw#GX: gets word under cursor for gx support {{{2
5470" See also: netrw#BrowseXVis
5471" netrw#BrowseX
5472fun! netrw#GX()
5473" call Dfunc("netrw#GX()")
5474 if &ft == "netrw"
5475 let fname= s:NetrwGetWord()
5476 else
Konfekt3d7e5672024-10-27 22:16:49 +01005477 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005478 endif
5479" call Dret("netrw#GX <".fname.">")
5480 return fname
5481endfun
5482
Konfekt3d7e5672024-10-27 22:16:49 +01005483fun! s:GetURL() abort
5484 let URL = ''
5485 if exists('*Netrw_get_URL_' .. &filetype)
5486 let URL = call('Netrw_get_URL_' .. &filetype, [])
5487 endif
5488 if !empty(URL) | return URL | endif
5489 " URLs end in letter, digit or forward slash
5490 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5491 if !empty(URL) | return URL | endif
5492
5493 " Is it a file in the current work dir ...
5494 let file = expand("<cfile>")
5495 if filereadable(file) | return file | endif
5496 " ... or in that of the current buffer?
5497 let path = fnamemodify(expand('%'), ':p')
5498 if isdirectory(path)
5499 let dir = path
5500 elseif filereadable(path)
5501 let dir = fnamemodify(path, ':h')
5502 endif
5503 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5504
5505 return ''
5506endf
5507
Bram Moolenaar85850f32019-07-19 22:05:51 +02005508" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005509" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5510fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005511 let dict={}
5512 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005513 norm! gv"ay
5514 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005515 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005516 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005517endfun
5518
5519" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005520" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5521" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5522" to become an unlisted buffer, so in that case don't bwipe it.
5523fun! s:NetrwBufRename(newname)
5524" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5525" call Dredir("ls!","s:NetrwBufRename (before rename)")
5526 let oldbufname= bufname(bufnr("%"))
5527" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5528
5529 if oldbufname != a:newname
5530" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5531 let b:junk= 1
5532" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5533 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005534" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005535 let oldbufnr= bufnr(oldbufname)
5536" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5537" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5538 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5539" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5540 exe "bwipe! ".oldbufnr
5541" else " Decho
5542" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005543" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5544" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5545" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005546 endif
5547" call Dredir("ls!","s:NetrwBufRename (after rename)")
5548" else " Decho
5549" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5550 endif
5551
5552" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5553endfun
5554
5555" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005556" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005557fun! netrw#CheckIfRemote(...)
5558" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5559 if a:0 > 0
5560 let curfile= a:1
5561 else
5562 let curfile= expand("%")
5563 endif
5564" call Decho("curfile<".curfile.">")
5565 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005566" call Dret("netrw#CheckIfRemote 1")
5567 return 1
5568 else
5569" call Dret("netrw#CheckIfRemote 0")
5570 return 0
5571 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005572endfun
5573
5574" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005575" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5576fun! s:NetrwChgPerm(islocal,curdir)
5577" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005578 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005579 call inputsave()
5580 let newperm= input("Enter new permission: ")
5581 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005582 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5583 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5584" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005585 call system(chgperm)
5586 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005587 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005588 endif
5589 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005590 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005591 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005592 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005593" call Dret("s:NetrwChgPerm")
5594endfun
5595
5596" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005597" s:CheckIfKde: checks if kdeinit is running {{{2
5598" Returns 0: kdeinit not running
5599" 1: kdeinit is running
5600fun! s:CheckIfKde()
5601" call Dfunc("s:CheckIfKde()")
5602 " seems kde systems often have gnome-open due to dependencies, even though
5603 " gnome-open's subsidiary display tools are largely absent. Kde systems
5604 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5605 if !exists("s:haskdeinit")
5606 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005607 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005608 if v:shell_error
5609 let s:haskdeinit = 0
5610 endif
5611 else
5612 let s:haskdeinit= 0
5613 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005614" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005615 endif
5616
5617" call Dret("s:CheckIfKde ".s:haskdeinit)
5618 return s:haskdeinit
5619endfun
5620
5621" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005622" s:NetrwClearExplore: clear explore variables (if any) {{{2
5623fun! s:NetrwClearExplore()
5624" call Dfunc("s:NetrwClearExplore()")
5625 2match none
5626 if exists("s:explore_match") |unlet s:explore_match |endif
5627 if exists("s:explore_indx") |unlet s:explore_indx |endif
5628 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5629 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5630 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5631 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5632 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5633 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5634 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5635" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005636" call Dret("s:NetrwClearExplore")
5637endfun
5638
5639" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005640" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5641fun! s:NetrwEditBuf(bufnum)
5642" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5643 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5644" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5645 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5646 else
5647" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005648 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005649 endif
5650" call Dret("s:NetrwEditBuf")
5651endfun
5652
5653" ---------------------------------------------------------------------
5654" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5655" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5656fun! s:NetrwEditFile(cmd,opt,fname)
5657" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5658 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5659" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5660 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5661 else
5662" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005663 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5664 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5665 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005666 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5667 endif
5668" call Dret("s:NetrwEditFile")
5669endfun
5670
5671" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005672" s:NetrwExploreListUniq: {{{2
5673fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005674" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005675
5676 " this assumes that the list is already sorted
5677 let newexplist= []
5678 for member in a:explist
5679 if !exists("uniqmember") || member != uniqmember
5680 let uniqmember = member
5681 let newexplist = newexplist + [ member ]
5682 endif
5683 endfor
5684
Bram Moolenaar15146672011-10-20 22:22:38 +02005685" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005686 return newexplist
5687endfun
5688
5689" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005690" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5691fun! s:NetrwForceChgDir(islocal,newdir)
5692" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005693 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005694 if a:newdir !~ '/$'
5695 " ok, looks like force is needed to get directory-style treatment
5696 if a:newdir =~ '@$'
5697 let newdir= substitute(a:newdir,'@$','/','')
5698 elseif a:newdir =~ '[*=|\\]$'
5699 let newdir= substitute(a:newdir,'.$','/','')
5700 else
5701 let newdir= a:newdir.'/'
5702 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005703" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005704 else
5705 " should already be getting treatment as a directory
5706 let newdir= a:newdir
5707 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005708 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005709 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005710 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005711" call Dret("s:NetrwForceChgDir")
5712endfun
5713
5714" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005715" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005716" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5717" expr : this is the expression to follow the directory. Will use s:ComposePath()
5718" pare =1: remove the current directory from the resulting glob() filelist
5719" =0: leave the current directory in the resulting glob() filelist
5720fun! s:NetrwGlob(direntry,expr,pare)
5721" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005722 if netrw#CheckIfRemote()
5723 keepalt 1sp
5724 keepalt enew
5725 let keep_liststyle = w:netrw_liststyle
5726 let w:netrw_liststyle = s:THINLIST
5727 if s:NetrwRemoteListing() == 0
5728 keepj keepalt %s@/@@
5729 let filelist= getline(1,$)
5730 q!
5731 else
5732 " remote listing error -- leave treedict unchanged
5733 let filelist= w:netrw_treedict[a:direntry]
5734 endif
5735 let w:netrw_liststyle= keep_liststyle
5736 else
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005737 let path= s:ComposePath(fnameescape(a:direntry), a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005738 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005739 " escape [ so it is not detected as wildcard character, see :h wildcard
5740 let path= substitute(path, '[', '[[]', 'g')
5741 endif
5742 if v:version > 704 || (v:version == 704 && has("patch656"))
5743 let filelist= glob(path,0,1,1)
5744 else
5745 let filelist= glob(path,0,1)
5746 endif
5747 if a:pare
5748 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5749 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005750 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005751 return filelist
5752endfun
5753
5754" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005755" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5756fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005757" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005758 if a:newfile =~ '[/@*=|\\]$'
5759 let newfile= substitute(a:newfile,'.$','','')
5760 else
5761 let newfile= a:newfile
5762 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005763 if a:islocal
5764 call s:NetrwBrowseChgDir(a:islocal,newfile)
5765 else
5766 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5767 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005768" call Dret("s:NetrwForceFile")
5769endfun
5770
5771" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005772" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5773" and switches the hiding mode. The actual hiding is done by
5774" s:NetrwListHide().
5775" g:netrw_hide= 0: show all
5776" 1: show not-hidden files
5777" 2: show hidden files only
5778fun! s:NetrwHide(islocal)
5779" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005780 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005781 let svpos= winsaveview()
5782" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005783
5784 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005785" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5786" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005787
5788 " hide the files in the markfile list
5789 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005790" call Decho("match(g:netrw_list_hide<".g:netrw_list_hide.'> fname<\<'.fname.'\>>)='.match(g:netrw_list_hide,'\<'.fname.'\>')." l:isk=".&l:isk,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005791 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5792 " remove fname from hiding list
5793 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5794 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5795 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005796" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005797 else
5798 " append fname to hiding list
5799 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5800 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5801 else
5802 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5803 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005804" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005805 endif
5806 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005807 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005808 let g:netrw_hide= 1
5809
5810 else
5811
5812 " switch between show-all/show-not-hidden/show-hidden
5813 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005814 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005815 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005816 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005817 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005818" call Dret("NetrwHide")
5819 return
5820 endif
5821 endif
5822
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005823 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005824" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5825 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005826 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005827" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005828endfun
5829
5830" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005831" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5832fun! s:NetrwHideEdit(islocal)
5833" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5834
5835 let ykeep= @@
5836 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005837 let svpos= winsaveview()
5838" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005839
5840 " get new hiding list from user
5841 call inputsave()
5842 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5843 call inputrestore()
5844 let g:netrw_list_hide= newhide
5845" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5846
5847 " refresh the listing
5848 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5849
5850 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005851" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5852 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005853 let @@= ykeep
5854
5855" call Dret("NetrwHideEdit")
5856endfun
5857
5858" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005859" s:NetrwHidden: invoked by "gh" {{{2
5860fun! s:NetrwHidden(islocal)
5861" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005862 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005863 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005864 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005865" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005866
5867 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005868 " remove .file pattern from hiding list
5869" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005870 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005871 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005872" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005873 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5874 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005875" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005876 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5877 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005878 if g:netrw_list_hide =~ '^,'
5879 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5880 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005881
5882 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005883 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005884" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5885 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005886 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005887" call Dret("s:NetrwHidden")
5888endfun
5889
5890" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005891" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5892fun! s:NetrwHome()
5893 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005894 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005895 else
5896 " go to vim plugin home
5897 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005898 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005899 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005900 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005901 let home= basehome."/.vim"
5902 break
5903 endif
5904 endfor
5905 if home == ""
5906 " just pick the first directory
5907 let home= substitute(&rtp,',.*$','','')
5908 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005909 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005910 let home= substitute(home,'/','\\','g')
5911 endif
5912 endif
5913 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005914 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005915" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005916 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005917" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005918 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005919 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005920" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005921 call mkdir(home)
5922 endif
5923 endif
5924 let g:netrw_home= home
5925 return home
5926endfun
5927
5928" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005929" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5930fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005931 if exists("s:netrwdrag")
5932 return
5933 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005934 if &ft != "netrw"
5935 return
5936 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005937" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005938
Bram Moolenaar97d62492012-11-15 21:28:22 +01005939 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005940 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005941 while getchar(0) != 0
5942 "clear the input stream
5943 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005944 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005945 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005946 let mouse_lnum = v:mouse_lnum
5947 let wlastline = line('w$')
5948 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005949" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5950" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005951 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5952 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005953 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005954" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5955 return
5956 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005957 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005958 " Windows are separated by vertical separator bars - but the mouse seems to be doing what it should when dragging that bar
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005959 " without this test when its disabled.
5960 " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005961" call Decho("v:mouse_col=".v:mouse_col." col#".col('.')." virtcol#".virtcol('.')." col($)#".col("$")." virtcol($)#".virtcol("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005962 if v:mouse_col > virtcol('.')
5963 let @@= ykeep
5964" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5965 return
5966 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005967
Bram Moolenaar446cb832008-06-24 21:56:24 +00005968 if a:islocal
5969 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005970 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005971 endif
5972 else
5973 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005974 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005975 endif
5976 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005977 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005978" call Dret("s:NetrwLeftmouse")
5979endfun
5980
5981" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005982" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5983fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005984 if &ft != "netrw"
5985 return
5986 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005987" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
5988 call s:NetrwMarkFileTgt(a:islocal)
5989" call Dret("s:NetrwCLeftmouse")
5990endfun
5991
5992" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005993" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5994" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005995" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005996" a:islocal=2 : <c-r> used, remote
5997" a:islocal=3 : <c-r> used, local
5998fun! s:NetrwServerEdit(islocal,fname)
5999" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6000 let islocal = a:islocal%2 " =0: remote =1: local
6001 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006002" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006003
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006004 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006005 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006006 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006007" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006008 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006009 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006010 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6011 unlet s:netrw_browse_split_{winnr()}
6012 endif
6013 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6014" call Dret("s:NetrwServerEdit")
6015 return
6016 endif
6017
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006018" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006019 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006020" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006021
6022 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006023" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006024 let srvrname = g:netrw_browse_split[0]
6025 let tabnum = g:netrw_browse_split[1]
6026 let winnum = g:netrw_browse_split[2]
6027
6028 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006029" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006030
6031 if !ctrlr
6032 " user must have closed the server window and the user did not use <c-r>, but
6033 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006034" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006035 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006036 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006037 endif
6038 let g:netrw_browse_split= 0
6039 if exists("s:netrw_browse_split_".winnr())
6040 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6041 endif
6042 call s:NetrwBrowseChgDir(islocal,a:fname)
6043" call Dret("s:NetrwServerEdit")
6044 return
6045
6046 elseif has("win32") && executable("start")
6047 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006048" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006049 call system("start gvim --servername ".srvrname)
6050
6051 else
6052 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006053" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006054 call system("gvim --servername ".srvrname)
6055 endif
6056 endif
6057
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006058" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006059 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6060 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006061 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006062
6063 else
6064
6065 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6066
6067 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006068" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006069 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006070 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006071 endif
6072 let g:netrw_browse_split= 0
6073 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6074" call Dret("s:NetrwServerEdit")
6075 return
6076
6077 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006078" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006079 if has("win32") && executable("start")
6080 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006081" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006082 call system("start gvim --servername ".g:netrw_servername)
6083 else
6084 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006085" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006086 call system("gvim --servername ".g:netrw_servername)
6087 endif
6088 endif
6089 endif
6090
6091 while 1
6092 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006093" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6094 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006095 break
6096 catch /^Vim\%((\a\+)\)\=:E241/
6097 sleep 200m
6098 endtry
6099 endwhile
6100
6101 if exists("g:netrw_browse_split")
6102 if type(g:netrw_browse_split) != 3
6103 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6104 endif
6105 unlet g:netrw_browse_split
6106 endif
6107 let g:netrw_browse_split= [g:netrw_servername,1,1]
6108 endif
6109
6110 else
6111 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6112 endif
6113
6114" call Dret("s:NetrwServerEdit")
6115endfun
6116
6117" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006118" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6119fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006120 if &ft != "netrw"
6121 return
6122 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006123" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006124
Bram Moolenaar8d043172014-01-23 14:24:41 +01006125 let s:ngw= s:NetrwGetWord()
6126 call s:NetrwMarkFile(a:islocal,s:ngw)
6127
6128" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006129endfun
6130
6131" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006132" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6133" Used to mark multiple files.
6134fun! s:NetrwSLeftdrag(islocal)
6135" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6136 if !exists("s:netrwdrag")
6137 let s:netrwdrag = winnr()
6138 if a:islocal
6139 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006140 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006141 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006142 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006143 endif
6144 let ngw = s:NetrwGetWord()
6145 if !exists("s:ngw") || s:ngw != ngw
6146 call s:NetrwMarkFile(a:islocal,ngw)
6147 endif
6148 let s:ngw= ngw
6149" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6150endfun
6151
6152" ---------------------------------------------------------------------
6153" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6154fun! s:NetrwSLeftrelease(islocal)
6155" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6156 if exists("s:netrwdrag")
6157 nunmap <s-leftrelease>
6158 let ngw = s:NetrwGetWord()
6159 if !exists("s:ngw") || s:ngw != ngw
6160 call s:NetrwMarkFile(a:islocal,ngw)
6161 endif
6162 if exists("s:ngw")
6163 unlet s:ngw
6164 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006165 unlet s:netrwdrag
6166 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006167" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006168endfun
6169
6170" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006171" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6172" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006173fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006174" call Dfunc("s:NetrwListHide() g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02006175" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006176 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006177
6178 " find a character not in the "hide" string to use as a separator for :g and :v commands
Bram Moolenaar85850f32019-07-19 22:05:51 +02006179 " How-it-works: take the hiding command, convert it into a range.
6180 " Duplicate characters don't matter.
6181 " Remove all such characters from the '/~@#...890' string.
6182 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006183" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006184 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006185 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006186" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006187
6188 while listhide != ""
6189 if listhide =~ ','
6190 let hide = substitute(listhide,',.*$','','e')
6191 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6192 else
6193 let hide = listhide
6194 let listhide = ""
6195 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006196" call Decho("..extracted pattern from listhide: hide<".hide."> g:netrw_sort_by<".g:netrw_sort_by.'>','~'.expand("<slnum>"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006197 if g:netrw_sort_by =~ '^[ts]'
6198 if hide =~ '^\^'
6199" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6200 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6201 elseif hide =~ '^\\(\^'
6202 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6203 endif
6204" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6205 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006206
6207 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006208" call Decho("..prune the list by hiding any files which ".((g:netrw_hide == 1)? "" : "don't")."match hide<".hide.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006209 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006210" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006211 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006212 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006213" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006214 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006215 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006216" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006217 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006218
Bram Moolenaar446cb832008-06-24 21:56:24 +00006219 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006220 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006221" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006222 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006223" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006224 endif
6225
Bram Moolenaaradc21822011-04-01 18:03:16 +02006226 " remove any blank lines that have somehow remained.
6227 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006228 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006229
Bram Moolenaar97d62492012-11-15 21:28:22 +01006230 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006231" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006232endfun
6233
6234" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006235" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006236" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006237fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006238" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006239
Bram Moolenaar97d62492012-11-15 21:28:22 +01006240 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006241 " get name of new directory from user. A bare <CR> will skip.
6242 " if its currently a directory, also request will be skipped, but with
6243 " a message.
6244 call inputsave()
6245 let newdirname= input("Please give directory name: ")
6246 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006247" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006248
6249 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006250 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006251" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006252 return
6253 endif
6254
6255 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006256" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006257
6258 " Local mkdir:
6259 " sanity checks
6260 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006261" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6262 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006263 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006264 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006265 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006266 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006267" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006268 return
6269 endif
6270 if s:FileReadable(fullnewdir)
6271 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006272 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006273 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006274 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006275" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006276 return
6277 endif
6278
6279 " requested new local directory is neither a pre-existing file or
6280 " directory, so make it!
6281 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006282 if has("unix")
6283 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6284 else
6285 call mkdir(fullnewdir,"p")
6286 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006287 else
6288 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006289 if s:NetrwLcd(b:netrw_curdir)
6290" call Dret("s:NetrwMakeDir : lcd failure")
6291 return
6292 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006293" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006294 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006295 if v:shell_error != 0
6296 let @@= ykeep
6297 call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006298" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006299 return
6300 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006301 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006302" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006303 if s:NetrwLcd(netrw_origdir)
6304" call Dret("s:NetrwBrowse : lcd failure")
6305 return
6306 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006307 endif
6308 endif
6309
6310 if v:shell_error == 0
6311 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006312" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006313 let svpos= winsaveview()
6314" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006315 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006316" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6317 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006318 elseif !exists("g:netrw_quiet")
6319 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6320 endif
6321" redraw!
6322
6323 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006324 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006325" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006326 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6327 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006328 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006329 if v:shell_error == 0
6330 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006331 let svpos= winsaveview()
6332" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006333 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006334" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6335 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006336 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006337 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006338 endif
6339" redraw!
6340
6341 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006342 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006343 let svpos= winsaveview()
6344" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006345" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006346 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006347" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006348 let remotepath= b:netrw_fname
6349 else
6350 let remotepath= ""
6351 endif
6352 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006353 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006354" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6355 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006356
Bram Moolenaar446cb832008-06-24 21:56:24 +00006357 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006358 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006359 let svpos= winsaveview()
6360" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006361" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006362 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006363" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006364 let remotepath= b:netrw_fname
6365 else
6366 let remotepath= ""
6367 endif
6368 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006369 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006370" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6371 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006372 endif
6373
Bram Moolenaar97d62492012-11-15 21:28:22 +01006374 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006375" call Dret("s:NetrwMakeDir")
6376endfun
6377
6378" ---------------------------------------------------------------------
6379" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6380fun! s:TreeSqueezeDir(islocal)
6381" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6382 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6383 " its a tree-listing style
6384 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006385 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006386 let depth = strchars(substitute(curdepth,' ','','g'))
6387 let srch = -1
6388" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6389" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006390" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006391" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6392 if depth >= 2
6393 NetrwKeepj norm! 0
6394 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6395 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6396" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6397" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6398 elseif depth == 1
6399 NetrwKeepj norm! 0
6400 let treedepthchr= substitute(s:treedepthstring,' ','','')
6401 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6402" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6403 endif
6404 if srch > 0
6405" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6406 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6407 exe srch
6408 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006409 endif
6410" call Dret("s:TreeSqueezeDir")
6411endfun
6412
6413" ---------------------------------------------------------------------
6414" s:NetrwMaps: {{{2
6415fun! s:NetrwMaps(islocal)
6416" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6417
Bram Moolenaar85850f32019-07-19 22:05:51 +02006418 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006419 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006420" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006421 if !hasmapto("<Plug>NetrwReturn")
6422 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006423" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006424 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6425 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006426" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006427 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6428 endif
6429 endif
6430 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006431" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006432 endif
6433
Bram Moolenaar85850f32019-07-19 22:05:51 +02006434 " generate default <Plug> maps {{{3
6435 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006436 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006437 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6438 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6439 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6440 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6441 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6442 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6443 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6444 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6445 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6446 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6447" ---------------------------------------------------------------------
6448" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6449" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6450" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6451" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6452" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6453" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6454" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6455" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6456" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6457" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6458" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6459" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6460" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6461" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6462" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6463" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6464" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6465" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6466" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6467" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6468" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6469" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6470" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6471" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6472" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6473" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6474" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6475" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6476" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6477" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6478" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6479" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6480" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6481" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6482" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6483" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6484" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6485" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6486" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6487" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6488" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6489" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6490" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6491" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6492" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6493" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6494" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6495
Bram Moolenaara6878372014-03-22 21:02:50 +01006496 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006497" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006498 " local normal-mode maps {{{3
6499 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6500 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6501 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6502 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6503 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6504 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6505 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6506 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6507 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6508 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6509 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6510" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006511 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6512 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6513 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006514 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006515 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006516 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6517 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6518 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6519 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006520 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6521 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6522 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6523 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6524 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6525 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6526 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6527 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6528 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6529 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6530 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6531 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6532 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006533 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006534 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006535 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6536 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6537 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6538 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6539 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006540 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006541 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006542 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6543 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006544 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6545 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6546 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006547 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006548 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006549 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6550 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006551 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006552 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006553 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6554 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6555 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006556 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6557 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006558
6559 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,'./'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006560 if !hasmapto('<Plug>NetrwHideEdit')
6561 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006562 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006563 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006564 if !hasmapto('<Plug>NetrwRefresh')
6565 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006566 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006567 nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(exists("w:netrw_liststyle") && exists("w:netrw_treetop") && w:netrw_liststyle == 3)? w:netrw_treetop : './'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006568 if s:didstarstar || !mapcheck("<s-down>","n")
6569 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006570 endif
6571 if s:didstarstar || !mapcheck("<s-up>","n")
6572 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006573 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006574 if !hasmapto('<Plug>NetrwTreeSqueeze')
6575 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006576 endif
6577 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006578 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6579 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006580 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6581 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6582 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6583 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6584 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6585 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6586 imap <buffer> <leftmouse> <Plug>ILeftmouse
6587 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006588 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6589 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6590 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6591 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6592 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006593 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006594 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6595 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006596 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006597 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6598 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6599 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6600 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6601 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6602 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6603 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006604 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6605
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006606 " support user-specified maps
6607 call netrw#UserMaps(1)
6608
Bram Moolenaar85850f32019-07-19 22:05:51 +02006609 else
6610 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006611" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006612 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006613 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6614 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6615 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6616 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6617 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6618 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6619 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6620 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6621 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6622 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6623 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6624" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006625 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6626 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6627 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6628 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6629 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6630 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6631 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6632 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006633 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006634 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006635 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6636 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6637 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6638 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6639 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6640 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6641 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6642 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6643 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6644 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6645 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006646 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006647 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006648 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6649 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6650 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6651 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6652 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006653 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6654 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6655 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6656 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006657 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006658 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6659 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006660 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006661 nnoremap <buffer> <silent> <nowait> r :<c-u>let g:netrw_sort_direction= (g:netrw_sort_direction =~# 'n')? 'r' : 'n'<bar>exe "norm! 0"<bar>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006662 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6663 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6664 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6665 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6666 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6667 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6668 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6669 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6670 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006671 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006672 if !hasmapto('<Plug>NetrwHideEdit')
6673 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006674 endif
6675 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6676 if !hasmapto('<Plug>NetrwRefresh')
6677 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006678 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006679 if !hasmapto('<Plug>NetrwTreeSqueeze')
6680 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006681 endif
6682 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006683
6684 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006685 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006686
6687 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6688 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006689 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006690 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006691 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006692 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006693 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006694 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006695 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006696 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006697 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006698 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006699 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6700 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6701 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006702 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006703 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006704 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6705 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006706 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006707 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6708 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6709 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6710 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6711 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6712 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6713 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006714 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006715
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006716 " support user-specified maps
6717 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006718 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006719
6720" call Dret("s:NetrwMaps")
6721endfun
6722
6723" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006724" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006725" If -buffer, the command is only available from within netrw buffers
6726" Otherwise, the command is available from any window, so long as netrw
6727" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006728fun! s:NetrwCommands(islocal)
6729" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6730
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006731 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6732 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006733 com! Rexplore if exists("w:netrw_rexlocal")|call s:NetrwRexplore(w:netrw_rexlocal,exists("w:netrw_rexdir")? w:netrw_rexdir : ".")|else|call netrw#ErrorMsg(s:WARNING,"win#".winnr()." not a former netrw window",79)|endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006734 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006735 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006736 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006737 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006738 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006739 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006740
6741" call Dret("s:NetrwCommands")
6742endfun
6743
6744" ---------------------------------------------------------------------
6745" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6746" glob()ing only works with local files
6747fun! s:NetrwMarkFiles(islocal,...)
6748" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006749 let curdir = s:NetrwGetCurdir(a:islocal)
6750 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006751 while i <= a:0
6752 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006753 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006754 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006755 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006756 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006757 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006758 else
6759 let mffiles= [a:{i}]
6760 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006761" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006762 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006763" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006764 call s:NetrwMarkFile(a:islocal,mffile)
6765 endfor
6766 let i= i + 1
6767 endwhile
6768" call Dret("s:NetrwMarkFiles")
6769endfun
6770
6771" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006772" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006773fun! s:NetrwMarkTarget(...)
6774" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6775 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006776 let curdir = s:NetrwGetCurdir(1)
6777 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006778 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006779 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6780 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006781 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006782" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006783 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006784 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6785 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006786 let svpos = winsaveview()
6787" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006788 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006789" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6790 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006791" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006792endfun
6793
6794" ---------------------------------------------------------------------
6795" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6796" mark and unmark files. If a markfile list exists,
6797" then the rename and delete functions will use it instead
6798" of whatever may happen to be under the cursor at that
6799" moment. When the mouse and gui are available,
6800" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006801"
6802" Creates two lists
6803" s:netrwmarkfilelist -- holds complete paths to all marked files
6804" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6805"
6806" Creates a marked file match string
6807" s:netrwmarfilemtch_# -- used with 2match to display marked files
6808"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006809" Creates a buffer version of islocal
6810" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006811fun! s:NetrwMarkFile(islocal,fname)
6812" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006813" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006814
6815 " sanity check
6816 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006817" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006818 return
6819 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006820 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006821
Bram Moolenaar97d62492012-11-15 21:28:22 +01006822 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006823 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006824 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006825 if a:fname =~ '\a$'
6826 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6827 else
6828 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6829 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006830
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006831 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006832 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006833" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6834" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6835" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006836 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006837
6838 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006839 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006840" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006841 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006842 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006843
6844 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006845 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006846" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006847 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6848 if s:netrwmarkfilelist_{curbufnr} == []
6849 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006850" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006851 call s:NetrwUnmarkList(curbufnr,curdir)
6852 else
6853 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006854" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006855 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006856 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006857 for fname in s:netrwmarkfilelist_{curbufnr}
6858 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006859 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006860 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006861 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006862 endif
6863 let first= 0
6864 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006865" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006866 endif
6867 endif
6868
6869 else
6870 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006871" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006872
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006873" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006874 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006875 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6876" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006877
6878 " build initial markfile matching pattern
6879 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006880 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006881 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006882 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006884" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006885 endif
6886
6887 " handle global markfilelist
6888 if exists("s:netrwmarkfilelist")
6889 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6890 if index(s:netrwmarkfilelist,dname) == -1
6891 " append new filename to global markfilelist
6892 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006893" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006894 else
6895 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006896" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6897" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006898 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006899" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006900 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006901" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006902 unlet s:netrwmarkfilelist
6903 endif
6904 endif
6905 else
6906 " initialize new global-directory markfilelist
6907 let s:netrwmarkfilelist= []
6908 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006909" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006910 endif
6911
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006912 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006913 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6914 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6915" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6916 if exists("g:did_drchip_netrwlist_syntax")
6917 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6918 endif
6919 else
6920" " call Decho("2match none",'~'.expand("<slnum>"))
6921 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006922 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006923 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006924 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006925" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6926" call Dret("s:NetrwMarkFile : s:netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist")."> (buf#".curbufnr."list)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927endfun
6928
6929" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006930" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6931" mA: move the argument list to marked file list (tomflist=1)
6932" Uses the global marked file list
6933fun! s:NetrwMarkFileArgList(islocal,tomflist)
6934" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6935
6936 let svpos = winsaveview()
6937" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6938 let curdir = s:NetrwGetCurdir(a:islocal)
6939 let curbufnr = bufnr("%")
6940
6941 if a:tomflist
6942 " mA: move argument list to marked file list
6943 while argc()
6944 let fname= argv(0)
6945" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6946 exe "argdel ".fnameescape(fname)
6947 call s:NetrwMarkFile(a:islocal,fname)
6948 endwhile
6949
6950 else
6951 " ma: move marked file list to argument list
6952 if exists("s:netrwmarkfilelist")
6953
6954 " for every filename in the marked list
6955 for fname in s:netrwmarkfilelist
6956" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6957 exe "argadd ".fnameescape(fname)
6958 endfor " for every file in the marked list
6959
6960 " unmark list and refresh
6961 call s:NetrwUnmarkList(curbufnr,curdir)
6962 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6963" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6964 NetrwKeepj call winrestview(svpos)
6965 endif
6966 endif
6967
6968" call Dret("s:NetrwMarkFileArgList")
6969endfun
6970
6971" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006972" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6973" compress/decompress files using the programs
6974" in g:netrw_compress and g:netrw_uncompress,
6975" using g:netrw_compress_suffix to know which to
6976" do. By default:
6977" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006978" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006979fun! s:NetrwMarkFileCompress(islocal)
6980" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006981 let svpos = winsaveview()
6982" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006983 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006984 let curbufnr = bufnr("%")
6985
Bram Moolenaarff034192013-04-24 18:51:19 +02006986 " sanity check
6987 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006988 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006989" call Dret("s:NetrwMarkFileCompress")
6990 return
6991 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006992" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006993
Bram Moolenaar446cb832008-06-24 21:56:24 +00006994 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006995
6996 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006997 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006998 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006999" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007000 if exists("g:netrw_decompress['".sfx."']")
7001 " fname has a suffix indicating that its compressed; apply associated decompression routine
7002 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007003" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007004 let exe= netrw#WinPath(exe)
7005 if a:islocal
7006 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007007 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007008 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007009 call system(exe." ".fname)
7010 if v:shell_error
7011 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007012 endif
7013 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007014 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7015 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007016 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007017
Bram Moolenaarff034192013-04-24 18:51:19 +02007018 endif
7019 unlet sfx
7020
Bram Moolenaar446cb832008-06-24 21:56:24 +00007021 if exists("exe")
7022 unlet exe
7023 elseif a:islocal
7024 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007025 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007026 if v:shell_error
7027 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7028 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007029 else
7030 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007031 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007032 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007033 endfor " for every file in the marked list
7034
Bram Moolenaar446cb832008-06-24 21:56:24 +00007035 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007036 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007037" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7038 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007039 endif
7040" call Dret("s:NetrwMarkFileCompress")
7041endfun
7042
7043" ---------------------------------------------------------------------
7044" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7045" If no marked files, then set up directory as the
7046" target. Currently does not support copying entire
7047" directories. Uses the local-buffer marked file list.
7048" Returns 1=success (used by NetrwMarkFileMove())
7049" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007050fun! s:NetrwMarkFileCopy(islocal,...)
7051" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7052
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007053 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007054 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007055 if b:netrw_curdir !~ '/$'
7056 if !exists("b:netrw_curdir")
7057 let b:netrw_curdir= curdir
7058 endif
7059 let b:netrw_curdir= b:netrw_curdir."/"
7060 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007061
Bram Moolenaarff034192013-04-24 18:51:19 +02007062 " sanity check
7063 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007064 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007065" call Dret("s:NetrwMarkFileCopy")
7066 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007067 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007068" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007069
Bram Moolenaar446cb832008-06-24 21:56:24 +00007070 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007071 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007072" call Dret("s:NetrwMarkFileCopy 0")
7073 return 0
7074 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007075" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007076
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007077 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007078 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007079" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007080 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007081 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7082" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7083 return
7084 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007085
7086 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007087 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007088 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7089 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007090" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007091 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007092 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7093 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007094" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007095 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007096 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007097 let oldname = a:1
7098 else
7099 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007100" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007101 let s:recursive= 1
7102 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7103 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7104 if ret == 0
7105 break
7106 endif
7107 endfor
7108 unlet s:recursive
7109 call s:NetrwUnmarkList(curbufnr,curdir)
7110" call Dret("s:NetrwMarkFileCopy ".ret)
7111 return ret
7112 endif
7113
7114 call inputsave()
7115 let newname= input("Copy ".oldname." to : ",oldname,"file")
7116 call inputrestore()
7117 if newname == ""
7118" call Dret("s:NetrwMarkFileCopy 0")
7119 return 0
7120 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007121 let args= s:ShellEscape(oldname)
7122 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007123 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007124 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7125 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007126 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007127 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007128 let args= substitute(args,'/','\\','g')
7129 let tgt = substitute(tgt, '/','\\','g')
7130 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007131 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7132 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7133 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7134 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7135" call Decho("args <".args.">",'~'.expand("<slnum>"))
7136" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007137 if isdirectory(s:NetrwFile(args))
7138" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007139 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007140" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007141 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007142 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7143 " contents to a target. One must append the source directory name to the target to get xcopy to
7144 " do the right thing.
7145 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007146" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007147 endif
7148 else
7149 let copycmd= g:netrw_localcopycmd
7150 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007151 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007152 let copycmd = substitute(copycmd,'\s.*$','','')
7153 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007154 let copycmd = netrw#WinPath(copycmd).copycmdargs
7155 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007156 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007157 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007158" call Decho("args <".args.">",'~'.expand("<slnum>"))
7159" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7160" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7161" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007162 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007163 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007164 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007165 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)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007166 else
7167 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7168 endif
7169" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007170 return 0
7171 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007172
7173 elseif a:islocal && !s:netrwmftgt_islocal
7174 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007175" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007176 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007177
7178 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007179 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007180" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007181 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007182
7183 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007184 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007185" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007186 let curdir = getcwd()
7187 let tmpdir = s:GetTempfile("")
7188 if tmpdir !~ '/'
7189 let tmpdir= curdir."/".tmpdir
7190 endif
7191 if exists("*mkdir")
7192 call mkdir(tmpdir)
7193 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007194 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007195 if v:shell_error != 0
7196 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007197" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007198 return
7199 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007200 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007201 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007202 if s:NetrwLcd(tmpdir)
7203" call Dret("s:NetrwMarkFileCopy : lcd failure")
7204 return
7205 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007206 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007207 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007208 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007209 if getcwd() == tmpdir
7210 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007211 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007212 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007213 if s:NetrwLcd(curdir)
7214" call Dret("s:NetrwMarkFileCopy : lcd failure")
7215 return
7216 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007217 if delete(tmpdir,"d")
7218 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007219 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007220 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007221 if s:NetrwLcd(curdir)
7222" call Dret("s:NetrwMarkFileCopy : lcd failure")
7223 return
7224 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007225 endif
7226 endif
7227 endif
7228
7229 " -------
7230 " cleanup
7231 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007232" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007233 " remove markings from local buffer
7234 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007235" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7236" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7237" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7238" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7239" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7240" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7241 if exists("s:recursive")
7242" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7243 else
7244" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007245 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007246 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007247 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007248 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007249 else
7250 " refresh local and targets for fast browsing
7251 if !exists("s:recursive")
7252 " remove markings from local buffer
7253" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7254 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7255 endif
7256
7257 " refresh buffers
7258 if s:netrwmftgt_islocal
7259" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7260 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7261 endif
7262 if a:islocal && s:netrwmftgt != curdir
7263" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7264 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7265 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007266 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007267
Bram Moolenaar446cb832008-06-24 21:56:24 +00007268" call Dret("s:NetrwMarkFileCopy 1")
7269 return 1
7270endfun
7271
7272" ---------------------------------------------------------------------
7273" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7274" invoke vim's diff mode on the marked files.
7275" Either two or three files can be so handled.
7276" Uses the global marked file list.
7277fun! s:NetrwMarkFileDiff(islocal)
7278" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7279 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007280
Bram Moolenaarff034192013-04-24 18:51:19 +02007281 " sanity check
7282 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007283 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007284" call Dret("s:NetrwMarkFileDiff")
7285 return
7286 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007287 let curdir= s:NetrwGetCurdir(a:islocal)
7288" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007289
Bram Moolenaara6878372014-03-22 21:02:50 +01007290 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007291 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007292 for fname in s:netrwmarkfilelist
7293 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007294 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007295" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007296 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007297 diffthis
7298 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007299 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007300" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007301 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007302 diffthis
7303 else
7304 break
7305 endif
7306 endfor
7307 call s:NetrwUnmarkList(curbufnr,curdir)
7308 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007309
Bram Moolenaar446cb832008-06-24 21:56:24 +00007310" call Dret("s:NetrwMarkFileDiff")
7311endfun
7312
7313" ---------------------------------------------------------------------
7314" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7315" Uses global markfilelist
7316fun! s:NetrwMarkFileEdit(islocal)
7317" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7318
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007319 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007320 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007321
7322 " sanity check
7323 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007324 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007325" call Dret("s:NetrwMarkFileEdit")
7326 return
7327 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007328" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007329
Bram Moolenaar446cb832008-06-24 21:56:24 +00007330 if exists("s:netrwmarkfilelist_{curbufnr}")
7331 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007332 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007333 " unmark markedfile list
7334" call s:NetrwUnmarkList(curbufnr,curdir)
7335 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007336" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007337 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007338 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007339 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007340
Bram Moolenaar446cb832008-06-24 21:56:24 +00007341" call Dret("s:NetrwMarkFileEdit")
7342endfun
7343
7344" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007345" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007346fun! s:NetrwMarkFileQFEL(islocal,qfel)
7347" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7348 call s:NetrwUnmarkAll()
7349 let curbufnr= bufnr("%")
7350
7351 if !empty(a:qfel)
7352 for entry in a:qfel
7353 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007354" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007355 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007356" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007357 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7358 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7359 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7360 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007361" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007362 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7363 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007364" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007365 endif
7366 endfor
7367 echo "(use me to edit marked files)"
7368 else
7369 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7370 endif
7371
7372" call Dret("s:NetrwMarkFileQFEL")
7373endfun
7374
7375" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007376" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7377" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7378" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7379fun! s:NetrwMarkFileExe(islocal,enbloc)
7380" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007381 let svpos = winsaveview()
7382" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007383 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007384 let curbufnr = bufnr("%")
7385
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007386 if a:enbloc == 0
7387 " individually apply command to files, one at a time
7388 " sanity check
7389 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7390 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7391" call Dret("s:NetrwMarkFileExe")
7392 return
7393 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007394" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007395
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007396 if exists("s:netrwmarkfilelist_{curbufnr}")
7397 " get the command
7398 call inputsave()
7399 let cmd= input("Enter command: ","","file")
7400 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007401" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007402 if cmd == ""
7403" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7404 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007405 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007406
7407 " apply command to marked files, individually. Substitute: filename -> %
7408 " If no %, then append a space and the filename to the command
7409 for fname in s:netrwmarkfilelist_{curbufnr}
7410 if a:islocal
7411 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007412 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007413 endif
7414 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007415 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007416 endif
7417 if cmd =~ '%'
7418 let xcmd= substitute(cmd,'%',fname,'g')
7419 else
7420 let xcmd= cmd.' '.fname
7421 endif
7422 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007423" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007424 let ret= system(xcmd)
7425 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007426" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007427 let ret= s:RemoteSystem(xcmd)
7428 endif
7429 if v:shell_error < 0
7430 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7431 break
7432 else
yasudac75dad02024-08-22 21:06:32 +02007433 if ret !=# ''
7434 echo "\n"
7435 " skip trailing new line
7436 echo ret[0:-2]
7437 else
7438 echo ret
7439 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007440 endif
7441 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007442
7443 " unmark marked file list
7444 call s:NetrwUnmarkList(curbufnr,curdir)
7445
7446 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007447 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007448" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7449 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007450 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007451 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007452 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007453
7454 else " apply command to global list of files, en bloc
7455
7456 call inputsave()
7457 let cmd= input("Enter command: ","","file")
7458 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007459" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007460 if cmd == ""
7461" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7462 return
7463 endif
7464 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007465 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007466 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007467 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007468 endif
7469 if a:islocal
7470 call system(cmd)
7471 if v:shell_error < 0
7472 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7473 endif
7474 else
7475 let ret= s:RemoteSystem(cmd)
7476 endif
7477 call s:NetrwUnmarkAll()
7478
7479 " refresh the listing
7480 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007481" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7482 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483
7484 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007485
Bram Moolenaar446cb832008-06-24 21:56:24 +00007486" call Dret("s:NetrwMarkFileExe")
7487endfun
7488
7489" ---------------------------------------------------------------------
7490" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7491" as the marked file(s) (toggles suffix presence)
7492" Uses the local marked file list.
7493fun! s:NetrwMarkHideSfx(islocal)
7494" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007495 let svpos = winsaveview()
7496" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007497 let curbufnr = bufnr("%")
7498
7499 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7500 if exists("s:netrwmarkfilelist_{curbufnr}")
7501
7502 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007503" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007504 " construct suffix pattern
7505 if fname =~ '\.'
7506 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7507 else
7508 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7509 endif
7510 " determine if its in the hiding list or not
7511 let inhidelist= 0
7512 if g:netrw_list_hide != ""
7513 let itemnum = 0
7514 let hidelist= split(g:netrw_list_hide,',')
7515 for hidepat in hidelist
7516 if sfxpat == hidepat
7517 let inhidelist= 1
7518 break
7519 endif
7520 let itemnum= itemnum + 1
7521 endfor
7522 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007523" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007524 if inhidelist
7525 " remove sfxpat from list
7526 call remove(hidelist,itemnum)
7527 let g:netrw_list_hide= join(hidelist,",")
7528 elseif g:netrw_list_hide != ""
7529 " append sfxpat to non-empty list
7530 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7531 else
7532 " set hiding list to sfxpat
7533 let g:netrw_list_hide= sfxpat
7534 endif
7535 endfor
7536
7537 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007538 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007539" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7540 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007541 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007542 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007543 endif
7544
7545" call Dret("s:NetrwMarkHideSfx")
7546endfun
7547
7548" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007549" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007550" Uses the local marked-file list.
7551fun! s:NetrwMarkFileVimCmd(islocal)
7552" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007553 let svpos = winsaveview()
7554" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007555 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007556 let curbufnr = bufnr("%")
7557
Bram Moolenaarff034192013-04-24 18:51:19 +02007558 " sanity check
7559 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007560 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007561" call Dret("s:NetrwMarkFileVimCmd")
7562 return
7563 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007564" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007565
Bram Moolenaar15146672011-10-20 22:22:38 +02007566 if exists("s:netrwmarkfilelist_{curbufnr}")
7567 " get the command
7568 call inputsave()
7569 let cmd= input("Enter vim command: ","","file")
7570 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007571" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007572 if cmd == ""
7573" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7574 return
7575 endif
7576
7577 " apply command to marked files. Substitute: filename -> %
7578 " If no %, then append a space and the filename to the command
7579 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007580" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007581 if a:islocal
7582 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007583 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007584" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007585 exe cmd
7586 exe "sil! keepalt wq!"
7587 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007588" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007589 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007590 endif
7591 endfor
7592
7593 " unmark marked file list
7594 call s:NetrwUnmarkList(curbufnr,curdir)
7595
7596 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007597 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007598" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7599 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007600 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007601 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007602 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007603
Bram Moolenaar15146672011-10-20 22:22:38 +02007604" call Dret("s:NetrwMarkFileVimCmd")
7605endfun
7606
7607" ---------------------------------------------------------------------
7608" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7609" as the marked file(s) (toggles suffix presence)
7610" Uses the local marked file list.
7611fun! s:NetrwMarkHideSfx(islocal)
7612" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007613 let svpos = winsaveview()
7614" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007615 let curbufnr = bufnr("%")
7616
7617 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7618 if exists("s:netrwmarkfilelist_{curbufnr}")
7619
7620 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007621" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007622 " construct suffix pattern
7623 if fname =~ '\.'
7624 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7625 else
7626 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7627 endif
7628 " determine if its in the hiding list or not
7629 let inhidelist= 0
7630 if g:netrw_list_hide != ""
7631 let itemnum = 0
7632 let hidelist= split(g:netrw_list_hide,',')
7633 for hidepat in hidelist
7634 if sfxpat == hidepat
7635 let inhidelist= 1
7636 break
7637 endif
7638 let itemnum= itemnum + 1
7639 endfor
7640 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007641" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007642 if inhidelist
7643 " remove sfxpat from list
7644 call remove(hidelist,itemnum)
7645 let g:netrw_list_hide= join(hidelist,",")
7646 elseif g:netrw_list_hide != ""
7647 " append sfxpat to non-empty list
7648 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7649 else
7650 " set hiding list to sfxpat
7651 let g:netrw_list_hide= sfxpat
7652 endif
7653 endfor
7654
7655 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007656 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007657" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7658 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007659 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007660 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007661 endif
7662
7663" call Dret("s:NetrwMarkHideSfx")
7664endfun
7665
7666" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007667" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7668" Uses the global markfilelist
7669fun! s:NetrwMarkFileGrep(islocal)
7670" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007671 let svpos = winsaveview()
7672" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007673 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007674 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007675
7676 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007677" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007678 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007679" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007680 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007681 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007682" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007683 let netrwmarkfilelist= "*"
7684 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007685
Bram Moolenaarff034192013-04-24 18:51:19 +02007686 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007687" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007688 call inputsave()
7689 let pat= input("Enter pattern: ","")
7690 call inputrestore()
7691 let patbang = ""
7692 if pat =~ '^!'
7693 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007694 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007695 endif
7696 if pat =~ '^\i'
7697 let pat = escape(pat,'/')
7698 let pat = '/'.pat.'/'
7699 else
7700 let nonisi = pat[0]
7701 endif
7702
7703 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007704" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007705 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007706 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007707 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007708 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007709" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7710 return
7711 endtry
7712 echo "(use :cn, :cp to navigate, :Rex to return)"
7713
7714 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007715" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7716 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007717
7718 if exists("nonisi")
7719 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007720" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007721 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007722 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007723 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007724 endif
7725
7726" call Dret("s:NetrwMarkFileGrep")
7727endfun
7728
7729" ---------------------------------------------------------------------
7730" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7731" uses the global marked file list
7732" s:netrwmfloc= 0: target directory is remote
7733" = 1: target directory is local
7734fun! s:NetrwMarkFileMove(islocal)
7735" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007736 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007737 let curbufnr = bufnr("%")
7738
7739 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007740 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007741 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007742" call Dret("s:NetrwMarkFileMove")
7743 return
7744 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007745" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007746
Bram Moolenaar446cb832008-06-24 21:56:24 +00007747 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007748 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007749" call Dret("s:NetrwMarkFileCopy 0")
7750 return 0
7751 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007752" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007753
7754 if a:islocal && s:netrwmftgt_islocal
7755 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007756" call Decho("move from local to local",'~'.expand("<slnum>"))
7757" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007758 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007759 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7760" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7761 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007762 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007763 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007764" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007765 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007766 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007767" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007768 if g:netrw_localmovecmd =~ '\s'
7769 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7770 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7771 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007772" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007773 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007774 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007775" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007776 endif
7777 else
7778 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007779" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007780 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007781 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007782 if g:netrw_keepdir
7783 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7784 let fname= b:netrw_curdir."/".fname
7785 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007786 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007787 let fname= substitute(fname,'/','\\','g')
7788 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007789" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007790 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007791 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007792 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007793 call netrw#ErrorMsg(s:ERROR,"move failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",100)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007794 else
7795 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7796 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007797 break
7798 endif
7799 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007800
7801 elseif a:islocal && !s:netrwmftgt_islocal
7802 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007803" call Decho("move from local to remote",'~'.expand("<slnum>"))
7804" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007805 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007806 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007807" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007808 for fname in mflist
7809 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7810 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7811 endfor
7812 unlet mflist
7813
7814 elseif !a:islocal && s:netrwmftgt_islocal
7815 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007816" call Decho("move from remote to local",'~'.expand("<slnum>"))
7817" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007818 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007819 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007820" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007821 for fname in mflist
7822 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7823 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7824 endfor
7825 unlet mflist
7826
7827 elseif !a:islocal && !s:netrwmftgt_islocal
7828 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007829" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7830" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007831 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007832 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007833" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007834 for fname in mflist
7835 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7836 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7837 endfor
7838 unlet mflist
7839 endif
7840
7841 " -------
7842 " cleanup
7843 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007844" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007845
7846 " remove markings from local buffer
7847 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7848
7849 " refresh buffers
7850 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007851" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007852 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007853 endif
7854 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007855" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007856 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007857 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007858 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007859" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007860 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007861 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007862
Bram Moolenaar446cb832008-06-24 21:56:24 +00007863" call Dret("s:NetrwMarkFileMove")
7864endfun
7865
7866" ---------------------------------------------------------------------
7867" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7868" using the hardcopy command. Local marked-file list only.
7869fun! s:NetrwMarkFilePrint(islocal)
7870" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7871 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007872
7873 " sanity check
7874 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007875 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007876" call Dret("s:NetrwMarkFilePrint")
7877 return
7878 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007879" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7880 let curdir= s:NetrwGetCurdir(a:islocal)
7881
Bram Moolenaar446cb832008-06-24 21:56:24 +00007882 if exists("s:netrwmarkfilelist_{curbufnr}")
7883 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007884 call s:NetrwUnmarkList(curbufnr,curdir)
7885 for fname in netrwmarkfilelist
7886 if a:islocal
7887 if g:netrw_keepdir
7888 let fname= s:ComposePath(curdir,fname)
7889 endif
7890 else
7891 let fname= curdir.fname
7892 endif
7893 1split
7894 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007895" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007896 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007897" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007898 hardcopy
7899 q
7900 endfor
7901 2match none
7902 endif
7903" call Dret("s:NetrwMarkFilePrint")
7904endfun
7905
7906" ---------------------------------------------------------------------
7907" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7908" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007909" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007910fun! s:NetrwMarkFileRegexp(islocal)
7911" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7912
7913 " get the regular expression
7914 call inputsave()
7915 let regexp= input("Enter regexp: ","","file")
7916 call inputrestore()
7917
7918 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007919 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007920" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007921 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007922" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007923 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007924 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007925 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007926 else
7927 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007928 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007929 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007930" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007931
7932 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007933 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007934 if fname =~ '^'.fnameescape(curdir)
7935" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7936 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7937 else
7938" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7939 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7940 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007941 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007942
7943 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007944" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007945
7946 " convert displayed listing into a filelist
7947 let eikeep = &ei
7948 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007949 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007950 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007951" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007952 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007953 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007954 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007955 sil NetrwKeepj norm! "ap
7956 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007957 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007958 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007959 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007960 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007961 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007962 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007963 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007964 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007965 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007966 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007967 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7968 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007969 call histdel("/",-1)
7970 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007971 endif
7972 " convert regexp into the more usual glob-style format
7973 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007974" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007975 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007976 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007977 let filelist= getline(1,line("$"))
7978 q!
7979 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007980 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007981 endfor
7982 unlet filelist
7983 let @a = areg
7984 let &ei = eikeep
7985 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007986 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007987
7988" call Dret("s:NetrwMarkFileRegexp")
7989endfun
7990
7991" ---------------------------------------------------------------------
7992" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7993" Uses the local marked file list.
7994fun! s:NetrwMarkFileSource(islocal)
7995" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7996 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007997
7998 " sanity check
7999 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008000 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008001" call Dret("s:NetrwMarkFileSource")
8002 return
8003 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008004" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8005 let curdir= s:NetrwGetCurdir(a:islocal)
8006
Bram Moolenaar446cb832008-06-24 21:56:24 +00008007 if exists("s:netrwmarkfilelist_{curbufnr}")
8008 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008009 call s:NetrwUnmarkList(curbufnr,curdir)
8010 for fname in netrwmarkfilelist
8011 if a:islocal
8012 if g:netrw_keepdir
8013 let fname= s:ComposePath(curdir,fname)
8014 endif
8015 else
8016 let fname= curdir.fname
8017 endif
8018 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008019" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008020 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 endfor
8022 2match none
8023 endif
8024" call Dret("s:NetrwMarkFileSource")
8025endfun
8026
8027" ---------------------------------------------------------------------
8028" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8029" Uses the global markfilelist
8030fun! s:NetrwMarkFileTag(islocal)
8031" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008032 let svpos = winsaveview()
8033" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008034 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008035 let curbufnr = bufnr("%")
8036
Bram Moolenaarff034192013-04-24 18:51:19 +02008037 " sanity check
8038 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008039 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008040" call Dret("s:NetrwMarkFileTag")
8041 return
8042 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008043" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008044
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008046" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8047 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048 call s:NetrwUnmarkAll()
8049
8050 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008051
8052" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8053 call system(g:netrw_ctags." ".netrwmarkfilelist)
8054 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008055 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8056 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008057
Bram Moolenaar446cb832008-06-24 21:56:24 +00008058 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008059 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008060 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008061 let curdir= b:netrw_curdir
8062 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008063 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008064 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008065" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008066 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008067 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008068 wq!
8069 endif
8070 2match none
8071 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008072" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8073 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008074 endif
8075
8076" call Dret("s:NetrwMarkFileTag")
8077endfun
8078
8079" ---------------------------------------------------------------------
8080" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008081" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008082" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008083" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008084" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008085fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008086" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8087 let svpos = winsaveview()
8088" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008089 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008090 let hadtgt = exists("s:netrwmftgt")
8091 if !exists("w:netrw_bannercnt")
8092 let w:netrw_bannercnt= b:netrw_bannercnt
8093 endif
8094
8095 " set up target
8096 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008097" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008098 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8099 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008100" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008101 unlet s:netrwmftgt s:netrwmftgt_islocal
8102 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008103 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008104 endif
8105 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008106" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8107 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008108" call Dret("s:NetrwMarkFileTgt : removed target")
8109 return
8110 else
8111 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008112" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008113 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008114
8115 else
8116 " get word under cursor.
8117 " * If directory, use it for the target.
8118 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008119" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008120 let curword= s:NetrwGetWord()
8121 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008122 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008123 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008124" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008125 elseif !a:islocal && tgtdir =~ '/$'
8126 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008127" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008128 else
8129 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008130" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008131 endif
8132 endif
8133 if a:islocal
8134 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8135 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008136" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008137 endif
8138 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008139 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008140 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8141 endif
8142 let s:netrwmftgt_islocal= a:islocal
8143
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008144 " need to do refresh so that the banner will be updated
8145 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008146 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008147" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008148 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008150" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008151 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008152 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8153 else
8154 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8155 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008156" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8157 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008158 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008159 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008160 endif
8161
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008162" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8163" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008164" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8165endfun
8166
8167" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008168" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8169fun! s:NetrwGetCurdir(islocal)
8170" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8171
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008172 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008173 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8174" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8175 elseif !exists("b:netrw_curdir")
8176 let b:netrw_curdir= getcwd()
8177" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8178 endif
8179
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008180" call Decho("b:netrw_curdir<".b:netrw_curdir."> ".((b:netrw_curdir !~ '\<\a\{3,}://')? "does not match" : "matches")." url pattern",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008181 if b:netrw_curdir !~ '\<\a\{3,}://'
8182 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008183" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008184 if g:netrw_keepdir == 0
8185 call s:NetrwLcd(curdir)
8186 endif
8187 endif
8188
8189" call Dret("s:NetrwGetCurdir <".curdir.">")
8190 return b:netrw_curdir
8191endfun
8192
8193" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008194" s:NetrwOpenFile: query user for a filename and open it {{{2
8195fun! s:NetrwOpenFile(islocal)
8196" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008197 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008198 call inputsave()
8199 let fname= input("Enter filename: ")
8200 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008201" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8202
8203 " determine if Lexplore is in use
8204 if exists("t:netrw_lexbufnr")
8205 " check if t:netrw_lexbufnr refers to a netrw window
8206" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8207 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8208 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8209" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8210 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8211 exe "NetrwKeepj e ".fnameescape(fname)
8212 let @@= ykeep
8213" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8214 endif
8215 endif
8216
8217 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008218 if fname !~ '[/\\]'
8219 if exists("b:netrw_curdir")
8220 if exists("g:netrw_quiet")
8221 let netrw_quiet_keep = g:netrw_quiet
8222 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008223 let g:netrw_quiet = 1
8224 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008225 let s:rexposn_{bufnr("%")}= winsaveview()
8226" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008227 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008228 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008229 else
8230 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8231 endif
8232 if exists("netrw_quiet_keep")
8233 let g:netrw_quiet= netrw_quiet_keep
8234 else
8235 unlet g:netrw_quiet
8236 endif
8237 endif
8238 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008239 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008240 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008241 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008242" call Dret("s:NetrwOpenFile")
8243endfun
8244
8245" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008246" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8247" For the mapping to this function be made via
8248" netrwPlugin, you'll need to have had
8249" g:netrw_usetab set to non-zero.
8250fun! netrw#Shrink()
8251" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8252 let curwin = winnr()
8253 let wiwkeep = &wiw
8254 set wiw=1
8255
8256 if &ft == "netrw"
8257 if winwidth(0) > g:netrw_wiw
8258 let t:netrw_winwidth= winwidth(0)
8259 exe "vert resize ".g:netrw_wiw
8260 wincmd l
8261 if winnr() == curwin
8262 wincmd h
8263 endif
8264" call Decho("vert resize 0",'~'.expand("<slnum>"))
8265 else
8266 exe "vert resize ".t:netrw_winwidth
8267" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8268 endif
8269
8270 elseif exists("t:netrw_lexbufnr")
8271 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8272 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8273 let t:netrw_winwidth= winwidth(0)
8274 exe "vert resize ".g:netrw_wiw
8275 wincmd l
8276 if winnr() == curwin
8277 wincmd h
8278 endif
8279" call Decho("vert resize 0",'~'.expand("<slnum>"))
8280 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8281 exe "vert resize ".t:netrw_winwidth
8282" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008283 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008284 call netrw#Lexplore(0,0)
8285 endif
8286
8287 else
8288 call netrw#Lexplore(0,0)
8289 endif
8290 let wiw= wiwkeep
8291
8292" call Dret("netrw#Shrink")
8293endfun
8294
8295" ---------------------------------------------------------------------
8296" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8297fun! s:NetSortSequence(islocal)
8298" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8299
8300 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008301 let svpos= winsaveview()
8302" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008303 call inputsave()
8304 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8305 call inputrestore()
8306
8307 " refresh the listing
8308 let g:netrw_sort_sequence= newsortseq
8309 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008310" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8311 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008312 let @@= ykeep
8313
8314" call Dret("NetSortSequence")
8315endfun
8316
8317" ---------------------------------------------------------------------
8318" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8319" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008320" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008321fun! s:NetrwUnmarkList(curbufnr,curdir)
8322" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8323
8324 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008325 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008326 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8327 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8328 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8329 call remove(s:netrwmarkfilelist,idx) " remove from global list
8330 endfor
8331 if s:netrwmarkfilelist == []
8332 unlet s:netrwmarkfilelist
8333 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008334
Bram Moolenaar446cb832008-06-24 21:56:24 +00008335 " getting rid of the local marked-file lists is easy
8336 unlet s:netrwmarkfilelist_{a:curbufnr}
8337 endif
8338 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8339 unlet s:netrwmarkfilemtch_{a:curbufnr}
8340 endif
8341 2match none
8342" call Dret("s:NetrwUnmarkList")
8343endfun
8344
8345" ---------------------------------------------------------------------
8346" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8347fun! s:NetrwUnmarkAll()
8348" call Dfunc("s:NetrwUnmarkAll()")
8349 if exists("s:netrwmarkfilelist")
8350 unlet s:netrwmarkfilelist
8351 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008352 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008353 2match none
8354" call Dret("s:NetrwUnmarkAll")
8355endfun
8356
8357" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008358" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008359fun! s:NetrwUnmarkAll2()
8360" call Dfunc("s:NetrwUnmarkAll2()")
8361 redir => netrwmarkfilelist_let
8362 let
8363 redir END
8364 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008365 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008366 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8367 for flist in netrwmarkfilelist_list
8368 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8369 unlet s:netrwmarkfilelist_{curbufnr}
8370 unlet s:netrwmarkfilemtch_{curbufnr}
8371 endfor
8372" call Dret("s:NetrwUnmarkAll2")
8373endfun
8374
8375" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008376" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8377"
8378" Marked files are in two types of lists:
8379" s:netrwmarkfilelist -- holds complete paths to all marked files
8380" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8381"
8382" Marked files suitable for use with 2match are in:
8383" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008384fun! s:NetrwUnMarkFile(islocal)
8385" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008386 let svpos = winsaveview()
8387" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008388 let curbufnr = bufnr("%")
8389
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008390 " unmark marked file list
8391 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8392 if exists("s:netrwmarkfilelist")
8393" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008394 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008395 endif
8396
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008397 let ibuf= 1
8398 while ibuf < bufnr("$")
8399 if exists("s:netrwmarkfilelist_".ibuf)
8400 unlet s:netrwmarkfilelist_{ibuf}
8401 unlet s:netrwmarkfilemtch_{ibuf}
8402 endif
8403 let ibuf = ibuf + 1
8404 endwhile
8405 2match none
8406
Bram Moolenaar446cb832008-06-24 21:56:24 +00008407" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008408"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8409call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008410" call Dret("s:NetrwUnMarkFile")
8411endfun
8412
8413" ---------------------------------------------------------------------
8414" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8415fun! s:NetrwMenu(domenu)
8416
8417 if !exists("g:NetrwMenuPriority")
8418 let g:NetrwMenuPriority= 80
8419 endif
8420
Bram Moolenaaradc21822011-04-01 18:03:16 +02008421 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008422" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8423
8424 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008425" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008426 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008427 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8428 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8429 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8430 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8431 if g:netrw_dirhistmax > 0
8432 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8433 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8434 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8435 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8436 else
8437 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8438 endif
8439 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8440 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8441 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8442 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8443 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8444 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8445 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8446 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8447 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8448 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8449 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8450 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8451 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8452 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8453 exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008454 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Tab<tab>t t'
Bram Moolenaarff034192013-04-24 18:51:19 +02008455 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8456 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8457 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8458 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8459 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8460 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8461 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8462 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8463 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8464 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8465 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8466 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8467 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8468 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8469 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8470 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8471 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8472 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8473 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8474 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8475 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8476 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8477 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8478 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8479 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8480 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8481 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8482 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8483 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8484 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.1 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Show\ All<tab>a :let g:netrw_hide=0<cr><c-L>'
8485 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.3 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Normal<tab>a :let g:netrw_hide=1<cr><c-L>'
8486 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.2 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Hidden\ Only<tab>a :let g:netrw_hide=2<cr><c-L>'
8487 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8488 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.1 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Name<tab>s :let g:netrw_sort_by="name"<cr><c-L>'
8489 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.2 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Time<tab>s :let g:netrw_sort_by="time"<cr><c-L>'
8490 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Size<tab>s :let g:netrw_sort_by="size"<cr><c-L>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008491 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Exten<tab>s :let g:netrw_sort_by="exten"<cr><c-L>'
Bram Moolenaarff034192013-04-24 18:51:19 +02008492 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008494 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008495 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8496 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008497
8498 elseif !a:domenu
8499 let s:netrwcnt = 0
8500 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008501 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008502 exe curwin."wincmd w"
8503
8504 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008505" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008506 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008507" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008508 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008509 endif
8510 endif
8511" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008512 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008513 endif
8514
8515endfun
8516
8517" ---------------------------------------------------------------------
8518" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8519" Used by the O maps (as <SID>NetrwObtain())
8520fun! s:NetrwObtain(islocal)
8521" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8522
Bram Moolenaar97d62492012-11-15 21:28:22 +01008523 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008524 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008525 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008526 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008527 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8528 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008529 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008530 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008531 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008532
8533" call Dret("NetrwObtain")
8534endfun
8535
8536" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008537" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8538" If there's only one window, then the window will first be split.
8539" Returns:
8540" choice = 0 : didn't have to choose
8541" choice = 1 : saved modified file in window first
8542" choice = 2 : didn't save modified file, opened window
8543" choice = 3 : cancel open
8544fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008545" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008546
Bram Moolenaar97d62492012-11-15 21:28:22 +01008547 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008548 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008549 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008550" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008551
8552 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008553 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008554 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008555" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8556" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8557 let curword = s:NetrwGetWord()
8558 let choice = 0
8559 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8560" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008561 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008562" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008563 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008564" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008565" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008566" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008567
Bram Moolenaar8d043172014-01-23 14:24:41 +01008568 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008569 if lastwinnr == 1
8570 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008571" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008572 " g:netrw_preview=0: preview window shown in a horizontally split window
8573 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008574 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008575 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008576 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008577" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008578 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008579 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008580 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008581 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008582" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008583 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008584 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008585 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008586" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008587
8588 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008589" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008590 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008591" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008592 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008593" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008594 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008595" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008596 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008597" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008598" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008599" call Decho("COMBAK#12: mod=".&mod)
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008600
Bram Moolenaar71badf92023-04-22 22:40:14 +01008601 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8602 " whoops -- user trying to open file in the Lexplore window.
8603 " Use Lexplore's opening-file window instead.
8604" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8605" exe g:netrw_chgwin."wincmd w"
8606 wincmd p
8607 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8608 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008609
8610 " prevwinnr: the window number of the "prev" window
8611 " prevbufnr: the buffer number of the buffer in the "prev" window
8612 " bnrcnt : the qty of windows open on the "prev" buffer
8613 let prevwinnr = winnr()
8614 let prevbufnr = bufnr("%")
8615 let prevbufname = bufname("%")
8616 let prevmod = &mod
8617 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008618" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008619 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008620" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008621" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008622
8623 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008624 " and it doesn't appear in any other extant window, then ask the
8625 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008626 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008627" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008628 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008629" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008630 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008631" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008632
8633 if bnrcnt == 1 && &hidden == 0
8634 " only one copy of the modified buffer in a window, and
8635 " hidden not set, so overwriting will lose the modified file. Ask first...
8636 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008637" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008638 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008639" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640
8641 if choice == 1
8642 " Yes -- write file & then browse
8643 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008644 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008646 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008647 exe origwin."wincmd w"
8648 let &ei = eikeep
8649 let @@ = ykeep
8650" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008651 return choice
8652 endif
8653
8654 elseif choice == 2
8655 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008656" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008657 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008658
8659 else
8660 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008661" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008662 exe origwin."wincmd w"
8663 let &ei= eikeep
8664 let @@ = ykeep
8665" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008666 return choice
8667 endif
8668 endif
8669 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008670 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008671 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008672" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008673
8674 " restore b:netrw_curdir (window split/enew may have lost it)
8675 let b:netrw_curdir= curdir
8676 if a:islocal < 2
8677 if a:islocal
8678 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8679 else
8680 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8681 endif
8682 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008683 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008684" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008685 return choice
8686endfun
8687
8688" ---------------------------------------------------------------------
8689" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8690" Always assumed to be local -> remote
8691" call s:NetrwUpload(filename, target)
8692" call s:NetrwUpload(filename, target, fromdirectory)
8693fun! s:NetrwUpload(fname,tgt,...)
8694" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8695
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008696 if a:tgt =~ '^\a\{3,}://'
8697 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008698 else
8699 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8700 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008701" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008702
8703 if a:0 > 0
8704 let fromdir= a:1
8705 else
8706 let fromdir= getcwd()
8707 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008708" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709
8710 if type(a:fname) == 1
8711 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008712" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008713 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008714" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8715 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8716" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008717 if a:tgt =~ '/$'
8718 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008719" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008720 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008721 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008722" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008723 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008724" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008725 endif
8726 q!
8727
8728 elseif type(a:fname) == 3
8729 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008730" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008731 let curdir= getcwd()
8732 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008733 if s:NetrwLcd(fromdir)
8734" call Dret("s:NetrwUpload : lcd failure")
8735 return
8736 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008737 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008738 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008739 if exists("g:netrw_port") && g:netrw_port != ""
8740 let useport= " ".g:netrw_scpport." ".g:netrw_port
8741 else
8742 let useport= ""
8743 endif
8744 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8745 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008746 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".args." ".s:ShellEscape(machine.":".tgt,1))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008747 if s:NetrwLcd(curdir)
8748" call Dret("s:NetrwUpload : lcd failure")
8749 return
8750 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008751
8752 elseif a:tgt =~ '^ftp:'
8753 call s:NetrwMethod(a:tgt)
8754
8755 if b:netrw_method == 2
8756 " handle uploading a list of files via ftp+.netrc
8757 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008758 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008759" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008760
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008761 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008762" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008763
8764 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008765 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008766" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008767 endif
8768
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008769 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008770" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008771
Bram Moolenaaradc21822011-04-01 18:03:16 +02008772 if tgtdir == ""
8773 let tgtdir= '/'
8774 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008775 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008776" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008777
8778 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008779 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8780" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008781 endfor
8782
8783 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008784 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008785 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008786" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8787 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008788 endif
8789 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008790 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008791 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8793 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8794 else
8795 bw!|q
8796 endif
8797
8798 elseif b:netrw_method == 3
8799 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8800 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008801 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008802 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008803 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008804
8805 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008806 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008807" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008808 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008809 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008810" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008811 endif
8812
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008813 if exists("g:netrw_uid") && g:netrw_uid != ""
8814 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008815 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008816" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008817 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008818 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008819 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008820" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008821 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008822 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008824 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008825 endif
8826
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008827 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008828" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008829
8830 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008831 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008832" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008833 endif
8834
8835 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008836 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008837" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008838 endif
8839
8840 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008841 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008842" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008843 endfor
8844
8845 " perform ftp:
8846 " -i : turns off interactive prompting from ftp
8847 " -n unix : DON'T use <.netrc>, even though it exists
8848 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008849 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008850 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008851 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008852 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008853 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008854 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8855 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008856 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008857 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8858 let &debug = debugkeep
8859 let mod = 1
8860 else
8861 bw!|q
8862 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008863 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008864" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008865 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008866 endif
8867 else
8868 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8869 endif
8870 endif
8871
8872" call Dret("s:NetrwUpload")
8873endfun
8874
8875" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008876" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008877fun! s:NetrwPreview(path) range
8878" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008879" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8880" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008881 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008882 NetrwKeepj call s:NetrwOptionsSave("s:")
8883 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8884 NetrwKeepj call s:NetrwOptionsSafe(1)
8885 else
8886 NetrwKeepj call s:NetrwOptionsSafe(0)
8887 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008888 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008889" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008890 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008891" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8892 if g:netrw_preview
8893 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008894 let pvhkeep = &pvh
8895 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8896 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008897" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8898 else
8899 " horizontal split
8900 let pvhkeep = &pvh
8901 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8902 let &pvh = winheight(0) - winsz
8903" call Decho("!g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008904 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008905 " g:netrw_preview g:netrw_alto
8906 " 1 : vert 1: top -- preview window is vertically split off and on the left
8907 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8908 " 0 : 1: top -- preview window is horizontally split off and on the top
8909 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8910 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008911 " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowseCheck() check via
Bram Moolenaar85850f32019-07-19 22:05:51 +02008912 " the BufEnter event set up in netrwPlugin.vim
8913" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8914 let eikeep = &ei
8915 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008916 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008917 let &ei= eikeep
8918" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008919 if exists("pvhkeep")
8920 let &pvh= pvhkeep
8921 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008922 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008923 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008924 endif
8925 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008926 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, to preview your vim needs the quickfix feature compiled in",39)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008927 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008928 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008929 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930" call Dret("NetrwPreview")
8931endfun
8932
8933" ---------------------------------------------------------------------
8934" s:NetrwRefresh: {{{2
8935fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008936" call Dfunc("s:NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") g:netrw_hide=".g:netrw_hide." g:netrw_sort_direction=".g:netrw_sort_direction)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008937 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008938 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008939" call Decho("setl ma noro",'~'.expand("<slnum>"))
8940" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008941 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008942 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8943 if !exists("w:netrw_treetop")
8944 if exists("b:netrw_curdir")
8945 let w:netrw_treetop= b:netrw_curdir
8946 else
8947 let w:netrw_treetop= getcwd()
8948 endif
8949 endif
8950 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8951 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008952
8953 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008954 let screenposn = winsaveview()
8955" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008956
8957" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8958" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8959 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008960 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008961 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008962 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008963 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008964 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008965
8966 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008967" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8968 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008969
8970 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008971 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8972 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8973" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8974 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8975 else
8976" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8977 2match none
8978 endif
8979 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008980
Bram Moolenaar97d62492012-11-15 21:28:22 +01008981" restore
8982 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008983" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008984endfun
8985
8986" ---------------------------------------------------------------------
8987" s:NetrwRefreshDir: refreshes a directory by name {{{2
8988" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008989" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008990fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008991" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008992 if g:netrw_fastbrowse == 0
8993 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008994" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008995 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008996" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008997
8998 if tgtwin > 0
8999 " tgtwin is being displayed, so refresh it
9000 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009001" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009002 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009003 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009004 exe curwin."wincmd w"
9005
9006 elseif bufnr(a:dirname) > 0
9007 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009008" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9009 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009010 endif
9011
9012 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009013" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009014 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009015 endif
9016" call Dret("s:NetrwRefreshDir")
9017endfun
9018
9019" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009020" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9021" window number to do its editing in.
9022" Supports [count]C where the count, if present, is used to specify
9023" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009024fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009025" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009026 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009027" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009028 if a:1 == "" " :NetrwC win#
9029 let g:netrw_chgwin= winnr()
9030 else " :NetrwC
9031 let g:netrw_chgwin= a:1
9032 endif
9033 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009034 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009035 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009036 let g:netrw_chgwin= winnr()
9037 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009038 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009039" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009040endfun
9041
9042" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009043" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9044" What this function does is to compute a priority for the patterns
9045" in the g:netrw_sort_sequence. It applies a substitute to any
9046" "files" that satisfy each pattern, putting the priority / in
9047" front. An "*" pattern handles the default priority.
9048fun! s:NetrwSetSort()
9049" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009050 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009051 if w:netrw_liststyle == s:LONGLIST
9052 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9053 else
9054 let seqlist = g:netrw_sort_sequence
9055 endif
9056 " sanity check -- insure that * appears somewhere
9057 if seqlist == ""
9058 let seqlist= '*'
9059 elseif seqlist !~ '\*'
9060 let seqlist= seqlist.',*'
9061 endif
9062 let priority = 1
9063 while seqlist != ""
9064 if seqlist =~ ','
9065 let seq = substitute(seqlist,',.*$','','e')
9066 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9067 else
9068 let seq = seqlist
9069 let seqlist = ""
9070 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009072 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009073 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009074 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009075 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009076 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009077 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009078" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079
9080 " sanity check
9081 if w:netrw_bannercnt > line("$")
9082 " apparently no files were left after a Hiding pattern was used
9083" call Dret("SetSort : no files left after hiding")
9084 return
9085 endif
9086 if seq == '*'
9087 let starpriority= spriority
9088 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009089 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009090 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009091 " sometimes multiple sorting patterns will match the same file or directory.
9092 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009093 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9094 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009095 endif
9096 let priority = priority + 1
9097 endwhile
9098 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009099 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9100 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009101 endif
9102
9103 " Following line associated with priority -- items that satisfy a priority
9104 " pattern get prefixed by ###/ which permits easy sorting by priority.
9105 " Sometimes files can satisfy multiple priority patterns -- only the latest
9106 " priority pattern needs to be retained. So, at this point, these excess
9107 " priority prefixes need to be removed, but not directories that happen to
9108 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009109 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9110 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009111 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009112
9113" call Dret("SetSort")
9114endfun
9115
Bram Moolenaarff034192013-04-24 18:51:19 +02009116" ---------------------------------------------------------------------
9117" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9118" Implements [count]Tb (bookhist<b>)
9119" [count]Th (bookhist<h>)
9120" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009121fun! s:NetrwSetTgt(islocal,bookhist,choice)
9122" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009123
9124 if a:bookhist == 'b'
9125 " supports choosing a bookmark as a target using a qb-generated list
9126 let choice= a:choice - 1
9127 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009128 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009129 else
9130 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9131 endif
9132
9133 elseif a:bookhist == 'h'
9134 " supports choosing a history stack entry as a target using a qb-generated list
9135 let choice= (a:choice % g:netrw_dirhistmax) + 1
9136 if exists("g:netrw_dirhist_".choice)
9137 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009138 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009139 else
9140 echomsg "Sorry, history#".a:choice." not available!"
9141 endif
9142 endif
9143
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009144 " refresh the display
9145 if !exists("b:netrw_curdir")
9146 let b:netrw_curdir= getcwd()
9147 endif
9148 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9149
Bram Moolenaarff034192013-04-24 18:51:19 +02009150" call Dret("s:NetrwSetTgt")
9151endfun
9152
Bram Moolenaar446cb832008-06-24 21:56:24 +00009153" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009154" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009155fun! s:NetrwSortStyle(islocal)
9156" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009157 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009158 let svpos= winsaveview()
9159" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009160
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009161 let g:netrw_sort_by= (g:netrw_sort_by =~# '^n')? 'time' : (g:netrw_sort_by =~# '^t')? 'size' : (g:netrw_sort_by =~# '^siz')? 'exten' : 'name'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009162 NetrwKeepj norm! 0
9163 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009164" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9165 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009166
9167" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9168endfun
9169
9170" ---------------------------------------------------------------------
9171" s:NetrwSplit: mode {{{2
9172" =0 : net and o
9173" =1 : net and t
9174" =2 : net and v
9175" =3 : local and o
9176" =4 : local and t
9177" =5 : local and v
9178fun! s:NetrwSplit(mode)
9179" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9180
Bram Moolenaar97d62492012-11-15 21:28:22 +01009181 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009182 call s:SaveWinVars()
9183
9184 if a:mode == 0
9185 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009186 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009187 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009188" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009189 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009190 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009191 NetrwKeepj call s:RestoreWinVars()
9192 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009193 unlet s:didsplit
9194
9195 elseif a:mode == 1
9196 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009197 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009198" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009199 tabnew
9200 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009201 NetrwKeepj call s:RestoreWinVars()
9202 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009203 unlet s:didsplit
9204
9205 elseif a:mode == 2
9206 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009207 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009208 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009209" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009210 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009211 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009212 NetrwKeepj call s:RestoreWinVars()
9213 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009214 unlet s:didsplit
9215
9216 elseif a:mode == 3
9217 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009218 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009219 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009220" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009221 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009222 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009223 NetrwKeepj call s:RestoreWinVars()
9224 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009225 unlet s:didsplit
9226
9227 elseif a:mode == 4
9228 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009229 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009230 let eikeep = &ei
9231 let netrw_winnr = winnr()
9232 let netrw_line = line(".")
9233 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009234 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009235 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009236 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009237 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9238 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009239 let &ei = eikeep
9240 let netrw_curdir = s:NetrwTreeDir(0)
9241" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009242 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009243 let b:netrw_curdir = netrw_curdir
9244 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009245 NetrwKeepj call s:RestoreWinVars()
9246 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009247 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009248 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009249 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9250 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009251 let &ei= eikeep
9252 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009253 unlet s:didsplit
9254
9255 elseif a:mode == 5
9256 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009257 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009258 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009259" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009260 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009261 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009262 NetrwKeepj call s:RestoreWinVars()
9263 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009264 unlet s:didsplit
9265
9266 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009267 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009268 endif
9269
Bram Moolenaar97d62492012-11-15 21:28:22 +01009270 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009271" call Dret("s:NetrwSplit")
9272endfun
9273
9274" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009275" s:NetrwTgtMenu: {{{2
9276fun! s:NetrwTgtMenu()
9277 if !exists("s:netrw_menucnt")
9278 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009279 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009280" call Dfunc("s:NetrwTgtMenu()")
9281
9282 " the following test assures that gvim is running, has menus available, and has menus enabled.
9283 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9284 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009285" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009286 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9287 endif
9288 if !exists("s:netrw_initbookhist")
9289 call s:NetrwBookHistRead()
9290 endif
9291
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009292 " try to cull duplicate entries
9293 let tgtdict={}
9294
Bram Moolenaarff034192013-04-24 18:51:19 +02009295 " target bookmarked places
9296 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009297" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009298 let cnt= 1
9299 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009300 if has_key(tgtdict,bmd)
9301 let cnt= cnt + 1
9302 continue
9303 endif
9304 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009305 let ebmd= escape(bmd,g:netrw_menu_escape)
9306 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009307" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009308 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.1.".cnt." ".g:NetrwTopLvlMenu.'Targets.'.ebmd." :call netrw#MakeTgt('".bmd."')\<cr>"
Bram Moolenaarff034192013-04-24 18:51:19 +02009309 let cnt= cnt + 1
9310 endfor
9311 endif
9312
9313 " target directory browsing history
9314 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009315" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009316 let histcnt = 1
9317 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009318 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009319 if exists("g:netrw_dirhist_{histcnt}")
9320 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009321 if has_key(tgtdict,histentry)
9322 let histcnt = histcnt + 1
9323 continue
9324 endif
9325 let tgtdict[histentry] = histcnt
9326 let ehistentry = escape(histentry,g:netrw_menu_escape)
9327" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009328 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.2.".priority." ".g:NetrwTopLvlMenu.'Targets.'.ehistentry." :call netrw#MakeTgt('".histentry."')\<cr>"
Bram Moolenaarff034192013-04-24 18:51:19 +02009329 endif
9330 let histcnt = histcnt + 1
9331 endwhile
9332 endif
9333 endif
9334" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009335endfun
9336
9337" ---------------------------------------------------------------------
9338" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9339" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009340fun! s:NetrwTreeDir(islocal)
9341" call Dfunc("s:NetrwTreeDir(islocal=".a:islocal.") getline(".line(".").")"."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009342" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009343" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9344" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9345" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009346" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009347
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009348 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009349 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009350" call Decho('s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early')
Bram Moolenaar8d043172014-01-23 14:24:41 +01009351 let treedir= s:treedir
9352 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009353 unlet s:prevwinopen
9354" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009355 return treedir
9356 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009357 if exists("s:prevwinopen")
9358 unlet s:prevwinopen
9359 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009360" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009361
Bram Moolenaar8d043172014-01-23 14:24:41 +01009362 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9363 let b:netrw_curdir= getcwd()
9364 endif
9365 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009366" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009367" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009368
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009369 let s:treecurpos= winsaveview()
9370" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009371" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009372
9373 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009374" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9375" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009376" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009377
9378 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009379 let curline= substitute(getline('.'),"\t -->.*$",'','')
9380 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009381" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009382 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009383" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9384 elseif curline =~ '@$'
9385" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009386 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009387" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009388 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009389" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009390 let treedir= ""
9391 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009392" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009393
9394 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009395" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9396" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009397" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009398 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009399" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009400 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009401" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9402 sil! NetrwKeepj %d _
9403" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009404 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009405" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009406" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009407 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009408" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009409
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009410" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009411" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009412" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009413
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009414 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9415" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9416" let newdir = w:netrw_treetop.'/'.potentialdir
9417" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9418" let treedir = s:NetrwTreePath(newdir)
9419" let w:netrw_treetop = newdir
9420" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9421" else
9422" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009423 if a:islocal && curline =~ '@$'
9424 if isdirectory(s:NetrwFile(potentialdir))
9425 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9426 let w:netrw_treetop = treedir
9427 endif
9428 else
9429 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9430 let treedir = s:NetrwTreePath(w:netrw_treetop)
9431 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009432 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009433" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009434
9435 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009436 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009437" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009438" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009439
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009440" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009441 return treedir
9442endfun
9443
9444" ---------------------------------------------------------------------
9445" s:NetrwTreeDisplay: recursive tree display {{{2
9446fun! s:NetrwTreeDisplay(dir,depth)
9447" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9448
9449 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009450 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009451
9452 " install ../ and shortdir
9453 if a:depth == ""
9454 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009455" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009456 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009457 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009458 if a:dir == w:netrw_treetop
9459 let shortdir= a:dir
9460 else
9461 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9462 endif
9463 call setline(line("$")+1,a:depth.shortdir)
9464 else
9465 let shortdir= substitute(a:dir,'^.*/','','e')
9466 call setline(line("$")+1,a:depth.shortdir.'/')
9467 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009468" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009469 " append a / to dir if its missing one
9470 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009471
9472 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009473 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009474" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009475
Bram Moolenaar85850f32019-07-19 22:05:51 +02009476 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9477 if g:netrw_hide == 1
9478 " hide given patterns
9479 let listhide= split(g:netrw_list_hide,',')
9480" call Decho("listhide=".string(listhide))
9481 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009482 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009483 endfor
9484
9485 elseif g:netrw_hide == 2
9486 " show given patterns (only)
9487 let listhide= split(g:netrw_list_hide,',')
9488" call Decho("listhide=".string(listhide))
9489 let entries=[]
9490 for entry in w:netrw_treedict[dir]
9491 for pat in listhide
9492 if entry =~ pat
9493 call add(entries,entry)
9494 break
9495 endif
9496 endfor
9497 endfor
9498 let w:netrw_treedict[dir]= entries
9499 endif
9500 if depth != ""
9501 " always remove "." and ".." entries when there's depth
9502 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9503 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9504 endif
9505
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009506" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009507 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009508 if dir =~ '/$'
9509 let direntry= substitute(dir.entry,'[@/]$','','e')
9510 else
9511 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9512 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009513" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009514 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009515" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009516 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009517 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009518" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9519 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9520 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9521" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009522 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009523 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009524" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009525 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009526 endif
9527 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009528" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009529
Bram Moolenaar446cb832008-06-24 21:56:24 +00009530" call Dret("NetrwTreeDisplay")
9531endfun
9532
9533" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009534" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9535fun! s:NetrwRefreshTreeDict(dir)
9536" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009537 if !exists("w:netrw_treedict")
9538" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9539 return
9540 endif
9541
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009542 for entry in w:netrw_treedict[a:dir]
9543 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9544" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9545
9546 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9547" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9548 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009549 let liststar = s:NetrwGlob(direntry,'*',1)
9550 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009551 let w:netrw_treedict[direntry] = liststar + listdotstar
9552" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9553
9554 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9555" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9556 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009557 let liststar = s:NetrwGlob(direntry.'/','*',1)
9558 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009559 let w:netrw_treedict[direntry]= liststar + listdotstar
9560" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9561
9562 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9563" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9564 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009565 let liststar = s:NetrwGlob(direntry.'/','*',1)
9566 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009567" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9568
9569 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009570" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009571 endif
9572 endfor
9573" call Dret("s:NetrwRefreshTreeDict")
9574endfun
9575
9576" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009577" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009578" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009579fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009580 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00009581
9582 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009583 if !exists("w:netrw_treetop")
9584 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009585 let s:netrw_treetop= w:netrw_treetop
Tom Benham4d618002024-10-31 10:47:23 +01009586 " use \V in case the directory contains specials chars like '$' or '~'
9587 elseif (w:netrw_treetop =~ ('^'.'\V'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop))
9588 \ || a:dirname !~ ('^'.'\V'.w:netrw_treetop)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009589 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009590 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009591 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009592 if exists("w:netrw_treetop")
9593 let s:netrw_treetop= w:netrw_treetop
9594 else
9595 let w:netrw_treetop= getcwd()
9596 let s:netrw_treetop= w:netrw_treetop
9597 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009598
Bram Moolenaar446cb832008-06-24 21:56:24 +00009599 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009600 " insure that we have a treedict, albeit empty
Bram Moolenaar446cb832008-06-24 21:56:24 +00009601 let w:netrw_treedict= {}
9602 endif
9603
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009604 " update the dictionary for the current directory
Christian Brabandta063b222024-11-07 14:30:30 +01009605 exe "sil! NetrwKeepj keepp ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009606 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009607 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009608
9609 " if past banner, record word
9610 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9611 let fname= expand("<cword>")
9612 else
9613 let fname= ""
9614 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009615
9616 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009617 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009618
9619 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9620 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009621 1d
9622 endwhile
9623
Bram Moolenaar13600302014-05-22 18:26:40 +02009624 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009625
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009626 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009627 endif
9628endfun
9629
9630" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009631" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009632" Normally, treetop is w:netrw_treetop, but a
9633" user of the function ( netrw#SetTreetop() )
9634" wipes that out prior to calling this function
9635fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009636" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9637 if line(".") < w:netrw_bannercnt + 2
9638 let treedir= a:treetop
9639 if treedir !~ '/$'
9640 let treedir= treedir.'/'
9641 endif
9642" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9643 return treedir
9644 endif
9645
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009646 let svpos = winsaveview()
9647" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009648 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009649" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009650 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009651" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9652 let curline= getline('.')
9653" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9654 if curline =~ '/$'
9655" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9656 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9657" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9658 elseif curline =~ '@\s\+-->'
9659" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9660 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9661 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9662" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009663 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009664" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009665 let treedir= ""
9666 endif
9667 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009668" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9669" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009670 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9671 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9672 let treedir= dirname.treedir
9673 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009674" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009675 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009676" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009677 if a:treetop =~ '/$'
9678 let treedir= a:treetop.treedir
9679 else
9680 let treedir= a:treetop.'/'.treedir
9681 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009682" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009683 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009684" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009685" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9686 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009687" call Dret("s:NetrwTreePath <".treedir.">")
9688 return treedir
9689endfun
9690
9691" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009692" s:NetrwWideListing: {{{2
9693fun! s:NetrwWideListing()
9694
9695 if w:netrw_liststyle == s:WIDELIST
9696" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9697 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009698 " cpf: characters per filename
9699 " fpl: filenames per line
9700 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009701 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009702 let dict={}
9703 " save the unnamed register and register 0-9 and a
9704 let dict.a=[getreg('a'), getregtype('a')]
9705 for i in range(0, 9)
9706 let dict[i] = [getreg(i), getregtype(i)]
9707 endfor
9708 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009709" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009710 let b:netrw_cpf= 0
9711 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009712 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009713 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9714 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009715 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009716 " restore stored registers
9717 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009718" call Dret("NetrwWideListing")
9719 return
9720 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009721 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009722 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009723" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009724
9725 " determine qty files per line (fpl)
9726 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9727 if w:netrw_fpl <= 0
9728 let w:netrw_fpl= 1
9729 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009730" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009731
9732 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009733 " fpc: files per column of wide listing
9734 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009735 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009736 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9737 let newcolstart = w:netrw_bannercnt + fpc
9738 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009739" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009740 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009741" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009742 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009743 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009744 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009745 while line("$") >= newcolstart
9746 if newcolend > line("$") | let newcolend= line("$") | endif
9747 let newcolqty= newcolend - newcolstart
9748 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009749 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009750 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009751 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009752 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009753 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009754 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009755 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009756 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009757 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009758 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009759" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009760 if @* != keepregstar | sil! let @* = keepregstar | endif
9761 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009762 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009763 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9764 NetrwKeepj call histdel("/",-1)
9765 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9766 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009767" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009768 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009769 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009770" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009771" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009772 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009773 else
9774 if hasmapto("w","n")
9775 sil! nunmap <buffer> w
9776 endif
9777 if hasmapto("b","n")
9778 sil! nunmap <buffer> b
9779 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009780 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009781endfun
9782
9783" ---------------------------------------------------------------------
9784" s:PerformListing: {{{2
9785fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009786" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9787" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009788" call Decho("settings: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (enter)"." ei<".&ei.">",'~'.expand("<slnum>"))
9789 sil! NetrwKeepj %d _
9790" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009791
Bram Moolenaar15146672011-10-20 22:22:38 +02009792 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009793" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009794 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009795
Bram Moolenaar85850f32019-07-19 22:05:51 +02009796 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009797 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009798" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009799
9800" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009801" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009802" endif " Decho
9803
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009804" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009805 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9806 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009807" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9808 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009809 endif
9810
9811 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009812 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009813
9814 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009815 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009816" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009817 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009818 if exists("g:netrw_pchk")
9819 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9820 " failure detections.
9821 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009822 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009823 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9824 endif
9825 if exists("g:netrw_pchk")
9826 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9827 else
9828 let curdir= b:netrw_curdir
9829 endif
9830 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9831 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9832 else
9833 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009834 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009835 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009836 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009837 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009838" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009839 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009840 let w:netrw_bannercnt= 1
9841 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009842" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9843" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009844
Bram Moolenaar85850f32019-07-19 22:05:51 +02009845 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009846 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009847 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009848 let sortby= sortby." reversed"
9849 endif
9850
9851 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009852 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009853" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009854 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009855" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009856 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009857 NetrwKeepj put ='\" Sorted by '.sortby
9858 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009859 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9860 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009861" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009862 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009863 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009864 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9865 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009866 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009867" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009868" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009869 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009870
Bram Moolenaar85850f32019-07-19 22:05:51 +02009871 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009872 if g:netrw_banner
9873 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009874" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009875 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009876 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009877 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009878 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009879 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009880 endif
9881 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009882 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009883" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009884 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009885 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009887
9888 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009889 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009890" call Decho("--handle hiding/showing in banner (g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009891 if g:netrw_list_hide != "" && g:netrw_hide
9892 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009893 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009894 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009895 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009896 endif
9897 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009898 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009899 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009900
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009901" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009902 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009903" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009904 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009905" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009906 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009907 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009908" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009909" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009910 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009911
9912 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009913 if g:netrw_banner
9914 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009915 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009916" call Decho("--w:netrw_bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009917" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009918" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009919 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009920
Bram Moolenaar446cb832008-06-24 21:56:24 +00009921 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009922" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009923 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009924 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009925 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009926 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009927 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009928" call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009929" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9930 return
9931 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009932 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009933
9934 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009935 if !exists("w:netrw_bannercnt")
9936 let w:netrw_bannercnt= 0
9937 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009938" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9939" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9940" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009941
Bram Moolenaar5c736222010-01-06 20:54:52 +01009942 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009943" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009944" call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009945 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009946 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009947 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009948 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009949" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009950
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009951 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009952 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009953" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009954 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009955
Bram Moolenaar5c736222010-01-06 20:54:52 +01009956 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009957" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009958 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009959 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009960 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009961 else
9962 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009963 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009964 endif
9965 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009966
Bram Moolenaar446cb832008-06-24 21:56:24 +00009967 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009968" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009969 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9970 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009971
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009972 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009973 " exten: sort by extension
9974 " The histdel(...,-1) calls remove the last search from the search history
9975" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009976 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9977 NetrwKeepj call histdel("/",-1)
9978 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9979 NetrwKeepj call histdel("/",-1)
9980 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9981 NetrwKeepj call histdel("/",-1)
9982 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9983" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009984 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009985 " normal direction sorting
9986 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9987 else
9988 " reverse direction sorting
9989 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9990 endif
9991 endif
9992 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9993 NetrwKeepj call histdel("/",-1)
9994
Bram Moolenaar446cb832008-06-24 21:56:24 +00009995 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009996 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009997" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009998 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009999" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010000 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010001 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010002" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010003 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010004 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010005" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010006 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10007 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010008 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010009 endif
10010
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010011 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010012" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010013 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010014 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010015 call histdel("/",-1)
10016 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010017 endif
10018 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010019" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010020
10021 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010022" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10023" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010024 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010025" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010026 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010027" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#3)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010028
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010029 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010030 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010031" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Christian Brabandta063b222024-11-07 14:30:30 +010010032 sil! keepp g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010033 endif
10034
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010035 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010036 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010037" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10038 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010039 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010040" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10041 else
10042" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10043" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10044" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10045" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010046 endif
10047
10048 " record previous current directory
10049 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010050" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010051
10052 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010053" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10054" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#4)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010055 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010056" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#5)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010057 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010058" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#6)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010059
10060 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010061" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010062 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010063" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#7)",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010064 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010065" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010066 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10067 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010068" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010069" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010070
Bram Moolenaar8d043172014-01-23 14:24:41 +010010071 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010072" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10073" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#8)",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010074" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10075 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010076 unlet s:treecurpos
10077 endif
10078
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010079" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (return)",'~'.expand("<slnum>"))
10080" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010081" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10082endfun
10083
10084" ---------------------------------------------------------------------
10085" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010086fun! s:SetupNetrwStatusLine(statline)
10087" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10088
10089 if !exists("s:netrw_setup_statline")
10090 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010091" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010092
10093 if !exists("s:netrw_users_stl")
10094 let s:netrw_users_stl= &stl
10095 endif
10096 if !exists("s:netrw_users_ls")
10097 let s:netrw_users_ls= &laststatus
10098 endif
10099
10100 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010101 let dict={}
10102 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010103 redir @a
10104 try
10105 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010106 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010107 if &bg == "dark"
10108 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10109 else
10110 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10111 endif
10112 endtry
10113 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010114 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010115 endif
10116
10117 " set up status line (may use User9 highlighting)
10118 " insure that windows have a statusline
10119 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010120 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010121 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010122" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010123 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010124
10125" call Dret("SetupNetrwStatusLine : stl=".&stl)
10126endfun
10127
Bram Moolenaar85850f32019-07-19 22:05:51 +020010128" =========================================
10129" Remote Directory Browsing Support: {{{1
10130" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010131
10132" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010133" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10134" This function assumes that a long listing will be received. Size, time,
10135" and reverse sorts will be requested of the server but not otherwise
10136" enforced here.
10137fun! s:NetrwRemoteFtpCmd(path,listcmd)
10138" call Dfunc("NetrwRemoteFtpCmd(path<".a:path."> listcmd<".a:listcmd.">) w:netrw_method=".(exists("w:netrw_method")? w:netrw_method : (exists("b:netrw_method")? b:netrw_method : "???")))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010139" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010140 " sanity check: {{{3
10141 if !exists("w:netrw_method")
10142 if exists("b:netrw_method")
10143 let w:netrw_method= b:netrw_method
10144 else
10145 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10146" call Dret("NetrwRemoteFtpCmd")
10147 return
10148 endif
10149 endif
10150
10151 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10152 let ffkeep= &ff
10153 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010154" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010155
10156 " clear off any older non-banner lines " {{{3
10157 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010158" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10159 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010160
10161 ".........................................
10162 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10163 " ftp + <.netrc>: Method #2
10164 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010165 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010166 endif
10167 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010168 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010169" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010170 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010171 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010172" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010173 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010174" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1),'~'.expand("<slnum>"))
10175 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010176 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010177" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10178 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010179 endif
10180
10181 ".........................................
10182 elseif w:netrw_method == 3 " {{{3
10183 " ftp + machine,id,passwd,filename: Method #3
10184 setl ff=unix
10185 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010186 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010187 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010188 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010189 endif
10190
10191 " handle userid and password
10192 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010193" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010194 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10195 call NetUserPass("ftp:".host)
10196 endif
10197 if exists("g:netrw_uid") && g:netrw_uid != ""
10198 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010199 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010200 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010201 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010202 endif
10203 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010204 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010205 endif
10206 endif
10207
10208 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010209 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010210 endif
10211 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010212 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010213" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010214 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010215 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010216
10217 " perform ftp:
10218 " -i : turns off interactive prompting from ftp
10219 " -n unix : DON'T use <.netrc>, even though it exists
10220 " -n win32: quit being obnoxious about password
10221 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010222" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010223 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010224" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010225" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10226" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010227 endif
10228
10229 ".........................................
10230 elseif w:netrw_method == 9 " {{{3
10231 " sftp username@machine: Method #9
10232 " s:netrw_sftp_cmd
10233 setl ff=unix
10234
10235 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010236 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010237" call Dret("NetrwRemoteFtpCmd")
10238 return
10239
10240 ".........................................
10241 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010242 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010243 endif
10244
10245 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010246 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010247 sil! NetrwKeepj %s/\r$//e
10248 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010249 endif
10250 if a:listcmd == "dir"
10251 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010252 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10253 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10254 NetrwKeepj call histdel("/",-1)
10255 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010256 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010257 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10258 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010259 endif
10260 endif
10261
10262 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10263 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010264 exe 'NetrwKeepj '.w:netrw_bannercnt
10265 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010266 endif
10267 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010268 exe 'NetrwKeepj '.w:netrw_bannercnt
10269 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010270 endif
10271
10272 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010273 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010274" call Dret("NetrwRemoteFtpCmd")
10275endfun
10276
10277" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010278" s:NetrwRemoteListing: {{{2
10279fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010280" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010281
Bram Moolenaara6878372014-03-22 21:02:50 +010010282 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10283 let w:netrw_bannercnt= s:bannercnt
10284 endif
10285 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010286 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010287 endif
10288
Bram Moolenaar446cb832008-06-24 21:56:24 +000010289 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010290
Bram Moolenaar446cb832008-06-24 21:56:24 +000010291 " sanity check:
10292 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010293" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010294 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010295" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010296 if !exists("g:netrw_quiet")
10297 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10298 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010299 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010300" call Dret("s:NetrwRemoteListing -1")
10301 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010302 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010303
Bram Moolenaar8d043172014-01-23 14:24:41 +010010304 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010305" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010306 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010307 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010308 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your g:netrw_list_cmd is empty; perhaps ".g:netrw_ssh_cmd." is not executable on your system",47)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010309 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010310 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ".g:netrw_list_cmd,19)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010311 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010312 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010313
Bram Moolenaar85850f32019-07-19 22:05:51 +020010314 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010315" call Dret("s:NetrwRemoteListing -1")
10316 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010317 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010318" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010319
Bram Moolenaar446cb832008-06-24 21:56:24 +000010320 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010321" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010322 let w:netrw_method= b:netrw_method
10323 endif
10324
Bram Moolenaar13600302014-05-22 18:26:40 +020010325 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010326 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010327" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010328 let s:method = "ftp"
10329 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010330 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010331 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010332 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010333 let listcmd= g:netrw_ftp_sizelist_cmd
10334 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010335" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010336 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010337" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010338
Bram Moolenaara6878372014-03-22 21:02:50 +010010339 " report on missing file or directory messages
10340 if search('[Nn]o such file or directory\|Failed to change directory')
10341 let mesg= getline(".")
10342 if exists("w:netrw_bannercnt")
10343 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010344 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010345 setl noma
10346 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010347 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010348 call netrw#ErrorMsg(s:WARNING,mesg,96)
10349" call Dret("s:NetrwRemoteListing : -1")
10350 return -1
10351 endif
10352
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010353 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010354 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010355" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010356 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010357
10358 " cleanup
10359 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010360 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10361 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010362 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010363 sil! NetrwKeepj %s/\r$//e
10364 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010365
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010366 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010367 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010368 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010369 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010370" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010371 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010372" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010373 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010374 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010375 exe "sil! NetrwKeepj ".line1
10376 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010377
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010378" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010379 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010380" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010381 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10382 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010384" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010385 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10386 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10387 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10388 NetrwKeepj call histdel("/",-1)
10389 NetrwKeepj call histdel("/",-1)
10390 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010391 endif
10392 endif
10393
Bram Moolenaar13600302014-05-22 18:26:40 +020010394 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010395 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010396" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010398" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010399 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010400" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10401 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010402 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010403 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10404 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10405 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10406 NetrwKeepj call histdel("/",-1)
10407 NetrwKeepj call histdel("/",-1)
10408 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010409 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010410 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10411 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010412 endif
10413 else
10414 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010415" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010416 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010417 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010418" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10419 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10420" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010421 endif
10422 endif
10423
10424 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010425 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010426" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010427 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10428 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010429 endif
10430 endif
10431
10432 if w:netrw_liststyle == s:LONGLIST
10433 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010434" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010435
10436 if s:method == "ftp"
10437 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010438 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010439 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010440 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010441 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010442 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010443 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010444 sil! NetrwKeepj 1
10445 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010446 let line2= line(".")
10447 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010448 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010449 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010450 endif
10451 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010452 exe "sil! NetrwKeepj ".line1
10453 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010454 endif
10455
10456 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010457" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010458 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+\)\(\w.*\)$/\2\t\1/'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010460" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010461 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010462 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010463 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10464 NetrwKeepj call histdel("/",-1)
10465 NetrwKeepj call histdel("/",-1)
10466 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010467 endif
10468 endif
10469
10470" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010471" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010472" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010473
10474" call Dret("s:NetrwRemoteListing 0")
10475 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010476endfun
10477
Bram Moolenaar446cb832008-06-24 21:56:24 +000010478" ---------------------------------------------------------------------
10479" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10480fun! s:NetrwRemoteRm(usrhost,path) range
10481" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010482" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010483 let svpos= winsaveview()
10484" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485
10486 let all= 0
10487 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10488 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010489" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010490 for fname in s:netrwmarkfilelist_{bufnr("%")}
10491 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010492 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010494 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010495 let all= 1
10496 endif
10497 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010498 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010499
10500 else
10501 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010502" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010503
10504 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010505 let keepsol = &l:sol
10506 setl nosol
10507 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010508
10509 " remove multiple files and directories
10510 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010511 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010512 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010513 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010515 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010516 let all= 1
10517 endif
10518 let ctr= ctr + 1
10519 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010520 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010521 endif
10522
10523 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010524" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010525 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010526" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10527 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010528
10529" call Dret("s:NetrwRemoteRm")
10530endfun
10531
10532" ---------------------------------------------------------------------
10533" s:NetrwRemoteRmFile: {{{2
10534fun! s:NetrwRemoteRmFile(path,rmfile,all)
10535" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10536
10537 let all= a:all
10538 let ok = ""
10539
10540 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10541 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010542" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010543 if !all
10544 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010545" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010546 call inputsave()
10547 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10548 call inputrestore()
10549 echohl NONE
10550 if ok == ""
10551 let ok="no"
10552 endif
10553 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010554 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010555 let all= 1
10556 endif
10557 endif
10558
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010559 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010560" call Decho("case all=".all." or ok<".ok.">".(exists("w:netrw_method")? ': netrw_method='.w:netrw_method : ""),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010561 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010562" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010563 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010564 if path =~ '^\a\{3,}://'
10565 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010566 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010567 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010568 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10569 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010570" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010571 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010572" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010574 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575 let ok="q"
10576 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010577 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010578" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10579" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10580" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010584 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010585 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010586" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010587 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010588 if v:shell_error != 0
10589 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010590 call netrw#ErrorMsg(s:ERROR,"remove failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",102)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010591 else
10592 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10593 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010594 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010595 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010597" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010598 endif
10599 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010600 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010601" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010602 endif
10603
10604 else
10605 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010606" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010607 if !all
10608 call inputsave()
10609 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10610 call inputrestore()
10611 if ok == ""
10612 let ok="no"
10613 endif
10614 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010615 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010616 let all= 1
10617 endif
10618 endif
10619
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010620 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010621 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010622 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010623 else
10624 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010625 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10626" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010627 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010628" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010629
10630 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010631" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10632 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10633" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010634 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010635" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010636
10637 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010638 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010639 endif
10640 endif
10641 endif
10642
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010643 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010644" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010645 endif
10646 endif
10647
10648" call Dret("s:NetrwRemoteRmFile ".ok)
10649 return ok
10650endfun
10651
10652" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653" s:NetrwRemoteRename: rename a remote file or directory {{{2
10654fun! s:NetrwRemoteRename(usrhost,path) range
10655" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10656
10657 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010658 let svpos = winsaveview()
10659" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 let ctr = a:firstline
10661 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10662
10663 " rename files given by the markfilelist
10664 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10665 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010666" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010667 if exists("subfrom")
10668 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010669" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010670 else
10671 call inputsave()
10672 let newname= input("Moving ".oldname." to : ",oldname)
10673 call inputrestore()
10674 if newname =~ '^s/'
10675 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10676 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10677 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010678" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010679 endif
10680 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010681
Bram Moolenaar446cb832008-06-24 21:56:24 +000010682 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010683 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010684 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010685 let oldname= s:ShellEscape(a:path.oldname)
10686 let newname= s:ShellEscape(a:path.newname)
10687" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010688 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010689 endif
10690
10691 endfor
10692 call s:NetrwUnMarkFile(1)
10693
10694 else
10695
10696 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010697 let keepsol= &l:sol
10698 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010699 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010700 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010701
10702 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010703" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010704
10705 call inputsave()
10706 let newname= input("Moving ".oldname." to : ",oldname)
10707 call inputrestore()
10708
10709 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10710 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10711 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010712 let oldname= s:ShellEscape(a:path.oldname)
10713 let newname= s:ShellEscape(a:path.newname)
10714" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010715 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010716 endif
10717
10718 let ctr= ctr + 1
10719 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010720 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010721 endif
10722
10723 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010724 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010725" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10726 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010727
10728" call Dret("NetrwRemoteRename")
10729endfun
10730
Bram Moolenaar85850f32019-07-19 22:05:51 +020010731" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010732" Local Directory Browsing Support: {{{1
10733" ==========================================
10734
10735" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010736" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010737" Should accept: file://localhost/etc/fstab
10738" file:///etc/fstab
10739" file:///c:/WINDOWS/clock.avi
10740" file:///c|/WINDOWS/clock.avi
10741" file://localhost/c:/WINDOWS/clock.avi
10742" file://localhost/c|/WINDOWS/clock.avi
10743" file://c:/foo.txt
10744" file:///c:/foo.txt
10745" and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value
Bram Moolenaar85850f32019-07-19 22:05:51 +020010746fun! netrw#FileUrlEdit(fname)
10747" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010748 let fname = a:fname
10749 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010750" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010751 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010752" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010753 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010754 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010755 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010756" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010757 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010758" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010759 endif
10760 endif
10761 let fname2396 = netrw#RFC2396(fname)
10762 let fname2396e= fnameescape(fname2396)
10763 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010764 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010766 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010767" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010768 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10769 endif
10770 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010771
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010772" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10773" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010774 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010775 exe 'NetrwKeepj keepalt edit '.plainfname
10776 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10777
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010778" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010779" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010780 exe "sil doau BufReadPost ".fname2396e
10781endfun
10782
10783" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010784" netrw#LocalBrowseCheck: {{{2
10785fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010786 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010787 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10788 "
10789 " unfortunate interaction -- split window debugging can't be used here, must use
10790 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10791 " another call to LocalBrowseCheck() when attempts to write
10792 " to the DBG buffer are made.
10793 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010794 " The &ft == "netrw" test was installed because the BufEnter event
10795 " would hit when re-entering netrw windows, creating unexpected
10796 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010797" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010798" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010799" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +010010800 " getting E930: Cannot use :redir inside execute
10801"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010802" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10803" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010804
Bram Moolenaar97d62492012-11-15 21:28:22 +010010805 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010806 if isdirectory(s:NetrwFile(a:dirname))
10807" call Decho("is-directory ft<".&ft."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : " doesn't exist")."> dirname<".a:dirname.">"." line($)=".line("$")." ft<".&ft."> g:netrw_fastbrowse=".g:netrw_fastbrowse,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010808
Bram Moolenaar97d62492012-11-15 21:28:22 +010010809 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010810" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10811" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010812 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010813
Bram Moolenaar446cb832008-06-24 21:56:24 +000010814 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010815" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010816 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010817
Bram Moolenaar5c736222010-01-06 20:54:52 +010010818 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010819" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010820 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010821 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010822 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010823" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010824" call Dret("netrw#LocalBrowseCheck")
10825 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010826 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010827
Bram Moolenaar85850f32019-07-19 22:05:51 +020010828 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010829 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10830 " AND IF the listing style is not a tree listing
10831 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010832" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010833 let ibuf = 1
10834 let buflast = bufnr("$")
10835 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010836 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10837 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010838 endif
10839 let ibuf= ibuf + 1
10840 endwhile
10841 endif
10842 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010843" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
10844" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010845 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010846" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010847endfun
10848
10849" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010850" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010851" performed any shell command. The idea is to cause all local-browsing
10852" buffers to be refreshed after a user has executed some shell command,
10853" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010854fun! s:LocalBrowseRefresh()
10855" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010856" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10857" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010858
Bram Moolenaar446cb832008-06-24 21:56:24 +000010859 " determine which buffers currently reside in a tab
10860 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010861" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010862 return
10863 endif
10864 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010865" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010866 return
10867 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010868 if !empty(getcmdwintype())
10869 " cannot move away from cmdline window, see :h E11
10870 return
10871 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010872 if exists("s:netrw_events") && s:netrw_events == 1
10873 " s:LocalFastBrowser gets called (indirectly) from a
10874 let s:netrw_events= 2
10875" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10876 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010877 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010878 let itab = 1
10879 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010880 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010881 while itab <= tabpagenr("$")
10882 let buftablist = buftablist + tabpagebuflist()
10883 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010884 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010885 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010886" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10887" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010888 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10889 " | refresh any netrw window
10890 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010891 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010892 let ibl = 0
10893 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010894" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010895 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10896 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010897 " (ibuf not shown in a current window AND
10898 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010899" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10900 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010901 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010902" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010903 continue
10904 elseif index(tabpagebuflist(),ibuf) != -1
10905 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010906" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010907 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010908 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010909 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10910 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10911 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10912 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010913" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010914 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10915 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10916 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010917 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010918 endif
10919 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010920" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010921 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010922" call Decho("restore window: win_gotoid(".curwinid.")")
10923 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010924 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010925
Bram Moolenaara6878372014-03-22 21:02:50 +010010926" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010927endfun
10928
10929" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010930" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10931"
10932" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010933" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010934" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10935" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010936" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010937"
10938" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10939" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010940" (re-using a buffer may not be as accurate)
10941"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010942" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010943" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10944" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10945" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10946" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010947fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010948" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10949" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10950" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10951" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010952
10953 " initialize browselist, a list of buffer numbers that the local browser has used
10954 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010955" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010956 let s:netrw_browselist= []
10957 endif
10958
10959 " append current buffer to fastbrowse list
10960 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010961" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010962 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010963" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010964 endif
10965
10966 " enable autocmd events to handle refreshing/removing local browser buffers
10967 " If local browse buffer is currently showing: refresh it
10968 " If local browse buffer is currently hidden : wipe it
10969 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10970 " =1 : medium speed, re-use directory listing for remote only
10971 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010972 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10973 let s:netrw_events= 1
10974 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010975 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010976 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010977" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010978 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010979 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010980" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010981 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010982 endif
10983 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010984
10985 " user must have changed fastbrowse to its fast setting, so remove
10986 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010987 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010988" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010989 unlet s:netrw_events
10990 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010991 au!
10992 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010993 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010994 endif
10995
Bram Moolenaar85850f32019-07-19 22:05:51 +020010996" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010997endfun
10998
10999" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011000" s:LocalListing: does the job of "ls" for local directories {{{2
11001fun! s:LocalListing()
11002" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011003" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11004" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11005" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011006
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011007" if exists("b:netrw_curdir") |call Decho('b:netrw_curdir<'.b:netrw_curdir.">") |else|call Decho("b:netrw_curdir doesn't exist",'~'.expand("<slnum>")) |endif
11008" if exists("g:netrw_sort_by")|call Decho('g:netrw_sort_by<'.g:netrw_sort_by.">")|else|call Decho("g:netrw_sort_by doesn't exist",'~'.expand("<slnum>"))|endif
11009" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011010
11011 " get the list of files contained in the current directory
11012 let dirname = b:netrw_curdir
11013 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011014 let filelist = s:NetrwGlob(dirname,"*",0)
11015 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011016" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011017
Nir Lichtman1e34b952024-05-08 19:19:34 +020011018 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011019" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011020 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11021 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011022" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011023 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011024" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011025 endif
11026
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011027" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011028" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011029" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011030
11031 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11032 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11033 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011034" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11035" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011036 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011037" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011038
11039 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011040" call Decho(" ",'~'.expand("<slnum>"))
11041" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011042
11043 if getftype(filename) == "link"
11044 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011045" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011046 let pfile= filename."@"
11047
11048 elseif getftype(filename) == "socket"
11049 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011050" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011051 let pfile= filename."="
11052
11053 elseif getftype(filename) == "fifo"
11054 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011055" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011056 let pfile= filename."|"
11057
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011058 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011059 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011060" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011061 let pfile= filename."/"
11062
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011063 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011064 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011065 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11066 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011067" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011068 let pfile= filename."*"
11069 else
11070 " normal file
11071 let pfile= filename
11072 endif
11073 elseif executable(filename)
11074 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011075" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011076 let pfile= filename."*"
11077 else
11078 " normal file
11079 let pfile= filename
11080 endif
11081
11082 else
11083 " normal file
11084 let pfile= filename
11085 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011086" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011087
11088 if pfile =~ '//$'
11089 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011090" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011091 endif
11092 let pfile= strpart(pfile,dirnamelen)
11093 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011094" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11095" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011096
11097 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011098 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11099 let sz = getfsize(filename)
11100 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11101 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011102
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011103 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011104 let sz= s:NetrwHumanReadable(sz)
11105 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011106 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011107 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011108" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011109 endif
11110
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011111 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011112 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011113 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011114" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011115" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011116 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011117 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011118" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011119 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011120 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011121
11122 elseif g:netrw_sort_by =~ "^s"
11123 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011124" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011125" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011126 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011127 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011128" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011129 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011130 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011131
11132 else
11133 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011134" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011135" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011136 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011137 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011138" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011139 endfor
11140
11141 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011142 sil! NetrwKeepj g/^$/d
11143 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011144 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011145" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011146 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11147
11148" call Dret("s:LocalListing")
11149endfun
11150
11151" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011152" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11153fun! s:NetrwLocalExecute(cmd)
11154" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11155 let ykeep= @@
11156 " sanity check
11157 if !executable(a:cmd)
11158 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11159 let @@= ykeep
11160" call Dret("s:NetrwLocalExecute")
11161 return
11162 endif
11163
11164 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011165" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011166 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011167" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011168
11169 " strip any ansi escape sequences off
11170 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11171
11172 " show user the result(s)
11173 echomsg result
11174 let @@= ykeep
11175
11176" call Dret("s:NetrwLocalExecute")
11177endfun
11178
11179" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011180" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011181fun! s:NetrwLocalRename(path) range
11182" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11183
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011184 if !exists("w:netrw_bannercnt")
11185 let w:netrw_bannercnt= b:netrw_bannercnt
11186 endif
11187
Bram Moolenaar97d62492012-11-15 21:28:22 +010011188 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011189 let ykeep = @@
11190 let ctr = a:firstline
11191 let svpos = winsaveview()
11192 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011193" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011194
11195 " rename files given by the markfilelist
11196 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11197 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011198" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011199 if exists("subfrom")
11200 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011201" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011202 else
11203 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011204 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011205 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011206 if newname =~ ''
11207 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11208 let newname = substitute(newname,'^.*','','')
11209 elseif newname =~ ''
11210 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11211 let newname = substitute(newname,'[^/]*','','')
11212 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011213 if newname =~ '^s/'
11214 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11215 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011216" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011217 let newname = substitute(oldname,subfrom,subto,'')
11218 endif
11219 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011220 if !all && filereadable(newname)
11221 call inputsave()
11222 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11223 call inputrestore()
11224 if response == "all"
11225 let all= 1
11226 elseif response != "y" && response != "yes"
11227 " refresh the directory
11228" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11229 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11230" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11231 NetrwKeepj call winrestview(svpos)
11232 let @@= ykeep
11233" call Dret("NetrwLocalRename")
11234 return
11235 endif
11236 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011237 call rename(oldname,newname)
11238 endfor
11239 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011240
Bram Moolenaar97d62492012-11-15 21:28:22 +010011241 else
11242
11243 " attempt to rename files/directories
11244 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011245 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011246
11247 " sanity checks
11248 if line(".") < w:netrw_bannercnt
11249 let ctr= ctr + 1
11250 continue
11251 endif
11252 let curword= s:NetrwGetWord()
11253 if curword == "./" || curword == "../"
11254 let ctr= ctr + 1
11255 continue
11256 endif
11257
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011258 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011259 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011260" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011261
11262 call inputsave()
11263 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11264 call inputrestore()
11265
11266 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011267" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011268
11269 let ctr= ctr + 1
11270 endwhile
11271 endif
11272
11273 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011274" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011275 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011276" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11277 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011278 let @@= ykeep
11279
11280" call Dret("NetrwLocalRename")
11281endfun
11282
11283" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011284" s:NetrwLocalRm: {{{2
11285fun! s:NetrwLocalRm(path) range
11286" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011287" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011288
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011289 if !exists("w:netrw_bannercnt")
11290 let w:netrw_bannercnt= b:netrw_bannercnt
11291 endif
11292
Bram Moolenaar446cb832008-06-24 21:56:24 +000011293 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011294 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011295 let ret = 0
11296 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011297 let svpos = winsaveview()
11298" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011299
11300 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11301 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011302" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011303 for fname in s:netrwmarkfilelist_{bufnr("%")}
11304 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011305 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011306 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011307 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011308 let all= 1
11309 endif
11310 endfor
11311 call s:NetrwUnMarkFile(1)
11312
11313 else
11314 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011315" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011316
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011317 let keepsol= &l:sol
11318 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011319 let ctr = a:firstline
11320 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011321 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011322
11323 " sanity checks
11324 if line(".") < w:netrw_bannercnt
11325 let ctr= ctr + 1
11326 continue
11327 endif
11328 let curword= s:NetrwGetWord()
11329 if curword == "./" || curword == "../"
11330 let ctr= ctr + 1
11331 continue
11332 endif
11333 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011334 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011335 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011336 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011337 let all= 1
11338 endif
11339 let ctr= ctr + 1
11340 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011341 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011342 endif
11343
11344 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011345" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011346 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011347 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011348" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11349 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011350 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011351 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011352
11353" call Dret("s:NetrwLocalRm")
11354endfun
11355
11356" ---------------------------------------------------------------------
11357" s:NetrwLocalRmFile: remove file fname given the path {{{2
11358" Give confirmation prompt unless all==1
11359fun! s:NetrwLocalRmFile(path,fname,all)
11360" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011361
Bram Moolenaar446cb832008-06-24 21:56:24 +000011362 let all= a:all
11363 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011364 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011365 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011366" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011367
11368 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11369 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011370" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011371 if !all
11372 echohl Statement
11373 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011374 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011375 call inputrestore()
11376 echohl NONE
11377 if ok == ""
11378 let ok="no"
11379 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011380" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011381 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011382" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011383 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011384 let all= 1
11385 endif
11386 endif
11387
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011388 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011389 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011390" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011391 endif
11392
11393 else
11394 " attempt to remove directory
11395 if !all
11396 echohl Statement
11397 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011398 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399 call inputrestore()
11400 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11401 if ok == ""
11402 let ok="no"
11403 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011404 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011405 let all= 1
11406 endif
11407 endif
11408 let rmfile= substitute(rmfile,'[\/]$','','e')
11409
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011410 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011411 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011412 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011413 endif
11414 endif
11415 endif
11416
11417" call Dret("s:NetrwLocalRmFile ".ok)
11418 return ok
11419endfun
11420
Bram Moolenaar85850f32019-07-19 22:05:51 +020011421" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011422" Support Functions: {{{1
11423
Bram Moolenaar488c6512005-08-11 20:09:58 +000011424" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011425" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11426" 0: marked file list of current buffer
11427" 1: marked file target
11428fun! netrw#Access(ilist)
11429 if a:ilist == 0
11430 if exists("s:netrwmarkfilelist_".bufnr('%'))
11431 return s:netrwmarkfilelist_{bufnr('%')}
11432 else
11433 return "no-list-buf#".bufnr('%')
11434 endif
11435 elseif a:ilist == 1
11436 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011437 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011438endfun
11439
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011440" ---------------------------------------------------------------------
11441" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11442fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011443 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011444endfun
11445
Bram Moolenaara6878372014-03-22 21:02:50 +010011446" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011447" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11448" I expect this function to be used in
11449" :PChkAssert netrw#Expose("netrwmarkfilelist")
11450" for example.
11451fun! netrw#Expose(varname)
11452" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011453 if exists("s:".a:varname)
11454 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011455" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011456 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011457" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011458 if type(retval) == 3
11459 let retval = copy(retval)
11460 let i = 0
11461 while i < len(retval)
11462 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11463 let i = i + 1
11464 endwhile
11465 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011466" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011467 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011468 else
11469" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011470 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011471 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011472" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011473 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011474 endif
11475
11476" call Dret("netrw#Expose ".string(retval))
11477 return retval
11478endfun
11479
11480" ---------------------------------------------------------------------
11481" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11482fun! netrw#Modify(varname,newvalue)
11483" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11484 exe "let s:".a:varname."= ".string(a:newvalue)
11485" call Dret("netrw#Modify")
11486endfun
11487
11488" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011489" netrw#RFC2396: converts %xx into characters {{{2
11490fun! netrw#RFC2396(fname)
11491" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011492 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011493" call Dret("netrw#RFC2396 ".fname)
11494 return fname
11495endfun
11496
11497" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011498" netrw#UserMaps: supports user-specified maps {{{2
11499" see :help function()
11500"
11501" g:Netrw_UserMaps is a List with members such as:
11502" [[keymap sequence, function reference],...]
11503"
11504" The referenced function may return a string,
11505" refresh : refresh the display
11506" -other- : this string will be executed
11507" or it may return a List of strings.
11508"
11509" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011510" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011511" Related functions:
11512" netrw#Expose(varname) -- see s:varname variables
11513" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11514" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11515fun! netrw#UserMaps(islocal)
11516" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11517" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11518
11519 " set up usermaplist
11520 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11521" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11522 for umap in g:Netrw_UserMaps
11523" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11524" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11525 " if umap[0] is a string and umap[1] is a string holding a function name
11526 if type(umap[0]) == 1 && type(umap[1]) == 1
11527" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11528 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11529 else
11530 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11531 endif
11532 endfor
11533 endif
11534" call Dret("netrw#UserMaps")
11535endfun
11536
11537" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011538" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11539fun! netrw#WinPath(path)
11540" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011541 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011542 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011543 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011544 " remove trailing slash (Win95)
11545 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11546 " remove escaped spaces
11547 let path = substitute(path, '\ ', ' ', 'g')
11548 " convert slashes to backslashes
11549 let path = substitute(path, '/', '\', 'g')
11550 else
11551 let path= a:path
11552 endif
11553" call Dret("netrw#WinPath <".path.">")
11554 return path
11555endfun
11556
11557" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011558" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11559fun! s:StripTrailingSlash(path)
11560 " remove trailing slash
11561 return substitute(a:path, '[/\\]$', '', 'g')
11562endfun
11563
Travis Sheltone34d0e32024-07-30 21:08:56 +020011564" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011565" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11566" cb : bl2mf=0 add marked files to buffer list
11567" cB : bl2mf=1 use bufferlist to mark files
11568" (mnemonic: cb = copy (marked files) to buffer list)
11569fun! s:NetrwBadd(islocal,bl2mf)
11570" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11571 if a:bl2mf
11572 " cB: add buffer list to marked files
11573 redir => bufl
11574 ls
11575 redir END
11576 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11577 for fname in bufl
11578 call s:NetrwMarkFile(a:islocal,fname)
11579 endfor
11580 else
11581 " cb: add marked files to buffer list
11582 for fname in s:netrwmarkfilelist_{bufnr("%")}
11583" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11584 exe "badd ".fnameescape(fname)
11585 endfor
11586 let curbufnr = bufnr("%")
11587 let curdir = s:NetrwGetCurdir(a:islocal)
11588 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11589 endif
11590" call Dret("s:NetrwBadd")
11591endfun
11592
11593" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011594" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11595fun! s:ComposePath(base,subdir)
11596" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11597
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011598 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011599" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011600 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011601 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011602 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011603 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011604 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011605 endif
11606
Bram Moolenaar85850f32019-07-19 22:05:51 +020011607 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011608 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011609" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011610 let ret= a:subdir
11611
Nir Lichtman1e34b952024-05-08 19:19:34 +020011612 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011613" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011614 if a:base =~ '[/\\]$'
11615 let ret= a:base.a:subdir
11616 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011617 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011618 endif
11619
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011620 elseif a:base =~ '^\a\{3,}://'
11621" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011622 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11623 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11624 if a:subdir == '../'
11625 if curpath =~ '[^/]/[^/]\+/$'
11626 let curpath= substitute(curpath,'[^/]\+/$','','')
11627 else
11628 let curpath=""
11629 endif
11630 let ret= urlbase.curpath
11631 else
11632 let ret= urlbase.curpath.a:subdir
11633 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011634" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11635" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11636" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011637
11638 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011639" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011640 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11641 if a:base =~ '^//'
11642 " keeping initial '//' for the benefit of network share listing support
11643 let ret= '/'.ret
11644 endif
11645 let ret= simplify(ret)
11646 endif
11647
11648" call Dret("s:ComposePath ".ret)
11649 return ret
11650endfun
11651
11652" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011653" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11654" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11655fun! s:DeleteBookmark(fname)
11656" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11657 call s:MergeBookmarks()
11658
11659 if exists("g:netrw_bookmarklist")
11660 let indx= index(g:netrw_bookmarklist,a:fname)
11661 if indx == -1
11662 let indx= 0
11663 while indx < len(g:netrw_bookmarklist)
11664 if g:netrw_bookmarklist[indx] =~ a:fname
11665 call remove(g:netrw_bookmarklist,indx)
11666 let indx= indx - 1
11667 endif
11668 let indx= indx + 1
11669 endwhile
11670 else
11671 " remove exact match
11672 call remove(g:netrw_bookmarklist,indx)
11673 endif
11674 endif
11675
11676" call Dret("s:DeleteBookmark")
11677endfun
11678
11679" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011680" s:FileReadable: o/s independent filereadable {{{2
11681fun! s:FileReadable(fname)
11682" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11683
11684 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011685 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011686 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011687 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011688 endif
11689
11690" call Dret("s:FileReadable ".ret)
11691 return ret
11692endfun
11693
11694" ---------------------------------------------------------------------
11695" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11696" Places correct suffix on end of temporary filename,
11697" using the suffix provided with fname
11698fun! s:GetTempfile(fname)
11699" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11700
11701 if !exists("b:netrw_tmpfile")
11702 " get a brand new temporary filename
11703 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011704" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011705
Bram Moolenaarc236c162008-07-13 17:41:49 +000011706 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011707" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011708
Bram Moolenaar9964e462007-05-05 17:54:07 +000011709 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011710 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11711" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011712 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011713" call Dret("s:GetTempfile getcwd<".getcwd().">")
11714 return ""
11715 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011716
Bram Moolenaar9964e462007-05-05 17:54:07 +000011717 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011718 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011719" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011720
Bram Moolenaar9964e462007-05-05 17:54:07 +000011721 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011722 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011723 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011724 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011725 if !exists("+shellslash") || !&ssl
11726 let tmpfile = substitute(tmpfile,'/','\','g')
11727 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011728 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011729 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011730 endif
11731 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011732" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011733 else
11734 " re-use temporary filename
11735 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011736" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011737 endif
11738
11739 " use fname's suffix for the temporary file
11740 if a:fname != ""
11741 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011742" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011743 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011744 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011745 elseif a:fname =~ '.txz$'
11746 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011747 else
11748 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11749 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011750" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011751 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011752" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011753 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011754" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011755 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11756 endif
11757 endif
11758
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011759" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011760" call Dret("s:GetTempfile <".tmpfile.">")
11761 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011762endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011763
11764" ---------------------------------------------------------------------
11765" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011766" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011767fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011768" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011769 if s:user == ""
11770 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11771 else
11772 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11773 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011774 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011775 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011776 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011777 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011778 else
11779 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11780 endif
11781" call Dret("s:MakeSshCmd <".sshcmd.">")
11782 return sshcmd
11783endfun
11784
11785" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011786" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11787fun! s:MakeBookmark(fname)
11788" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11789
11790 if !exists("g:netrw_bookmarklist")
11791 let g:netrw_bookmarklist= []
11792 endif
11793
11794 if index(g:netrw_bookmarklist,a:fname) == -1
11795 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011796 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011797 call add(g:netrw_bookmarklist,a:fname.'/')
11798 elseif a:fname !~ '/'
11799 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11800 else
11801 call add(g:netrw_bookmarklist,a:fname)
11802 endif
11803 call sort(g:netrw_bookmarklist)
11804 endif
11805
11806" call Dret("s:MakeBookmark")
11807endfun
11808
11809" ---------------------------------------------------------------------
11810" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11811fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011812" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011813 " get bookmarks from .netrwbook file
11814 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011815 if filereadable(s:NetrwFile(savefile))
11816" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011817 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011818" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011819 NetrwKeepj call delete(savefile)
11820 endif
11821" call Dret("s:MergeBookmarks")
11822endfun
11823
11824" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011825" s:NetrwBMShow: {{{2
11826fun! s:NetrwBMShow()
11827" call Dfunc("s:NetrwBMShow()")
11828 redir => bmshowraw
11829 menu
11830 redir END
11831 let bmshowlist = split(bmshowraw,'\n')
11832 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011833 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011834 if bmshowfuncs != []
11835 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011836 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011837 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011838 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011839 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011840 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011841" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11842endfun
11843
11844" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011845" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011846fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011847 if !exists("w:netrw_liststyle")
11848 let w:netrw_liststyle= g:netrw_liststyle
11849 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011850" call Dfunc("s:NetrwCursor() ft<".&ft."> liststyle=".w:netrw_liststyle." g:netrw_cursor=".g:netrw_cursor." s:netrw_usercuc=".s:netrw_usercuc." s:netrw_usercul=".s:netrw_usercul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011851
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011852" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11853
Bram Moolenaaradc21822011-04-01 18:03:16 +020011854 if &ft != "netrw"
11855 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11856 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011857" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011858
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011859 elseif g:netrw_cursor == 8
11860 if w:netrw_liststyle == s:WIDELIST
11861 setl cursorline
11862 setl cursorcolumn
11863 else
11864 setl cursorline
11865 endif
11866 elseif g:netrw_cursor == 7
11867 setl cursorline
11868 elseif g:netrw_cursor == 6
11869 if w:netrw_liststyle == s:WIDELIST
11870 setl cursorline
11871 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011872 elseif g:netrw_cursor == 4
11873 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011874" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011875 setl cursorline
11876 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011877
11878 elseif g:netrw_cursor == 3
11879 " thin-long-tree: cursorline, user's cursorcolumn
11880 " wide : cursorline, cursorcolumn
11881 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011882" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011883 setl cursorline
11884 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011885 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011886" call Decho("case g:netrw_cursor==3 and not wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011887 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011888 endif
11889
11890 elseif g:netrw_cursor == 2
11891 " thin-long-tree: cursorline, user's cursorcolumn
11892 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011893" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011894 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011895
11896 elseif g:netrw_cursor == 1
11897 " thin-long-tree: user's cursorline, user's cursorcolumn
11898 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011899 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011900" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011901 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011902 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011903" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011904 endif
11905
11906 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011907 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011908" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011909 let &l:cursorline = s:netrw_usercul
11910 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011911 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011912
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011913" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011914" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011915endfun
11916
11917" ---------------------------------------------------------------------
11918" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11919fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011920" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011921 if exists("s:netrw_usercul")
11922 let &l:cursorline = s:netrw_usercul
11923 endif
11924 if exists("s:netrw_usercuc")
11925 let &l:cursorcolumn = s:netrw_usercuc
11926 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011927" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011928" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11929endfun
11930
Christian Brabandt62f7b552024-06-23 20:23:40 +020011931" s:RestoreRegister: restores all registers given in the dict {{{2
11932fun! s:RestoreRegister(dict)
11933 for [key, val] in items(a:dict)
11934 if key == 'unnamed'
11935 let key = ''
11936 endif
11937 call setreg(key, val[0], val[1])
11938 endfor
11939endfun
11940
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011941" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011942" s:NetrwDelete: Deletes a file. {{{2
11943" Uses Steve Hall's idea to insure that Windows paths stay
11944" acceptable. No effect on Unix paths.
11945" Examples of use: let result= s:NetrwDelete(path)
11946fun! s:NetrwDelete(path)
11947" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11948
Bram Moolenaar5c736222010-01-06 20:54:52 +010011949 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011950 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011951 if exists("+shellslash")
11952 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011953 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011954 let result = delete(path)
11955 let &shellslash = sskeep
11956 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011957" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011958 let result= delete(path)
11959 endif
11960 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011961" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011962 let result= delete(path)
11963 endif
11964 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011965 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011966 endif
11967
11968" call Dret("s:NetrwDelete ".result)
11969 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011970endfun
11971
11972" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011973" s:NetrwBufRemover: removes a buffer that: {{{2s
11974" has buffer-id > 1
11975" is unlisted
11976" is unnamed
11977" does not appear in any window
11978fun! s:NetrwBufRemover(bufid)
11979" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11980" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11981" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11982" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11983" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11984
yasuda4dbb2662023-10-04 20:50:35 +020011985 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011986" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020011987 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011988 endif
11989
11990" call Dret("s:NetrwBufRemover")
11991endfun
11992
11993" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011994" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011995fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011996" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011997" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011998
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011999 " Clean out the last buffer:
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012000 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12001 " If so, delete it.
12002 call s:NetrwBufRemover(bufnr("$"))
12003
Bram Moolenaar446cb832008-06-24 21:56:24 +000012004 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012005" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012006 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12007 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12008 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12009 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12010 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12011 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12012 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12013 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12014 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12015 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12016 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12017 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12018 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12019 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12020 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12021 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12022
Bram Moolenaar85850f32019-07-19 22:05:51 +020012023 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012024" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012025 " when tree listing uses file TreeListing... a new buffer is made.
12026 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012027 " COMBAK: this causes a problem, see P43
12028" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012029 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012030 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012031 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012032" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012033 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012034
Bram Moolenaar446cb832008-06-24 21:56:24 +000012035 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012036" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012037 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12038 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12039 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12040 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12041 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12042 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12043 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12044 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12045 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12046 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12047 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12048 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12049 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12050 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12051 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12052 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12053
Bram Moolenaar5c736222010-01-06 20:54:52 +010012054 if a:0 > 0
12055 let b:netrw_curdir= a:1
12056 if b:netrw_curdir =~ '/$'
12057 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012058 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012059 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012060 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012061 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12062 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012063 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012064 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012065 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012066 endif
12067 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012068 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12069 let &l:bexpr = "netrw#BalloonHelp()"
12070 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012071
Bram Moolenaar8d043172014-01-23 14:24:41 +010012072" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012073endfun
12074
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012075" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012076" s:NetrwExe: executes a string using "!" {{{2
12077fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012078" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Konfekt3d7e5672024-10-27 22:16:49 +010012079 if has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012080" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012081 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12082 set shell& shellcmdflag& shellxquote& shellxescape&
12083 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010012084 try
12085 exe a:cmd
12086 finally
12087 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12088 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012089 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012090" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012091 exe a:cmd
12092 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012093 if v:shell_error
12094 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12095 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012096" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012097endfun
12098
12099" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012100" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12101fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012102 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012103" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012104 let curbuf = bufnr("%")
12105 let curwin = winnr()
12106 let iwin = 1
12107 while iwin <= winnr("$")
12108 exe iwin."wincmd w"
12109 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12110 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12111 let winvars= w:
12112 break
12113 endif
12114 let iwin= iwin + 1
12115 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012116 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012117 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012118" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012119 for k in keys(winvars)
12120 let w:{k}= winvars[k]
12121 endfor
12122 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012123" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012124 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012125endfun
12126
Bram Moolenaara6878372014-03-22 21:02:50 +010012127" ---------------------------------------------------------------------
12128" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012129" Returns: 0=success
12130" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012131fun! s:NetrwLcd(newdir)
12132" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012133" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012134
Bram Moolenaar85850f32019-07-19 22:05:51 +020012135 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012136 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012137 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012138 catch /^Vim\%((\a\+)\)\=:E344/
12139 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12140 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012141 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012142 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12143 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012144 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012145 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12146 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012147 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012148 endif
12149 endif
12150 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012151 let err472= 1
12152 endtry
12153
12154 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012155 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12156 if exists("w:netrw_prvdir")
12157 let a:newdir= w:netrw_prvdir
12158 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012159 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012160" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012161 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012162" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012163 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012164 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012165" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12166 return -1
12167 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012168
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012169" call Decho("getcwd <".getcwd().">")
12170" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012171" call Dret("s:NetrwLcd 0")
12172 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012173endfun
12174
Bram Moolenaar9964e462007-05-05 17:54:07 +000012175" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012176" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12177" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12178fun! s:NetrwSaveWordPosn()
12179" call Dfunc("NetrwSaveWordPosn()")
12180 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12181" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12182endfun
12183
12184" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012185" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12186" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12187fun! s:NetrwHumanReadable(sz)
12188" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12189
12190 if g:netrw_sizestyle == 'h'
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010012191 if a:sz >= 1000000000
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012192 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12193 elseif a:sz >= 10000000
12194 let sz = printf("%d",a:sz/1000000)."m"
12195 elseif a:sz >= 1000000
12196 let sz = printf("%.1f",a:sz/1000000.0)."m"
12197 elseif a:sz >= 10000
12198 let sz = printf("%d",a:sz/1000)."k"
12199 elseif a:sz >= 1000
12200 let sz = printf("%.1f",a:sz/1000.0)."k"
12201 else
12202 let sz= a:sz
12203 endif
12204
12205 elseif g:netrw_sizestyle == 'H'
12206 if a:sz >= 1073741824
12207 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12208 elseif a:sz >= 10485760
12209 let sz = printf("%d",a:sz/1048576)."M"
12210 elseif a:sz >= 1048576
12211 let sz = printf("%.1f",a:sz/1048576.0)."M"
12212 elseif a:sz >= 10240
12213 let sz = printf("%d",a:sz/1024)."K"
12214 elseif a:sz >= 1024
12215 let sz = printf("%.1f",a:sz/1024.0)."K"
12216 else
12217 let sz= a:sz
12218 endif
12219
12220 else
12221 let sz= a:sz
12222 endif
12223
12224" call Dret("s:NetrwHumanReadable ".sz)
12225 return sz
12226endfun
12227
12228" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012229" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12230" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12231fun! s:NetrwRestoreWordPosn()
12232" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012233 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012234" call Dret("NetrwRestoreWordPosn")
12235endfun
12236
12237" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012238" s:RestoreBufVars: {{{2
12239fun! s:RestoreBufVars()
12240" call Dfunc("s:RestoreBufVars()")
12241
12242 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12243 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12244 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12245 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12246 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12247 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12248
12249" call Dret("s:RestoreBufVars")
12250endfun
12251
12252" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012253" s:RemotePathAnalysis: {{{2
12254fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012255" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012256
Bram Moolenaara6878372014-03-22 21:02:50 +010012257 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012258 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012259 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012260 let s:user = substitute(a:dirname,dirpat,'\3','')
12261 let s:machine = substitute(a:dirname,dirpat,'\4','')
12262 let s:port = substitute(a:dirname,dirpat,'\5','')
12263 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012264 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012265 if s:machine =~ '@'
12266 let dirpat = '^\(.*\)@\(.\{-}\)$'
12267 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12268 let s:machine = substitute(s:machine,dirpat,'\2','')
12269 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012270
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012271" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12272" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12273" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12274" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12275" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12276" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012277
12278" call Dret("s:RemotePathAnalysis")
12279endfun
12280
12281" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012282" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12283" Returns status
12284" Runs system() on
12285" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012286" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012287fun! s:RemoteSystem(cmd)
12288" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12289 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012290 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"g:netrw_ssh_cmd<".g:netrw_ssh_cmd."> is not executable!",52)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012291 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012292 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012293 else
12294 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12295 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12296 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012297 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012298 else
12299 let cmd= cmd.' '
12300 endif
12301 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012302" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012303 let ret= system(cmd)
12304 endif
12305" call Dret("s:RemoteSystem ".ret)
12306 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012307endfun
12308
12309" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012310" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012311fun! s:RestoreWinVars()
12312" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012313 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012314 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12315 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12316 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12317 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12318 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12319 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12320 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12321 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12322 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12323 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12324 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12325 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012326 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12327 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012328 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12329 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12330 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12331" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012332endfun
12333
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012334" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012335" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12336"
12337" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12338" is true) and a command, :Rexplore, which call this function.
12339"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012340" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012341"
12342" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012343fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012344 if exists("s:netrwdrag")
12345 return
12346 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012347" call Dfunc("s:NetrwRexplore() w:netrw_rexlocal=".w:netrw_rexlocal." w:netrw_rexdir<".w:netrw_rexdir."> win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012348" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12349" call Decho("ft=".&ft." win#".winnr()." w:netrw_rexfile<".(exists("w:netrw_rexfile")? w:netrw_rexfile : 'n/a').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012350
12351 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012352 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012353" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012354 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012355 unlet w:netrw_rexfile
12356" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012357 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012358" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012359" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12360" call Decho("treating as not-netrw-buffer: w:netrw_rexfile<".((exists("w:netrw_rexfile"))? w:netrw_rexfile : 'n/a').">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020012361 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012362
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012363 " ---------------------------
12364 " :Rex issued while in a file
12365 " ---------------------------
12366
Bram Moolenaara6878372014-03-22 21:02:50 +010012367 " record current file so :Rex can return to it from netrw
12368 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012369" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012370
12371 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012372" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012373 return
12374 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012375" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012376 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012377 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012378 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012379 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012380 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012381 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012382 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012383 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012384 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012385" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12386 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012387" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12388 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012389 if exists("s:rexposn_".bufnr('%'))
12390 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012391 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012392 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012393" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012394 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012395
Bram Moolenaar85850f32019-07-19 22:05:51 +020012396 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12397 if exists("s:explore_match")
12398 exe "2match netrwMarkFile /".s:explore_match."/"
12399 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012400 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012401
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012402" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012403" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012404endfun
12405
12406" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012407" s:SaveBufVars: save selected b: variables to s: variables {{{2
12408" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012409fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012410" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012411
12412 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12413 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12414 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12415 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12416 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12417 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12418
12419" call Dret("s:SaveBufVars")
12420endfun
12421
12422" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012423" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12424fun! s:SavePosn(posndict)
12425" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12426
Bram Moolenaar85850f32019-07-19 22:05:51 +020012427 if !exists("a:posndict[bufnr('%')]")
12428 let a:posndict[bufnr("%")]= []
12429 endif
12430" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12431 call add(a:posndict[bufnr("%")],winsaveview())
12432" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012433
12434" call Dret("s:SavePosn posndict")
12435 return a:posndict
12436endfun
12437
12438" ---------------------------------------------------------------------
12439" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12440fun! s:RestorePosn(posndict)
12441" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012442 if exists("a:posndict")
12443 if has_key(a:posndict,bufnr("%"))
12444" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12445 let posnlen= len(a:posndict[bufnr("%")])
12446 if posnlen > 0
12447 let posnlen= posnlen - 1
12448" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12449 call winrestview(a:posndict[bufnr("%")][posnlen])
12450 call remove(a:posndict[bufnr("%")],posnlen)
12451" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12452 endif
12453 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012454 endif
12455" call Dret("s:RestorePosn")
12456endfun
12457
12458" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012459" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012460fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012461" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012462 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12463 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12464 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12465 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12466 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12467 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12468 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12469 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12470 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12471 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12472 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12473 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12474 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12475 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12476 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12477 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12478 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12479 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12480" call Dret("s:SaveWinVars")
12481endfun
12482
12483" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012484" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012485" To allow separate windows to have their own activities, such as
12486" Explore **/pattern, several variables have been made window-oriented.
12487" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012488" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012489" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012490fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012491" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012492 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12493 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12494 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12495 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12496 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12497 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12498 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12499 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12500 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12501 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12502" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012503endfun
12504
12505" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012506" s:SetRexDir: set directory for :Rexplore {{{2
12507fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012508" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012509 let w:netrw_rexdir = a:dirname
12510 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012511 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012512" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12513" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012514" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012515" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012516" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012517endfun
12518
12519" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012520" s:ShowLink: used to modify thin and tree listings to show links {{{2
12521fun! s:ShowLink()
12522" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012523" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12524" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012525 if exists("b:netrw_curdir")
12526 norm! $?\a
12527 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12528 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012529" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12530" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12531" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12532 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012533 let dirlen = strlen(b:netrw_curdir)
12534 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012535" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012536 endif
12537 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012538" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12539" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012540 setl noro ma
12541 call setline(".",modline)
12542 setl ro noma nomod
12543 endif
12544" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12545endfun
12546
12547" ---------------------------------------------------------------------
12548" s:ShowStyle: {{{2
12549fun! s:ShowStyle()
12550 if !exists("w:netrw_liststyle")
12551 let liststyle= g:netrw_liststyle
12552 else
12553 let liststyle= w:netrw_liststyle
12554 endif
12555 if liststyle == s:THINLIST
12556 return s:THINLIST.":thin"
12557 elseif liststyle == s:LONGLIST
12558 return s:LONGLIST.":long"
12559 elseif liststyle == s:WIDELIST
12560 return s:WIDELIST.":wide"
12561 elseif liststyle == s:TREELIST
12562 return s:TREELIST.":tree"
12563 else
12564 return 'n/a'
12565 endif
12566endfun
12567
12568" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012569" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12570" Solution from Nicolai Weibull, vim docs (:help strlen()),
12571" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012572fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012573" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12574
12575 if v:version >= 703 && exists("*strdisplaywidth")
12576 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012577
Bram Moolenaar8d043172014-01-23 14:24:41 +010012578 elseif type(g:Align_xstrlen) == 1
12579 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12580 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012581
Bram Moolenaar8d043172014-01-23 14:24:41 +010012582 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012583 " number of codepoints (Latin a + combining circumflex is two codepoints)
12584 " (comment from TM, solution from NW)
12585 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012586
Bram Moolenaar8d043172014-01-23 14:24:41 +010012587 elseif g:Align_xstrlen == 2
12588 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012589 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12590 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012591 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012592
Bram Moolenaar8d043172014-01-23 14:24:41 +010012593 elseif g:Align_xstrlen == 3
12594 " virtual length (counting, for instance, tabs as anything between 1 and
12595 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012596 " preceded by lam, one otherwise, etc.)
12597 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012598 let modkeep= &l:mod
12599 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012600 call setline(line("."),a:x)
12601 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012602 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012603 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012604 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012605
Bram Moolenaar446cb832008-06-24 21:56:24 +000012606 else
12607 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012608 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012609 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012610" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012611 return ret
12612endfun
12613
12614" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012615" s:ShellEscape: shellescape(), or special windows handling {{{2
12616fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012617 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012618 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010012619 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012620 let f = a:0 > 0 ? a:1 : 0
12621 return shellescape(a:s, f)
12622endfun
12623
12624" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012625" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012626fun! s:TreeListMove(dir)
12627" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012628 let curline = getline('.')
12629 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12630 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12631 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12632 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12633 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12634 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12635" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12636" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12637" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12638" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12639" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12640 " COMBAK : need to handle when on a directory
12641 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012642 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012643 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012644 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012645 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012646" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012647 elseif a:dir == '[]' && nxtline != ''
12648 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012649" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012650 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12651 if nl != 0
12652 NetrwKeepj norm! k
12653 else
12654 NetrwKeepj norm! G
12655 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012656" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012657 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012658 endif
12659
12660" call Dret("s:TreeListMove")
12661endfun
12662
12663" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012664" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12665" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12666" can't be called except via emenu. But due to locale, that menu line may not be called
12667" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12668fun! s:UpdateBuffersMenu()
12669" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012670 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012671 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012672 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012673 catch /^Vim\%((\a\+)\)\=:E/
12674 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012675 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012676 endtry
12677 endif
12678" call Dret("s:UpdateBuffersMenu")
12679endfun
12680
12681" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012682" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012683" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012684fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012685" call Dfunc("s:UseBufWinVars()")
12686 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012687 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12688 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12689 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12690 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12691 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12692 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12693 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12694 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12695 if exists("b:netrw_explore_list") && !exists("w:netrw_explore_list") |let w:netrw_explore_list = b:netrw_explore_list |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012696" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012697endfun
12698
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012699" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012700" s:UserMaps: supports user-defined UserMaps {{{2
12701" * calls a user-supplied funcref(islocal,curdir)
12702" * interprets result
12703" See netrw#UserMaps()
12704fun! s:UserMaps(islocal,funcname)
12705" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12706
12707 if !exists("b:netrw_curdir")
12708 let b:netrw_curdir= getcwd()
12709 endif
12710 let Funcref = function(a:funcname)
12711 let result = Funcref(a:islocal)
12712
12713 if type(result) == 1
12714 " if result from user's funcref is a string...
12715" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12716 if result == "refresh"
12717" call Decho("refreshing display",'~'.expand("<slnum>"))
12718 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12719 elseif result != ""
12720" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12721 exe result
12722 endif
12723
12724 elseif type(result) == 3
12725 " if result from user's funcref is a List...
12726" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12727 for action in result
12728 if action == "refresh"
12729" call Decho("refreshing display",'~'.expand("<slnum>"))
12730 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12731 elseif action != ""
12732" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12733 exe action
12734 endif
12735 endfor
12736 endif
12737
12738" call Dret("s:UserMaps")
12739endfun
12740
Bram Moolenaar85850f32019-07-19 22:05:51 +020012741" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012742" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012743" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012744let &cpo= s:keepcpo
12745unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012746
Bram Moolenaar85850f32019-07-19 22:05:51 +020012747" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012748" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012749" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012750" vim:ts=8 fdm=marker