blob: 77456d3fb5a003728b746d9c47735cc9753e15d5 [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)
Travis Sheltone34d0e32024-07-30 21:08:56 +020033" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010034" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000035" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010036" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000037" Permission is hereby granted to use and distribute this code,
38" with or without modifications, provided that this copyright
39" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000040" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000041" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000042" expressed or implied. By using this plugin, you agree that
43" in no event will the copyright holder be liable for any damages
44" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010045"
46" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
47" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
48"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020049"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000050"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000051" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000052" (James 1:22 RSV)
53" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000054" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000055if &cp || exists("g:loaded_netrw")
56 finish
57endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020058
59" Check that vim has patches that netrw requires.
60" Patches needed for v7.4: 1557, and 213.
61" (netrw will benefit from vim's having patch#656, too)
62let s:needspatches=[1557,213]
63if exists("s:needspatches")
64 for ptch in s:needspatches
65 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
66 if !exists("s:needpatch{ptch}")
67 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
68 endif
69 let s:needpatch{ptch}= 1
70 finish
71 endif
72 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020073endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020074
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010075let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000076
Bram Moolenaar1afcace2005-11-25 19:54:28 +000077let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010078setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020079"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010080"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010081"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000082
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000083" ======================
84" Netrw Variables: {{{1
85" ======================
86
Bram Moolenaar071d4272004-06-13 20:20:40 +000087" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020088" netrw#ErrorMsg: {{{2
89" 0=note = s:NOTE
90" 1=warning = s:WARNING
91" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010092" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
93" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
94" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010095" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020096fun! netrw#ErrorMsg(level,msg,errnum)
97" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
98
99 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200100" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200101 return
102 endif
103
104 if a:level == 1
105 let level= "**warning** (netrw) "
106 elseif a:level == 2
107 let level= "**error** (netrw) "
108 else
109 let level= "**note** (netrw) "
110 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100111" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200112
Damienb4d11642024-08-15 22:00:45 +0200113 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200114 " use popup window
115 if type(a:msg) == 3
116 let msg = [level]+a:msg
117 else
118 let msg= level.a:msg
119 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200120 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200121 let s:popuperr_text= ""
122 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200123 " (default) netrw creates a one-line window to show error/warning
124 " messages (reliably displayed)
125
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100126 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200127 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100128" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200129
130 " getting messages out reliably is just plain difficult!
131 " This attempt splits the current window, creating a one line window.
132 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100133" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200134 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100135" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200136 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100137 if type(a:msg) == 3
138 for msg in a:msg
139 NetrwKeepj call setline(line("$")+1,level.msg)
140 endfor
141 else
142 NetrwKeepj call setline(line("$")+1,level.a:msg)
143 endif
144 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200145 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100146" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200147 bo 1split
148 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200149 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200150 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100151 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100152" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200153 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100154 if type(a:msg) == 3
155 for msg in a:msg
156 NetrwKeepj call setline(line("$")+1,level.msg)
157 endfor
158 else
159 NetrwKeepj call setline(line("$"),level.a:msg)
160 endif
161 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200162 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100163" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200164 if &fo !~ '[ta]'
165 syn clear
166 syn match netrwMesgNote "^\*\*note\*\*"
167 syn match netrwMesgWarning "^\*\*warning\*\*"
168 syn match netrwMesgError "^\*\*error\*\*"
169 hi link netrwMesgWarning WarningMsg
170 hi link netrwMesgError Error
171 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100172" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200173 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200174
175 else
176 " (optional) netrw will show messages using echomsg. Even if the
177 " message doesn't appear, at least it'll be recallable via :messages
178" redraw!
179 if a:level == s:WARNING
180 echohl WarningMsg
181 elseif a:level == s:ERROR
182 echohl Error
183 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100184
185 if type(a:msg) == 3
186 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100187 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100188 endfor
189 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100190 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100191 endif
192
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100193" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200194 echohl None
195 endif
196
197" call Dret("netrw#ErrorMsg")
198endfun
199
200" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100201" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100202" Loosely, varname = value.
203fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100204" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100205 if !exists(a:varname)
206 if type(a:value) == 0
207 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200208 elseif type(a:value) == 1 && a:value =~ '^[{[]'
209 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100210 elseif type(a:value) == 1
211 exe "let ".a:varname."="."'".a:value."'"
212 else
213 exe "let ".a:varname."=".a:value
214 endif
215 endif
216endfun
217
218" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000219" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200220call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000221if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100222 call s:NetrwInit("s:THINLIST",0)
223 call s:NetrwInit("s:LONGLIST",1)
224 call s:NetrwInit("s:WIDELIST",2)
225 call s:NetrwInit("s:TREELIST",3)
226 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000227endif
228
Damien7c754112024-08-15 21:58:57 +0200229let s:NOTE = 0
230let s:WARNING = 1
231let s:ERROR = 2
232call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
233
Bram Moolenaar9964e462007-05-05 17:54:07 +0000234" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200235" Default option values: {{{2
236let g:netrw_localcopycmdopt = ""
237let g:netrw_localcopydircmdopt = ""
238let g:netrw_localmkdiropt = ""
239let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200240
241" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000242" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200243if exists("*popup_atcursor")
244\ && has("syntax")
245\ && exists("g:syntax_on")
246\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200247 call s:NetrwInit("g:netrw_use_errorwindow",2)
248else
249 call s:NetrwInit("g:netrw_use_errorwindow",1)
250endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200251
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000252if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100253 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000254 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100255 elseif executable("curl")
256 let g:netrw_dav_cmd = "curl"
257 else
258 let g:netrw_dav_cmd = ""
259 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000260endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000261if !exists("g:netrw_fetch_cmd")
262 if executable("fetch")
263 let g:netrw_fetch_cmd = "fetch -o"
264 else
265 let g:netrw_fetch_cmd = ""
266 endif
267endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100268if !exists("g:netrw_file_cmd")
269 if executable("elinks")
270 call s:NetrwInit("g:netrw_file_cmd","elinks")
271 elseif executable("links")
272 call s:NetrwInit("g:netrw_file_cmd","links")
273 endif
274endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000275if !exists("g:netrw_ftp_cmd")
276 let g:netrw_ftp_cmd = "ftp"
277endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200278let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200279if !exists("g:netrw_ftp_options")
280 let g:netrw_ftp_options= "-i -n"
281endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000282if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100283 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100284 let g:netrw_http_cmd = "wget"
285 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100286 elseif executable("curl")
287 let g:netrw_http_cmd = "curl"
288 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200289 elseif executable("elinks")
290 let g:netrw_http_cmd = "elinks"
291 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000292 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100293 let g:netrw_http_cmd = "fetch"
294 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200295 elseif executable("links")
296 let g:netrw_http_cmd = "links"
297 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000298 else
299 let g:netrw_http_cmd = ""
300 endif
301endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100302call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100303call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100304call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
305call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200306call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200307if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200308 if executable("scp")
309 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
310 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200311 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200312 else
313 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
314 endif
315endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100316call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
317call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000318
Nir Lichtman1e34b952024-05-08 19:19:34 +0200319if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000320 \ && exists("g:netrw_use_nt_rcp")
321 \ && g:netrw_use_nt_rcp
322 \ && executable( $SystemRoot .'/system32/rcp.exe')
323 let s:netrw_has_nt_rcp = 1
324 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000325else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000326 let s:netrw_has_nt_rcp = 0
327 let s:netrw_rcpmode = ''
328endif
329
330" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000331" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000332" Cygwin Detection ------- {{{3
333if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200334 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
335 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000336 else
337 let g:netrw_cygwin= 0
338 endif
339endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000340" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100341call s:NetrwInit("g:netrw_alto" , &sb)
342call s:NetrwInit("g:netrw_altv" , &spr)
343call s:NetrwInit("g:netrw_banner" , 1)
344call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200345call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100346call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200347call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100348call s:NetrwInit("g:netrw_compress" , "gzip")
349call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200350if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
351 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
352 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000353endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200354call s:NetrwInit("g:netrw_cursor" , 2)
355let s:netrw_usercul = &cursorline
356let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200357"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100358call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000359" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200360call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200361call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200362call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100363call s:NetrwInit("g:netrw_dirhistmax" , 10)
364call s:NetrwInit("g:netrw_fastbrowse" , 1)
365call 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 +0000366if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000367 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
368 let g:netrw_ftp_list_cmd = "ls -lF"
369 let g:netrw_ftp_timelist_cmd = "ls -tlF"
370 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000371 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000372 let g:netrw_ftp_list_cmd = "dir"
373 let g:netrw_ftp_timelist_cmd = "dir"
374 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000375 endif
376endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100377call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000378" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100379call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000380if !exists("g:netrw_ignorenetrc")
381 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
382 let g:netrw_ignorenetrc= 1
383 else
384 let g:netrw_ignorenetrc= 0
385 endif
386endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100387call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000388if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000389 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100390 if exists("g:netrw_list_cmd_options")
391 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
392 else
393 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
394 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000395 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200396 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100397 if exists("g:netrw_list_cmd_options")
398 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
399 else
400 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
401 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000402 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100403" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000404 let g:netrw_list_cmd= ""
405 endif
406endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100407call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000408" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200409if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200410 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200411 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
412endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100413if !exists("g:netrw_localcmdshell")
414 let g:netrw_localcmdshell= ""
415endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000416if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200417 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000418 if g:netrw_cygwin
419 let g:netrw_localcopycmd= "cp"
420 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000421 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200422 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000423 endif
424 elseif has("unix") || has("macunix")
425 let g:netrw_localcopycmd= "cp"
426 else
427 let g:netrw_localcopycmd= ""
428 endif
429endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100430if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200431 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100432 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200433 let g:netrw_localcopydircmd = "cp"
434 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100435 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000436 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200437 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100438 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200439 elseif has("unix")
440 let g:netrw_localcopydircmd = "cp"
441 let g:netrw_localcopydircmdopt= " -R"
442 elseif has("macunix")
443 let g:netrw_localcopydircmd = "cp"
444 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100445 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200446 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100447 endif
448endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200449if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100450 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200451 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
452endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200453if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200454 if g:netrw_cygwin
455 call s:NetrwInit("g:netrw_localmkdir","mkdir")
456 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000457 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200458 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200459 endif
460else
461 call s:NetrwInit("g:netrw_localmkdir","mkdir")
462endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200463call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200464if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200465 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200466 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
467endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000468if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200469 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000470 if g:netrw_cygwin
471 let g:netrw_localmovecmd= "mv"
472 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000473 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200474 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000475 endif
476 elseif has("unix") || has("macunix")
477 let g:netrw_localmovecmd= "mv"
478 else
479 let g:netrw_localmovecmd= ""
480 endif
481endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100482" following serves as an example for how to insert a version&patch specific test
483"if v:version < 704 || (v:version == 704 && !has("patch1107"))
484"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100485call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
486" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000487if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000488 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000489endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000490if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000491 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
492endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000493" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100494call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
495call s:NetrwInit("g:netrw_maxfilenamelen", 32)
496call s:NetrwInit("g:netrw_menu" , 1)
497call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200498call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100499call s:NetrwInit("g:netrw_retmap" , 0)
500if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
501 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200502elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100503 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
504else
505 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000506endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100507call s:NetrwInit("g:netrw_preview" , 0)
508call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100509call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100510call s:NetrwInit("g:netrw_sshport" , "-p")
511call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
512call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
513call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100514call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
515" Default values - q-s ---------- {{{3
516call s:NetrwInit("g:netrw_quickhelp",0)
517let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100518 \ "(create new) %:file d:directory",
519 \ "(windows split&open) o:horz v:vert p:preview",
520 \ "i:style qf:file info O:obtain r:reverse",
521 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
522 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
523 \ "(history) qb:list u:go up U:go down",
524 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100525" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
526call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100527if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
528 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
529else
530 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
531endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100532call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
533call s:NetrwInit("g:netrw_sort_options" , "")
534call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000535if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100536 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200537 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100538 else
539 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000540 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000541endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100542call s:NetrwInit("g:netrw_special_syntax" , 0)
543call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100544call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100545call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000546" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100547call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200548if !exists("g:netrw_xstrlen")
549 if exists("g:Align_xstrlen")
550 let g:netrw_xstrlen= g:Align_xstrlen
551 elseif exists("g:drawit_xstrlen")
552 let g:netrw_xstrlen= g:drawit_xstrlen
553 elseif &enc == "latin1" || !has("multi_byte")
554 let g:netrw_xstrlen= 0
555 else
556 let g:netrw_xstrlen= 1
557 endif
558endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100559call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200560call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100561call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200562if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000563" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000564" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100565call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200566if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200567 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200568else
Bram Moolenaarff034192013-04-24 18:51:19 +0200569 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200570endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200571call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100572call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
573call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100574if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100575 let s:treedepthstring= "│ "
576else
577 let s:treedepthstring= "| "
578endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200579call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000580
581" BufEnter event ignored by decho when following variable is true
582" Has a side effect that doau BufReadPost doesn't work, so
583" files read by network transfer aren't appropriately highlighted.
584"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585
Bram Moolenaaradc21822011-04-01 18:03:16 +0200586" ======================
587" Netrw Initialization: {{{1
588" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200589if 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 +0100590" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100591 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200592" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100593 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100594 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
595 au VimEnter * let s:initbeval= &beval
596"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100597" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
598" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
599" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
600" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
601" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
602" 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 +0200603endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200604au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200605
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200606if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100607 com! -nargs=* NetrwKeepj keepj <args>
608else
609 let g:netrw_keepj= ""
610 com! -nargs=* NetrwKeepj <args>
611endif
612
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000613" ==============================
614" Netrw Utility Functions: {{{1
615" ==============================
616
Bram Moolenaaradc21822011-04-01 18:03:16 +0200617" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100618" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100619if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100620" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100621 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100622 if &ft != "netrw"
623 return ""
624 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200625 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
626 " popup error window is still showing
627 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
628 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
629 " text under mouse hasn't changed; only close window when it changes
630 call popup_close(s:popuperr_id)
631 unlet s:popuperr_text
632 else
633 let s:popuperr_text= v:beval_text
634 endif
635 let mesg= ""
636 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 +0100637 let mesg= ""
638 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
639 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
640 elseif getline(v:beval_lnum) =~ '^"\s*/'
641 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
642 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100643 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100644 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
645 let mesg = "S: edit sorting sequence"
646 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
647 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
648 elseif v:beval_text == "Quick" || v:beval_text == "Help"
649 let mesg = "Help: press <F1>"
650 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
651 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
652 else
653 let mesg= ""
654 endif
655 return mesg
656 endfun
657"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100658" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
659" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
660" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
661" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
662" 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 +0200663endif
664
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200666" netrw#Explore: launch the local browser in the directory of the current file {{{2
667" indx: == -1: Nexplore
668" == -2: Pexplore
669" == +: this is overloaded:
670" * If Nexplore/Pexplore is in use, then this refers to the
671" indx'th item in the w:netrw_explore_list[] of items which
672" matched the */pattern **/pattern *//pattern **//pattern
673" * If Hexplore or Vexplore, then this will override
674" g:netrw_winsize to specify the qty of rows or columns the
675" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100676" 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 +0200677" dosplit==1: the window will be split before running the local browser
678" style == 0: Explore style == 1: Explore!
679" == 2: Hexplore style == 3: Hexplore!
680" == 4: Vexplore style == 5: Vexplore!
681" == 6: Texplore
682fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100683" 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 +0100684" 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 +0200685 if !exists("b:netrw_curdir")
686 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100687" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200688 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100689
690 " record current file for Rexplore's benefit
691 if &ft != "netrw"
692 let w:netrw_rexfile= expand("%:p")
693 endif
694
695 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200696 let curdir = simplify(b:netrw_curdir)
697 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200698 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200699 let curdir= substitute(curdir,'\','/','g')
700 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100701" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100702
703 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
704 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
705 " try Explore again.
706 if a:0 > 0
707" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100708 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
709 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
710 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
711 \ '~'.expand("<slnum>"))
712 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200713 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
714 if a1 != a:1
715 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
716 return
717 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100718 endif
719 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200720
721 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200722 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100723" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100724 sil! let keepregstar = @*
725 sil! let keepregplus = @+
726 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200727 sil! let keepregslash= @/
728
Bram Moolenaar8d043172014-01-23 14:24:41 +0100729 " if dosplit
730 " -or- file has been modified AND file not hidden when abandoned
731 " -or- Texplore used
732 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200733 call s:SaveWinVars()
734 let winsz= g:netrw_winsize
735 if a:indx > 0
736 let winsz= a:indx
737 endif
738
739 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200740 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200741 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200742 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200743
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200744 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200745 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200746 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200747 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200748
749 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200750 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200751 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200752 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200753
754 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200755 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200756 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200757 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200758
759 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200760 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200761 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200762 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200763
764 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200765 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200766 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200767 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200768
769 elseif a:style == 6 " Texplore
770 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200771 exe "keepalt tabnew ".fnameescape(curdir)
772 call s:RestoreBufVars()
773 endif
774 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100776 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200777
778 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100779" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200780 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100785" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
787 if dirname !~ '/$'
788 let dirname= dirname."/"
789 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200795 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100796" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200797 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100798" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200799 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100800" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200801 let dirname= a:1
802 endif
803 else
804 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100805" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200806 call s:NetrwClearExplore()
807" call Dret("netrw#Explore : cleared list")
808 return
809 endif
810
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100811" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200812 if dirname =~ '\.\./\=$'
813 let dirname= simplify(fnamemodify(dirname,':p:h'))
814 elseif dirname =~ '\.\.' || dirname == '.'
815 let dirname= simplify(fnamemodify(dirname,':p'))
816 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100817" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200818
819 if dirname =~ '^\*//'
820 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100821" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200822 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
823 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100824" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200825 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
826
827 elseif dirname =~ '^\*\*//'
828 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100829" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200830 let pattern= substitute(dirname,'^\*\*//','','')
831 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100832" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200833
834 elseif dirname =~ '/\*\*/'
835 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100836" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200837 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200838 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200839 let b:netrw_curdir = prefixdir
840 else
841 let b:netrw_curdir= getcwd().'/'.prefixdir
842 endif
843 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
844 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100845" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
846" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200847
848 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200849 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200850 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100851" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200852
853 elseif dirname=~ '^\*\*/'
854 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
855 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100856" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200857
858 else
859 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100860" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200861 endif
862
863 if starpat == 0 && a:indx >= 0
864 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100865" 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 +0200866 if dirname == ""
867 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100868" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200869 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200870 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200871 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200872 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200873 if dirname == ""
874 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200875 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100876 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100877 " depending on whether backslashes have been converted to forward slashes by earlier code).
878 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200879 let dirname= b:netrw_curdir."/".dirname
880 endif
881 elseif dirname !~ '^/'
882 let dirname= b:netrw_curdir."/".dirname
883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100884" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200885 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100886" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
887" 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 +0200888 endif
889 if exists("w:netrw_bannercnt")
890 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
891 " If one wants to return the same place in the netrw window, use :Rex instead.
892 exe w:netrw_bannercnt
893 endif
894
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100895" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200896 " ---------------------------------------------------------------------
897 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
898" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100899" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200900" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100901" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200902" endif
903 " ---------------------------------------------------------------------
904
905 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
906 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
907 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
908 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
909 elseif a:indx <= 0
910 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100911" 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 +0200912 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100913" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200914 let s:didstarstar= 1
915 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
916 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
917 endif
918
919 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100920" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200921 if !exists("w:netrw_explore_indx")
922 let w:netrw_explore_indx= 0
923 endif
924
925 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100926" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200927
928 if indx == -1
929 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100930" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200931 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100932 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 +0200933 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100934" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100935 if @* != keepregstar | sil! let @* = keepregstar | endif
936 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100937 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200938 sil! let @/ = keepregslash
939" call Dret("netrw#Explore")
940 return
941 endif
942 let indx= w:netrw_explore_indx
943 if indx < 0 | let indx= 0 | endif
944 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
945 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100946" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200947 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
948 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100949" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200950 endwhile
951 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100952" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200953
954 elseif indx == -2
955 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100956" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200957 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100958 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 +0200959 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100960" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100961 if @* != keepregstar | sil! let @* = keepregstar | endif
962 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100963 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200964 sil! let @/ = keepregslash
965" call Dret("netrw#Explore")
966 return
967 endif
968 let indx= w:netrw_explore_indx
969 if indx < 0 | let indx= 0 | endif
970 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
971 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100972" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200973 while indx >= 0 && curfile == w:netrw_explore_list[indx]
974 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100975" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200976 endwhile
977 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100978" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200979
980 else
981 " Explore -- initialize
982 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100983" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100984 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200985 let w:netrw_explore_indx= 0
986 if !exists("b:netrw_curdir")
987 let b:netrw_curdir= getcwd()
988 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100989" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200990
991 " switch on starpat to build the w:netrw_explore_list of files
992 if starpat == 1
993 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100994" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
995" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200996 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100997 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200998 catch /^Vim\%((\a\+)\)\=:E480/
999 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1000" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1001 return
1002 endtry
1003 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1004 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1005
1006 elseif starpat == 2
1007 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001008" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1009" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001010 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001011 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001012 catch /^Vim\%((\a\+)\)\=:E480/
1013 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1014 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001015 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001016" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001017 if @* != keepregstar | sil! let @* = keepregstar | endif
1018 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001019 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001020 sil! let @/ = keepregslash
1021" call Dret("netrw#Explore : no files matched pattern")
1022 return
1023 endtry
1024 let s:netrw_curdir = b:netrw_curdir
1025 let w:netrw_explore_list = getqflist()
1026 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1027 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1028
1029 elseif starpat == 3
1030 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001031" 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 +02001032 let filepat= substitute(dirname,'^\*/','','')
1033 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001034" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1035" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001036 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1037 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1038
1039 elseif starpat == 4
1040 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001041" 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 +02001042 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1043 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1044 endif " switch on starpat to build w:netrw_explore_list
1045
1046 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001047" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1048" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001049
1050 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001051 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001052 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001053" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001054 if @* != keepregstar | sil! let @* = keepregstar | endif
1055 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001056 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001057 sil! let @/ = keepregslash
1058" call Dret("netrw#Explore : no files matched")
1059 return
1060 endif
1061 endif " if indx ... endif
1062
1063 " NetrwStatusLine support - for exploring support
1064 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001065" 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 +02001066
1067 " wrap the indx around, but issue a note
1068 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001069" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001070 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1071 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001072 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001073 endif
1074
1075 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001076" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001077 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001078" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001079
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001080" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001081 call netrw#LocalBrowseCheck(newdir)
1082 if !exists("w:netrw_liststyle")
1083 let w:netrw_liststyle= g:netrw_liststyle
1084 endif
1085 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001086 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001087 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001088 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001089 endif
1090 let w:netrw_explore_mtchcnt = indx + 1
1091 let w:netrw_explore_bufnr = bufnr("%")
1092 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001093 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001094" 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 +02001095
1096 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001097" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001098 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001099 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 +02001100 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001101 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001102" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001103 if @* != keepregstar | sil! let @* = keepregstar | endif
1104 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001105 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001106 sil! let @/ = keepregslash
1107" call Dret("netrw#Explore : missing +path_extra")
1108 return
1109 endif
1110
1111 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001112" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001113 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1114 sil! unlet w:netrw_treedict
1115 sil! unlet w:netrw_treetop
1116 endif
1117 let newdir= dirname
1118 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001119 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001120 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001121 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 endif
1123 endif
1124
1125 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001126" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1127" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001128 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001129" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001130 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001131 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001132" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001133 let s:explore_prvdir = b:netrw_curdir
1134 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001135 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001136 if b:netrw_curdir !~ '/$'
1137 let dirlen= dirlen + 1
1138 endif
1139 let prvfname= ""
1140 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001141" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001142 if fname =~ '^'.b:netrw_curdir
1143 if s:explore_match == ""
1144 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1145 else
1146 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1147 endif
1148 elseif fname !~ '^/' && fname != prvfname
1149 if s:explore_match == ""
1150 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1151 else
1152 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1153 endif
1154 endif
1155 let prvfname= fname
1156 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001157" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001158 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1159 exe "2match netrwMarkFile /".s:explore_match."/"
1160 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001161 endif
1162 echo "<s-up>==Pexplore <s-down>==Nexplore"
1163 else
1164 2match none
1165 if exists("s:explore_match") | unlet s:explore_match | endif
1166 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001167" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001168 endif
1169
Bram Moolenaara6878372014-03-22 21:02:50 +01001170 " since Explore may be used to initialize netrw's browser,
1171 " there's no danger of a late FocusGained event on initialization.
1172 " Consequently, set s:netrw_events to 2.
1173 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001174 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001175" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001176 if @* != keepregstar | sil! let @* = keepregstar | endif
1177 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001178 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001179 sil! let @/ = keepregslash
1180" call Dret("netrw#Explore : @/<".@/.">")
1181endfun
1182
1183" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001184" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001185" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1186" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1187" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1188" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1189" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001190fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001191" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001192 let curwin= winnr()
1193
Bram Moolenaara6878372014-03-22 21:02:50 +01001194 if a:0 > 0 && a:1 != ""
1195 " if a netrw window is already on the left-side of the tab
1196 " and a directory has been specified, explore with that
1197 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001198" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001199 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001200" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001201 exe "1wincmd w"
1202 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001203" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
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 Moolenaara0f849e2015-10-30 14:37:44 +01001209" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001210 unlet t:netrw_lexposn
1211 endif
1212" call Dret("netrw#Lexplore")
1213 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001214 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001215 exe curwin."wincmd w"
1216 else
1217 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001218" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001219 endif
1220
Bram Moolenaar8d043172014-01-23 14:24:41 +01001221 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001222 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001223 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001224" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001225 else
1226 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001227" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001228 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001229" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001230
1231 if lexwinnr > 0
1232 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001233" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001234 exe lexwinnr."wincmd w"
1235 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001236 let t:netrw_lexposn = winsaveview()
1237" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001238" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001239 close
1240 if lexwinnr < curwin
1241 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001242 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001243 if lexwinnr != curwin
1244 exe curwin."wincmd w"
1245 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001246 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001247" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001248
1249 else
1250 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001251" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001252 exe "1wincmd w"
1253 let keep_altv = g:netrw_altv
1254 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001255 if a:count != 0
1256 let netrw_winsize = g:netrw_winsize
1257 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001258 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001259 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001260" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001261 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001262" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001263 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001264" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001265 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001267 elseif curfile =~ '^\a\{3,}://'
1268" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001269 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001270 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001271" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001272 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001273 endif
1274 if a:count != 0
1275 let g:netrw_winsize = netrw_winsize
1276 endif
1277 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001278 let g:netrw_altv = keep_altv
1279 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001280 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1281 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001282 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001283 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001284" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1285" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001286 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001287" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001288" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1289 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001290 unlet t:netrw_lexposn
1291 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001292 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001293
1294 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001295 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001296 if a:rightside
1297 let g:netrw_chgwin= 1
1298 else
1299 let g:netrw_chgwin= 2
1300 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001301" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001302 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001303
Bram Moolenaar8d043172014-01-23 14:24:41 +01001304" call Dret("netrw#Lexplore")
1305endfun
1306
1307" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001308" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001309" supports :NetrwClean -- remove netrw from first directory on runtimepath
1310" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001311fun! netrw#Clean(sys)
1312" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001313
1314 if a:sys
1315 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1316 else
1317 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1318 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001319" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001320 let diddel= 0
1321 let diddir= ""
1322
1323 if choice == 1
1324 for dir in split(&rtp,',')
1325 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001326" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001327 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1328 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1329 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1330 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1331 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1332 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 +00001333 let diddir= dir
1334 let diddel= diddel + 1
1335 if !a:sys|break|endif
1336 endif
1337 endfor
1338 endif
1339
1340 echohl WarningMsg
1341 if diddel == 0
1342 echomsg "netrw is either not installed or not removable"
1343 elseif diddel == 1
1344 echomsg "removed one copy of netrw from <".diddir.">"
1345 else
1346 echomsg "removed ".diddel." copies of netrw"
1347 endif
1348 echohl None
1349
Bram Moolenaara6878372014-03-22 21:02:50 +01001350" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001351endfun
1352
Bram Moolenaar5c736222010-01-06 20:54:52 +01001353" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001354" netrw#MakeTgt: make a target out of the directory name provided {{{2
1355fun! netrw#MakeTgt(dname)
1356" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1357 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001358 let svpos = winsaveview()
1359" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001360 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1361" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001362 if s:netrwmftgt_islocal
1363 let netrwmftgt= simplify(a:dname)
1364 else
1365 let netrwmftgt= a:dname
1366 endif
1367 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1368 " re-selected target, so just clear it
1369 unlet s:netrwmftgt s:netrwmftgt_islocal
1370 else
1371 let s:netrwmftgt= netrwmftgt
1372 endif
1373 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001374 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001375 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001376" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1377 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001378" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001379endfun
1380
Bram Moolenaara6878372014-03-22 21:02:50 +01001381" ---------------------------------------------------------------------
1382" netrw#Obtain: {{{2
1383" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001384" islocal=0 obtain from remote source
1385" =1 obtain from local source
1386" fname : a filename or a list of filenames
1387" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001388fun! netrw#Obtain(islocal,fname,...)
1389" 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 +02001390 " NetrwStatusLine support - for obtaining support
1391
1392 if type(a:fname) == 1
1393 let fnamelist= [ a:fname ]
1394 elseif type(a:fname) == 3
1395 let fnamelist= a:fname
1396 else
1397 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 +01001398" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001399 return
1400 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001401" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001402 if a:0 > 0
1403 let tgtdir= a:1
1404 else
1405 let tgtdir= getcwd()
1406 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001407" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001408
1409 if exists("b:netrw_islocal") && b:netrw_islocal
1410 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001411" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001412 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1413 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001414 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001415 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001416" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001417 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001418" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001419 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001420 if v:shell_error != 0
1421 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 +01001422" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001423 return
1424 endif
1425 endfor
1426 else
1427 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001428" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1429 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1430" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001431 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001432 if v:shell_error != 0
1433 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 +01001434" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001435 return
1436 endif
1437 endif
1438 elseif !exists("b:netrw_curdir")
1439 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1440 else
1441 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1442 endif
1443
1444 else
1445 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001446" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001447 if type(a:fname) == 1
1448 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1449 endif
1450 call s:NetrwMethod(b:netrw_curdir)
1451
1452 if b:netrw_method == 4
1453 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001454" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001455 if exists("g:netrw_port") && g:netrw_port != ""
1456 let useport= " ".g:netrw_scpport." ".g:netrw_port
1457 else
1458 let useport= ""
1459 endif
1460 if b:netrw_fname =~ '/'
1461 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1462 else
1463 let path= ""
1464 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001465 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001466 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 +02001467
1468 elseif b:netrw_method == 2
1469 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001470" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001471 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001472 let tmpbufnr= bufnr("%")
1473 setl ff=unix
1474 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001475 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001476" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001477 endif
1478
1479 if exists("b:netrw_fname") && b:netrw_fname != ""
1480 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001481" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001482 endif
1483
1484 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001485 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001486" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001487 endif
1488 for fname in fnamelist
1489 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001490" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001491 endfor
1492 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001493 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 +02001494 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001495 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001496 endif
1497 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1498 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1499 let debugkeep= &debug
1500 setl debug=msg
1501 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1502 let &debug= debugkeep
1503 endif
1504
1505 elseif b:netrw_method == 3
1506 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001507" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001508 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001509 let tmpbufnr= bufnr("%")
1510 setl ff=unix
1511
1512 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001513 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001514" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001515 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001516 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001517" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001518 endif
1519
1520 if exists("g:netrw_uid") && g:netrw_uid != ""
1521 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001522 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001523" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001524 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001525 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001526 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001527" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001528 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001529 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001530" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001531 endif
1532 endif
1533
1534 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001535 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001536" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001537 endif
1538
1539 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001540 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001541" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001542 endif
1543
1544 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001545 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001546" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001547 endif
1548
1549 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001550 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001551" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001552 endif
1553 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001554 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001555 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001556" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001557
1558 " perform ftp:
1559 " -i : turns off interactive prompting from ftp
1560 " -n unix : DON'T use <.netrc>, even though it exists
1561 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001562 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1563 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001564 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001565 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1566 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001567" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001568 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001569 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001570 endif
1571 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001572
1573 elseif b:netrw_method == 9
1574 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001575" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001576 if a:fname =~ '/'
1577 let localfile= substitute(a:fname,'^.*/','','')
1578 else
1579 let localfile= a:fname
1580 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001581 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 +02001582
Bram Moolenaarff034192013-04-24 18:51:19 +02001583 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001584 " probably a badly formed url; protocol not recognized
1585" call Dret("netrw#Obtain : unsupported method")
1586 return
1587
1588 else
1589 " protocol recognized but not supported for Obtain (yet?)
1590 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001591 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001592 endif
1593" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001594 return
1595 endif
1596
1597 " restore status line
1598 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001599 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001600 endif
1601
1602 endif
1603
1604 " cleanup
1605 if exists("tmpbufnr")
1606 if bufnr("%") != tmpbufnr
1607 exe tmpbufnr."bw!"
1608 else
1609 q!
1610 endif
1611 endif
1612
Bram Moolenaara6878372014-03-22 21:02:50 +01001613" call Dret("netrw#Obtain")
1614endfun
1615
1616" ---------------------------------------------------------------------
1617" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1618fun! netrw#Nread(mode,fname)
1619" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001620 let svpos= winsaveview()
1621" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001622 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001623" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1624 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001625
1626 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1627 if exists("w:netrw_bannercnt")
1628 " start with cursor just after the banner
1629 exe w:netrw_bannercnt
1630 endif
1631 endif
1632" call Dret("netrw#Nread")
1633endfun
1634
1635" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001636" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1637" Options get restored by s:NetrwOptionsRestore()
1638"
1639" Option handling:
1640" * save user's options (s:NetrwOptionsSave)
1641" * set netrw-safe options (s:NetrwOptionsSafe)
1642" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1643" * restore user's options (s:netrwOPtionsRestore)
1644" - restore a user option when != safe option (s:NetrwRestoreSetting)
1645" vt: (variable type) normally its either "w:" or "s:"
1646fun! s:NetrwOptionsSave(vt)
1647" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1648" 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 +02001649" 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>"))
1650" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001651
1652 if !exists("{a:vt}netrw_optionsave")
1653 let {a:vt}netrw_optionsave= 1
1654 else
1655" call Dret("s:NetrwOptionsSave : options already saved")
1656 return
1657 endif
1658" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1659
1660 " Save current settings and current directory
1661" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1662 let s:yykeep = @@
1663 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1664 let {a:vt}netrw_aikeep = &l:ai
1665 let {a:vt}netrw_awkeep = &l:aw
1666 let {a:vt}netrw_bhkeep = &l:bh
1667 let {a:vt}netrw_blkeep = &l:bl
1668 let {a:vt}netrw_btkeep = &l:bt
1669 let {a:vt}netrw_bombkeep = &l:bomb
1670 let {a:vt}netrw_cedit = &cedit
1671 let {a:vt}netrw_cikeep = &l:ci
1672 let {a:vt}netrw_cinkeep = &l:cin
1673 let {a:vt}netrw_cinokeep = &l:cino
1674 let {a:vt}netrw_comkeep = &l:com
1675 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001676 let {a:vt}netrw_cuckeep = &l:cuc
1677 let {a:vt}netrw_culkeep = &l:cul
1678" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001679 let {a:vt}netrw_diffkeep = &l:diff
1680 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001681 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1682 let {a:vt}netrw_ffkeep = &l:ff
1683 endif
1684 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1685 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001686 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001687 let {a:vt}netrw_hidkeep = &l:hidden
1688 let {a:vt}netrw_imkeep = &l:im
1689 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001690 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001691 let {a:vt}netrw_lskeep = &l:ls
1692 let {a:vt}netrw_makeep = &l:ma
1693 let {a:vt}netrw_magickeep = &l:magic
1694 let {a:vt}netrw_modkeep = &l:mod
1695 let {a:vt}netrw_nukeep = &l:nu
1696 let {a:vt}netrw_rnukeep = &l:rnu
1697 let {a:vt}netrw_repkeep = &l:report
1698 let {a:vt}netrw_rokeep = &l:ro
1699 let {a:vt}netrw_selkeep = &l:sel
1700 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001701 if !g:netrw_use_noswf
1702 let {a:vt}netrw_swfkeep = &l:swf
1703 endif
1704 let {a:vt}netrw_tskeep = &l:ts
1705 let {a:vt}netrw_twkeep = &l:tw " textwidth
1706 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1707 let {a:vt}netrw_wrapkeep = &l:wrap
1708 let {a:vt}netrw_writekeep = &l:write
1709
1710 " save a few selected netrw-related variables
1711" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1712 if g:netrw_keepdir
1713 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001714" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001715 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001716 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001717 sil! let {a:vt}netrw_starkeep = @*
1718 sil! let {a:vt}netrw_pluskeep = @+
1719 endif
1720 sil! let {a:vt}netrw_slashkeep= @/
1721
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001722" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001723" 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>"))
1724" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1725endfun
1726
1727" ---------------------------------------------------------------------
1728" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1729" Use s:NetrwSaveOptions() to save user settings
1730" Use s:NetrwOptionsRestore() to restore user settings
1731fun! s:NetrwOptionsSafe(islocal)
1732" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1733" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1734" 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>"))
1735 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1736 call s:NetrwSetSafeSetting("&l:ai",0)
1737 call s:NetrwSetSafeSetting("&l:aw",0)
1738 call s:NetrwSetSafeSetting("&l:bl",0)
1739 call s:NetrwSetSafeSetting("&l:bomb",0)
1740 if a:islocal
1741 call s:NetrwSetSafeSetting("&l:bt","nofile")
1742 else
1743 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1744 endif
1745 call s:NetrwSetSafeSetting("&l:ci",0)
1746 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001747 if g:netrw_fastbrowse > a:islocal
1748 call s:NetrwSetSafeSetting("&l:bh","hide")
1749 else
1750 call s:NetrwSetSafeSetting("&l:bh","delete")
1751 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001752 call s:NetrwSetSafeSetting("&l:cino","")
1753 call s:NetrwSetSafeSetting("&l:com","")
1754 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1755 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1756 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001757 if &go =~ 'a' | set go-=a | endif
1758 if &go =~ 'A' | set go-=A | endif
1759 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001760 call s:NetrwSetSafeSetting("&l:hid",0)
1761 call s:NetrwSetSafeSetting("&l:im",0)
1762 setl isk+=@ isk+=* isk+=/
1763 call s:NetrwSetSafeSetting("&l:magic",1)
1764 if g:netrw_use_noswf
1765 call s:NetrwSetSafeSetting("swf",0)
1766 endif
1767 call s:NetrwSetSafeSetting("&l:report",10000)
1768 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1769 call s:NetrwSetSafeSetting("&l:spell",0)
1770 call s:NetrwSetSafeSetting("&l:tw",0)
1771 call s:NetrwSetSafeSetting("&l:wig","")
1772 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001773
1774 " set up cuc and cul based on g:netrw_cursor and listing style
1775 " COMBAK -- cuc cul related
1776 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001777
1778 " allow the user to override safe options
1779" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1780 if &ft == "netrw"
1781" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1782 keepalt NetrwKeepj doau FileType netrw
1783 endif
1784
1785" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1786" 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>"))
1787" call Dret("s:NetrwOptionsSafe")
1788endfun
1789
1790" ---------------------------------------------------------------------
1791" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1792fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001793 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001794 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1795 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1796 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001797 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001798 else
1799 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001800 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001801 return
1802 endif
1803 unlet {a:vt}netrw_optionsave
1804
1805 if exists("+acd")
1806 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001807 let curdir = getcwd()
1808 let &l:acd = {a:vt}netrw_acdkeep
1809 unlet {a:vt}netrw_acdkeep
1810 if &l:acd
1811 call s:NetrwLcd(curdir)
1812 endif
1813 endif
1814 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001815 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1816 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1817 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1818 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1819 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1820 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1821 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1822 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1823 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1824 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1825 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1826 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1827 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1828 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1829 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001830 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001831 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1832 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001833 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001834 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001835 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1836 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001837 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001838 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1839 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001840 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001841 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1842 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001843 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1844 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1845 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1846 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001847 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001848 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1849 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1850 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001851 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1852 call s:NetrwRestoreSetting("s:yykeep","@@")
1853 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1854 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1855 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1856 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1857
Bram Moolenaara6878372014-03-22 21:02:50 +01001858 if exists("{a:vt}netrw_swfkeep")
1859 if &directory == ""
1860 " user hasn't specified a swapfile directory;
1861 " netrw will temporarily set the swapfile directory
1862 " to the current directory as returned by getcwd().
1863 let &l:directory= getcwd()
1864 sil! let &l:swf = {a:vt}netrw_swfkeep
1865 setl directory=
1866 unlet {a:vt}netrw_swfkeep
1867 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001868 if !g:netrw_use_noswf
1869 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1870 sil! let &l:swf= {a:vt}netrw_swfkeep
1871 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001872 unlet {a:vt}netrw_swfkeep
1873 endif
1874 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001875 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001876 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1877 if exists("{a:vt}netrw_dirkeep")
1878 call s:NetrwLcd(dirkeep)
1879 unlet {a:vt}netrw_dirkeep
1880 endif
1881 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001882 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001883 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1884 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001885 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001886 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001887
Bram Moolenaara6878372014-03-22 21:02:50 +01001888 " Moved the filetype detect here from NetrwGetFile() because remote files
1889 " were having their filetype detect-generated settings overwritten by
1890 " NetrwOptionRestore.
1891 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001892 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001893 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001894endfun
1895
1896" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001897" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1898" but only when the options' value and the safe setting differ
1899" Doing this means that netrw will not come up as having changed a
1900" setting last when it really didn't actually change it.
1901"
1902" Called from s:NetrwOptionsSafe
1903" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1904fun! s:NetrwSetSafeSetting(setting,safesetting)
1905" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001906
Bram Moolenaar85850f32019-07-19 22:05:51 +02001907 if a:setting =~ '^&'
1908" call Decho("fyi: a:setting starts with &")
1909 exe "let settingval= ".a:setting
1910" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001911
Bram Moolenaar85850f32019-07-19 22:05:51 +02001912 if settingval != a:safesetting
1913" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1914 if type(a:safesetting) == 0
1915 exe "let ".a:setting."=".a:safesetting
1916 elseif type(a:safesetting) == 1
1917 exe "let ".a:setting."= '".a:safesetting."'"
1918 else
1919 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1920 endif
1921 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001922 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001923
Bram Moolenaar85850f32019-07-19 22:05:51 +02001924" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001925endfun
1926
1927" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001928" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1929" but only if the setting value differs from the associated keepvar.
1930" Doing this means that netrw will not come up as having changed a
1931" setting last when it really didn't actually change it.
1932"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001933" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001934" keepvars are set up by s:NetrwOptionsSave
1935fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001936""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001937
Bram Moolenaar85850f32019-07-19 22:05:51 +02001938 " typically called from s:NetrwOptionsRestore
1939 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1940 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001941 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001942 if exists(a:keepvar)
1943 exe "let keepvarval= ".a:keepvar
1944 exe "let setting= ".a:setting
1945
1946"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1947"" call Decho("fyi: keepvarval=".keepvarval)
1948"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1949
1950 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001951"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001952 if type(a:setting) == 0
1953 exe "let ".a:setting."= ".keepvarval
1954 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001955 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001956 else
1957 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1958 endif
1959 endif
1960
1961 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001962 endif
1963
Bram Moolenaar85850f32019-07-19 22:05:51 +02001964"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001965endfun
1966
1967" ---------------------------------------------------------------------
1968" NetrwStatusLine: {{{2
1969fun! NetrwStatusLine()
1970
1971" vvv NetrwStatusLine() debugging vvv
1972" let g:stlmsg=""
1973" if !exists("w:netrw_explore_bufnr")
1974" let g:stlmsg="!X<explore_bufnr>"
1975" elseif w:netrw_explore_bufnr != bufnr("%")
1976" let g:stlmsg="explore_bufnr!=".bufnr("%")
1977" endif
1978" if !exists("w:netrw_explore_line")
1979" let g:stlmsg=" !X<explore_line>"
1980" elseif w:netrw_explore_line != line(".")
1981" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1982" endif
1983" if !exists("w:netrw_explore_list")
1984" let g:stlmsg=" !X<explore_list>"
1985" endif
1986" ^^^ NetrwStatusLine() debugging ^^^
1987
1988 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")
1989 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001990 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001991 let &laststatus = s:netrw_users_ls
1992 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1993 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1994 return ""
1995 else
1996 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1997 endif
1998endfun
1999
Bram Moolenaar85850f32019-07-19 22:05:51 +02002000" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002001" Netrw Transfer Functions: {{{1
2002" ===============================
2003
Bram Moolenaar071d4272004-06-13 20:20:40 +00002004" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002005" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002006" mode: =0 read remote file and insert before current line
2007" =1 read remote file and insert after current line
2008" =2 replace with remote file
2009" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002010fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002011" 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 +00002012
Bram Moolenaar5c736222010-01-06 20:54:52 +01002013 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002014 call s:NetrwOptionsSave("w:")
2015 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002016 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002017 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2018 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2019 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002020" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002021
Bram Moolenaar5c736222010-01-06 20:54:52 +01002022 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002023 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002024 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002025 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002026 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002027 elseif a:mode == 2 " replace with remote file
2028 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002029 elseif a:mode == 3 " skip read of file (leave as temporary)
2030 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002031 else
2032 exe a:mode
2033 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002034 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002035 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002036" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002037
Bram Moolenaar5c736222010-01-06 20:54:52 +01002038 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002039 let tmpfile= s:GetTempfile("")
2040 if tmpfile == ""
2041" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002042 return
2043 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002044
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002045 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002046
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002047 " attempt to repeat with previous host-file-etc
2048 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002049" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002050 let choice = b:netrw_lastfile
2051 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002052
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002053 else
2054 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002055" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002057 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002058 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002059 echomsg 'NetRead Usage:'
2060 echomsg ':Nread machine:path uses rcp'
2061 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2062 echomsg ':Nread "machine id password path" uses ftp'
2063 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2064 echomsg ':Nread fetch://machine/path uses fetch'
2065 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2066 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002067 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002068 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002069 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2070 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2071 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2072 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002073 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002074 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002075
Bram Moolenaar9964e462007-05-05 17:54:07 +00002076 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002077 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002078" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002079 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002080 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002081 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002082 else
2083 " case "... ... ..."
2084 let choice = strpart(choice,1,strlen(choice)-1)
2085 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002086
Bram Moolenaar9964e462007-05-05 17:54:07 +00002087 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002088 let wholechoice = wholechoice . " " . choice
2089 let ichoice = ichoice + 1
2090 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002091 if !exists("g:netrw_quiet")
2092 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2093 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002094" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002095 return
2096 endif
2097 let choice= a:{ichoice}
2098 endwhile
2099 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2100 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002101 endif
2102 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002104" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002105 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002106
Bram Moolenaar5c736222010-01-06 20:54:52 +01002107 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002108 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002109 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002110" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002111 return
2112 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002113 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002114
Bram Moolenaar8d043172014-01-23 14:24:41 +01002115 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002116" 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 +02002117 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002118" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002119 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002120" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002121 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002123
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002124 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002125 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002126 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002127 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2128 echo "(netrw) Processing your read request..."
2129 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002130
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002131 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002132 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002133 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002134" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002135 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002136 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002137 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002138 " ER: the tmpfile is full path: rcp sees C:\... as host C
2139 if s:netrw_has_nt_rcp == 1
2140 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2141 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2142 else
2143 " Any way needed it machine contains a '.'
2144 let uid_machine = g:netrw_machine .'.'. $USERNAME
2145 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002147 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2148 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2149 else
2150 let uid_machine = g:netrw_machine
2151 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002153 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 +00002154 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002155 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002156
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002157 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002158 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002159 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002160" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002161 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002162 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002163 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002164 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002165 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002166" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002167 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002168 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002169" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002170 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002171 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002172" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002173 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002174 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 +00002175 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002176 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002177 endif
2178 " 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 +00002179 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002180 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002181 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002182 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002183 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002184 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002185 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002186 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002187 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2188 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002189 q!
2190 endif
2191 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002192 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002193 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002194
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002195 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002196 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002197 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2198 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002199" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002200 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002201 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002202 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002203 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002204 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002205 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002206" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002207 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002208 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002209" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002210 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002211
Bram Moolenaar97d62492012-11-15 21:28:22 +01002212 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002213 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002214 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002215" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002216 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002217 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002218 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002219" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002220 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002221 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002222" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002223 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002224 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002225
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002227 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002228" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002230 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002231 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002232" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002233 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002234 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002235" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002236
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002237 " perform ftp:
2238 " -i : turns off interactive prompting from ftp
2239 " -n unix : DON'T use <.netrc>, even though it exists
2240 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002241 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002242 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002243 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2244 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002245" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002246 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002247 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002248 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002249 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002250 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002251 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002252 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002253
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002254 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002255 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002256 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002257" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002258 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002259 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002260 else
2261 let useport= ""
2262 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002263 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2264 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002265 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002266 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2267 else
2268 let tmpfile_get = tmpfile
2269 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002270 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 +00002271 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002273
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002274 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002275 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002276 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002277" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002279 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002280 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002281 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002282" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002283 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002285
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002286 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2287 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002288" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002289 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002290 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 +00002291 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002292 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 +00002293 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002294 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002295
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002296 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002297 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002298" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002299 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2300 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002301" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2302" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2303 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 +00002304 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002305" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002306 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002307 endif
2308 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002309" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002310 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002311
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002312 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002313 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002314 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002315" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002316
Bram Moolenaar5c736222010-01-06 20:54:52 +01002317 if !executable(g:netrw_dav_cmd)
2318 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2319" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2320 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002321 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002322 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002323 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 +01002324 else
2325 " Construct execution string (four lines) which will be passed through filter
2326 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2327 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002328 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002329 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002330 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002331 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002332 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002333 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002334 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002335 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002336 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002337 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2338 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002339
Bram Moolenaar5c736222010-01-06 20:54:52 +01002340 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002341 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002342 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002343 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002344 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002345 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002346 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002347
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002348 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002349 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002350 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002351" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002352 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 +00002353 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002354 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002355
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002356 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002357 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002358 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002359 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002360" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002361 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002362 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002363 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002364 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002365" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002366 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002367 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002368 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002369 let netrw_option= "http"
2370 else
2371 let netrw_option= "ftp"
2372 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002373" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002374
Bram Moolenaar446cb832008-06-24 21:56:24 +00002375 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002376 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 +00002377 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002378 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 +00002379 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002380
Bram Moolenaar446cb832008-06-24 21:56:24 +00002381 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002382 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002383" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002384 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002385
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002387 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002388 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002389" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2390 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 +00002391 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002392 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002393
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002394 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002395 " NetRead: (file) NetRead Method #10 {{{3
2396 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002397" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2398 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002399 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2400 let b:netrw_lastfile = choice
2401
2402 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002403 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002404 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002405 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002406 endif
2407 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002408
Bram Moolenaar5c736222010-01-06 20:54:52 +01002409 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002410 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002411" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002412 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002413 unlet b:netrw_fname
2414 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002415 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 +01002416" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002417 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002418 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002419 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002420
Bram Moolenaar9964e462007-05-05 17:54:07 +00002421" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002422endfun
2423
2424" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002425" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002426fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002427" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002428
Bram Moolenaar5c736222010-01-06 20:54:52 +01002429 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002430 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002431 call s:NetrwOptionsSave("w:")
2432 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002433
Bram Moolenaar5c736222010-01-06 20:54:52 +01002434 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002435 let tmpfile= s:GetTempfile("")
2436 if tmpfile == ""
2437" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002438 return
2439 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002440
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002441 if a:0 == 0
2442 let ichoice = 0
2443 else
2444 let ichoice = 1
2445 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002446
Bram Moolenaar9964e462007-05-05 17:54:07 +00002447 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002448" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002449 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002450 " For binary writes, always write entire file.
2451 " (line numbers don't really make sense for that).
2452 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002453" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002454 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002455 elseif g:netrw_cygwin
2456 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002457 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002458" 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 +01002459 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002460 else
2461 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002462" 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 +01002463 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002464 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002465
Bram Moolenaar9964e462007-05-05 17:54:07 +00002466 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002467 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002468 " on the temporary file's name. Deletion of the temporary file during
2469 " cleanup then causes an error message.
2470 0file!
2471 endif
2472
Bram Moolenaar5c736222010-01-06 20:54:52 +01002473 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002474 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002475
Bram Moolenaar9964e462007-05-05 17:54:07 +00002476 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002477 " attempt to repeat with previous host-file-etc
2478 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002479" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002480 let choice = b:netrw_lastfile
2481 let ichoice= ichoice + 1
2482 else
2483 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002484
Bram Moolenaar8d043172014-01-23 14:24:41 +01002485 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002486 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002487 echomsg 'NetWrite Usage:"'
2488 echomsg ':Nwrite machine:path uses rcp'
2489 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2490 echomsg ':Nwrite "machine id password path" uses ftp'
2491 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2492 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2493 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2494 echomsg ':Nwrite rcp://machine/path uses rcp'
2495 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2496 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2497 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002498 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002499 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002500
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002501 elseif match(choice,"^\"") != -1
2502 if match(choice,"\"$") != -1
2503 " case "..."
2504 let choice=strpart(choice,1,strlen(choice)-2)
2505 else
2506 " case "... ... ..."
2507 let choice = strpart(choice,1,strlen(choice)-1)
2508 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002509
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002510 while match(choice,"\"$") == -1
2511 let wholechoice= wholechoice . " " . choice
2512 let ichoice = ichoice + 1
2513 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002514 if !exists("g:netrw_quiet")
2515 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2516 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002517" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002518 return
2519 endif
2520 let choice= a:{ichoice}
2521 endwhile
2522 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2523 endif
2524 endif
2525 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002526 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002527" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002528
Bram Moolenaar9964e462007-05-05 17:54:07 +00002529 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002530 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002531 if !exists("b:netrw_method") || b:netrw_method < 0
2532" call Dfunc("netrw#NetWrite : unsupported method")
2533 return
2534 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002535
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002536 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002537 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002538 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002539 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2540 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002541" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002542 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002543
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002544 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002545 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002546 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002547" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002548 if s:netrw_has_nt_rcp == 1
2549 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2550 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2551 else
2552 let uid_machine = g:netrw_machine .'.'. $USERNAME
2553 endif
2554 else
2555 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2556 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2557 else
2558 let uid_machine = g:netrw_machine
2559 endif
2560 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002561 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 +00002562 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002563
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002564 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002565 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002566 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002567" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002568 let netrw_fname = b:netrw_fname
2569
2570 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2571 let bhkeep = &l:bh
2572 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002573 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002574 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002575
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002576" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002577 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002578 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002579" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002580 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002581 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002582" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002583 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002584 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002585" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002587 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 +00002588 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002589" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2590 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 endif
2592 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2593 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002594 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002595 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002596 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002597 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002599
2600 " remove enew buffer (quietly)
2601 let filtbuf= bufnr("%")
2602 exe curbuf."b!"
2603 let &l:bh = bhkeep
2604 exe filtbuf."bw!"
2605
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002607
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002608 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002609 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002610 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002611 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002612" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002613 let netrw_fname = b:netrw_fname
2614 let bhkeep = &l:bh
2615
2616 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2617 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002618 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002619 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002620 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002621
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002622 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002623 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002624" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002625 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002626 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002627" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002628 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002629 if exists("g:netrw_uid") && g:netrw_uid != ""
2630 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002631 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002632" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002633 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002634 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002635 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002636" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002637 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002638 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002639" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002640 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002641 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002642 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002643" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002645 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002646" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002647 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002648 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002649" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002650 " save choice/id/password for future use
2651 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002652
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002653 " perform ftp:
2654 " -i : turns off interactive prompting from ftp
2655 " -n unix : DON'T use <.netrc>, even though it exists
2656 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002657 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002658 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002659 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2660 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002661 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002662 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002663 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002664 let mod=1
2665 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002666
2667 " remove enew buffer (quietly)
2668 let filtbuf= bufnr("%")
2669 exe curbuf."b!"
2670 let &l:bh= bhkeep
2671 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002672
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002673 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002674 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002675 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002676" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002677 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002678 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002679 else
2680 let useport= ""
2681 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002682 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 +00002683 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002684
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002685 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002686 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002687 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002688" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002689 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2690 if executable(curl)
2691 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002692 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 +01002693 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002694 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002695 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002696
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002697 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002698 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002699 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002700" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002701
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002702 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002703 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2704 let bhkeep = &l:bh
2705
2706 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2707 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002708 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002709 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002710
Bram Moolenaarff034192013-04-24 18:51:19 +02002711 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002712 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002713 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002714 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002715 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002716 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002717 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002718 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002719 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002720 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002721
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002722 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002723 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002724 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002725
2726 " remove enew buffer (quietly)
2727 let filtbuf= bufnr("%")
2728 exe curbuf."b!"
2729 let &l:bh = bhkeep
2730 exe filtbuf."bw!"
2731
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002732 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002733
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002734 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002735 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002736 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002737" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002738 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 +00002739 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002740
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002741 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002742 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002743 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002744" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002745 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002746 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2747 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2748 else
2749 let uid_machine = g:netrw_machine
2750 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002751
2752 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2753 let bhkeep = &l:bh
2754 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002755 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002756 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002757
Bram Moolenaarff034192013-04-24 18:51:19 +02002758 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002759 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002760" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002761 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002762 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002763 let filtbuf= bufnr("%")
2764 exe curbuf."b!"
2765 let &l:bh = bhkeep
2766 exe filtbuf."bw!"
2767 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002768
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002769 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002770 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002771 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002772 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002773 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002774 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002775 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002776
Bram Moolenaar5c736222010-01-06 20:54:52 +01002777 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002778" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002779 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002780" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002781 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002782 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002783 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002784
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002785 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002786 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002787 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002788" 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 +02002789 elseif !exists("leavemod")
2790 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002791" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002792 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002793" 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 +00002794 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002795
Bram Moolenaar9964e462007-05-05 17:54:07 +00002796" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002797endfun
2798
2799" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002800" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002801" uses NetRead to get a copy of the file into a temporarily file,
2802" then sources that file,
2803" then removes that file.
2804fun! netrw#NetSource(...)
2805" call Dfunc("netrw#NetSource() a:0=".a:0)
2806 if a:0 > 0 && a:1 == '?'
2807 " give help
2808 echomsg 'NetSource Usage:'
2809 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2810 echomsg ':Nsource fetch://machine/path uses fetch'
2811 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002812 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002813 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2814 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2815 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2816 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2817 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002818 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002819 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002820 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002821 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002822" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002823 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002824" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002825 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002826" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002827 if delete(s:netrw_tmpfile)
2828 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2829 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002830 unlet s:netrw_tmpfile
2831 else
2832 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2833 endif
2834 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002835 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002836 endif
2837" call Dret("netrw#NetSource")
2838endfun
2839
Bram Moolenaar8d043172014-01-23 14:24:41 +01002840" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002841" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2842" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002843fun! netrw#SetTreetop(iscmd,...)
2844" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2845" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002846
Bram Moolenaar85850f32019-07-19 22:05:51 +02002847 " iscmd==0: netrw#SetTreetop called using gn mapping
2848 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2849" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002850 " clear out the current tree
2851 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002852" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002853 let inittreetop= w:netrw_treetop
2854 unlet w:netrw_treetop
2855 endif
2856 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002857" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002858 unlet w:netrw_treedict
2859 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002860" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002861
Bram Moolenaar85850f32019-07-19 22:05:51 +02002862 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002863 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002864" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002865 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002866 if isdirectory(s:NetrwFile(a:1))
2867" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002868 let treedir = a:1
2869 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002870 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002871 let treedir = b:netrw_curdir."/".a:1
2872 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002873" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002874 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002875 " normally the cursor is left in the message window.
2876 " However, here this results in the directory being listed in the message window, which is not wanted.
2877 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002878 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002879 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002880 let treedir = "."
2881 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002882 endif
2883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002884" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002885
2886 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002887 let islocal= expand("%") !~ '^\a\{3,}://'
2888" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002889
2890 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002891 if islocal
2892 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2893 else
2894 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2895 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002896
Bram Moolenaara6878372014-03-22 21:02:50 +01002897" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002898endfun
2899
Bram Moolenaar9964e462007-05-05 17:54:07 +00002900" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002901" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002902" readcmd == %r : replace buffer with newly read file
2903" == 0r : read file at top of buffer
2904" == r : read file after current line
2905" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002906fun! s:NetrwGetFile(readcmd, tfile, method)
2907" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002908
2909 " readcmd=='t': simply do nothing
2910 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002911" 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 +01002912" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002913 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002914 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002915
Bram Moolenaar9964e462007-05-05 17:54:07 +00002916 " get name of remote filename (ie. url and all)
2917 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002918" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002919
Bram Moolenaar9964e462007-05-05 17:54:07 +00002920 if exists("*NetReadFixup")
2921 " for the use of NetReadFixup (not otherwise used internally)
2922 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002923 endif
2924
Bram Moolenaar9964e462007-05-05 17:54:07 +00002925 if a:readcmd[0] == '%'
2926 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002927" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002928
2929 " rename the current buffer to the temp file (ie. tfile)
2930 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002931 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002932 else
2933 let tfile= a:tfile
2934 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002935 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002936
2937 " edit temporary file (ie. read the temporary file in)
2938 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002939" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002940 call zip#Browse(tfile)
2941 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002942" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002943 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002944 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002945" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002946 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002947 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002948" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002949 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002950 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002951" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002952 call tar#Browse(tfile)
2953 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002954" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002955 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002956 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002957" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002958 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002959 endif
2960
2961 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002962 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002963
Bram Moolenaar71badf92023-04-22 22:40:14 +01002964 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002965 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002966 " Note that isk must not include a "/" for scripts.vim
2967 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002968" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2969" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002970" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002971" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2972 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002973 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002974 filetype detect
2975" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002976 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002977" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002978 let line1 = 1
2979 let line2 = line("$")
2980
Bram Moolenaar8d043172014-01-23 14:24:41 +01002981 elseif !&ma
2982 " 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 +01002983 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002984" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002985 return
2986
Bram Moolenaar9964e462007-05-05 17:54:07 +00002987 elseif s:FileReadable(a:tfile)
2988 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002989" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002990 let curline = line(".")
2991 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002992" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002993 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002994 let line1= curline + 1
2995 let line2= line("$") - lastline + 1
2996
2997 else
2998 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002999" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3000" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003001 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003002" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003003 return
3004 endif
3005
3006 " User-provided (ie. optional) fix-it-up command
3007 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003008" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003009 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003010" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003011" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003012 endif
3013
Bram Moolenaaradc21822011-04-01 18:03:16 +02003014 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003015 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003016 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003017 endif
3018
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003019" 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 +00003020
3021 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003022" redraw!
3023
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003024" 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 +00003025" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003026endfun
3027
Bram Moolenaar9964e462007-05-05 17:54:07 +00003028" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003029" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003030" Input:
3031" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3032" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003033" b:netrw_method= 1: rcp
3034" 2: ftp + <.netrc>
3035" 3: ftp + machine, id, password, and [path]filename
3036" 4: scp
3037" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003038" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003039" 7: rsync
3040" 8: fetch
3041" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003042" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003043" g:netrw_machine= hostname
3044" b:netrw_fname = filename
3045" g:netrw_port = optional port number (for ftp)
3046" g:netrw_choice = copy of input url (choice)
3047fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003048" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003049
Bram Moolenaar251e1912011-06-19 05:09:16 +02003050 " sanity check: choice should have at least three slashes in it
3051 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3052 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3053 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003054" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003055 return
3056 endif
3057
Bram Moolenaar5c736222010-01-06 20:54:52 +01003058 " record current g:netrw_machine, if any
3059 " curmachine used if protocol == ftp and no .netrc
3060 if exists("g:netrw_machine")
3061 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003062" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003063 else
3064 let curmachine= "N O T A HOST"
3065 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003066 if exists("g:netrw_port")
3067 let netrw_port= g:netrw_port
3068 endif
3069
3070 " insure that netrw_ftp_cmd starts off every method determination
3071 " with the current g:netrw_ftp_cmd
3072 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003073
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003074 " initialization
3075 let b:netrw_method = 0
3076 let g:netrw_machine = ""
3077 let b:netrw_fname = ""
3078 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003079 let g:netrw_choice = a:choice
3080
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003081 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003082 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003083 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3084 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003085 " rcpurm : rcp://[user@]host/filename Use rcp
3086 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003087 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003088 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003089 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003090 " rsyncurm : rsync://host[:port]/path Use rsync
3091 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3092 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003093 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003094 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3095 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003096 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3097 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003098 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003099 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003100 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003101 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003102 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003103 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003104 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003105 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003106
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003107" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003108 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003109 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003110 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003111" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003112 let b:netrw_method = 1
3113 let userid = substitute(a:choice,rcpurm,'\1',"")
3114 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3115 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 if userid != ""
3117 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003119
Bram Moolenaaradc21822011-04-01 18:03:16 +02003120 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003121 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003122" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003123 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003124 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3125 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3126 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003127
Bram Moolenaar15146672011-10-20 22:22:38 +02003128 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003130" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003131 let b:netrw_method = 5
3132 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3133 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003134 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003135
Bram Moolenaaradc21822011-04-01 18:03:16 +02003136 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003137 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003138" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003140 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003141 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3142 else
3143 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3144 endif
3145 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003146
Bram Moolenaaradc21822011-04-01 18:03:16 +02003147 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003148 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003149" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003150 let b:netrw_method = 7
3151 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3152 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003153
Bram Moolenaaradc21822011-04-01 18:03:16 +02003154 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003155 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003156" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003157 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003158 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3159 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3160 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003161" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003162 if userid != ""
3163 let g:netrw_uid= userid
3164 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003165
Bram Moolenaaradc21822011-04-01 18:03:16 +02003166 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003167 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003168 call NetUserPass("ftp:".g:netrw_machine)
3169 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003170 " if there's a change in hostname, require password re-entry
3171 unlet s:netrw_passwd
3172 endif
3173 if exists("netrw_port")
3174 unlet netrw_port
3175 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003176 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003177
Bram Moolenaar446cb832008-06-24 21:56:24 +00003178 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003179 let b:netrw_method = 3
3180 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003181 let host= substitute(g:netrw_machine,'\..*$','','')
3182 if exists("s:netrw_hup[host]")
3183 call NetUserPass("ftp:".host)
3184
Nir Lichtman1e34b952024-05-08 19:19:34 +02003185 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003186" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3187" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003188 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003189 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003190" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003191 endif
3192 let b:netrw_method= 2
3193 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003194" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003195 let b:netrw_method= 2
3196 else
3197 if !exists("g:netrw_uid") || g:netrw_uid == ""
3198 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003199 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003200 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003201 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003202 endif
3203 let b:netrw_method= 3
3204 endif
3205 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003206
Bram Moolenaaradc21822011-04-01 18:03:16 +02003207 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003208 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003209" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003210 let b:netrw_method = 8
3211 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3212 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3213 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3214 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003215
Bram Moolenaaradc21822011-04-01 18:03:16 +02003216 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003217 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003218" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003220 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3221 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003222 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003223 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003224 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003225
Bram Moolenaaradc21822011-04-01 18:03:16 +02003226 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003227 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003228" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003229 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003230 let b:netrw_method = 3
3231 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3232 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003233
Bram Moolenaar9964e462007-05-05 17:54:07 +00003234 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003235 let b:netrw_method = 2
3236 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3237 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3238 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003239
Bram Moolenaaradc21822011-04-01 18:03:16 +02003240 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003241 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003242" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003243 let b:netrw_method = 9
3244 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3245 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003246
Bram Moolenaaradc21822011-04-01 18:03:16 +02003247 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003248 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003249" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003250 let b:netrw_method = 1
3251 let userid = substitute(a:choice,rcphf,'\2',"")
3252 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3253 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003254" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3255" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3256" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3257" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003258 if userid != ""
3259 let g:netrw_uid= userid
3260 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003261
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003262 " Method#10: file://user@hostname/...path-to-file {{{3
3263 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003264" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003265 let b:netrw_method = 10
3266 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003267" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003268
Bram Moolenaaradc21822011-04-01 18:03:16 +02003269 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003270 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003271 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003272 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003273 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003274 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003276 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003277
Bram Moolenaar81695252004-12-29 20:58:21 +00003278 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003279 " remove any leading [:#] from port number
3280 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3281 elseif exists("netrw_port")
3282 " retain port number as implicit for subsequent ftp operations
3283 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003284 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003285
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003286" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3287" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3288" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3289" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003290" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003291" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003292" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003293" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003294" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003295" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003296" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003297" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003299
Bram Moolenaar9964e462007-05-05 17:54:07 +00003300" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003301" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003302" Usage: :call NetUserPass() -- will prompt for userid and password
3303" :call NetUserPass("uid") -- will prompt for password
3304" :call NetUserPass("uid","password") -- sets global userid and password
3305" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3306" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307fun! NetUserPass(...)
3308
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003309" call Dfunc("NetUserPass() a:0=".a:0)
3310
3311 if !exists('s:netrw_hup')
3312 let s:netrw_hup= {}
3313 endif
3314
Bram Moolenaar071d4272004-06-13 20:20:40 +00003315 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003316 " case: no input arguments
3317
3318 " change host and username if not previously entered; get new password
3319 if !exists("g:netrw_machine")
3320 let g:netrw_machine= input('Enter hostname: ')
3321 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003323 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003324 let g:netrw_uid= input('Enter username: ')
3325 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003326 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003327 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003328
3329 " set up hup database
3330 let host = substitute(g:netrw_machine,'\..*$','','')
3331 if !exists('s:netrw_hup[host]')
3332 let s:netrw_hup[host]= {}
3333 endif
3334 let s:netrw_hup[host].uid = g:netrw_uid
3335 let s:netrw_hup[host].passwd = s:netrw_passwd
3336
3337 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003338 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003339
3340 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003341 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003342 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003343" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003344 let host = substitute(a:1,'^ftp:','','')
3345 let host = substitute(host,'\..*','','')
3346 if exists("s:netrw_hup[host]")
3347 let g:netrw_uid = s:netrw_hup[host].uid
3348 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003349" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3350" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003351 else
3352 let g:netrw_uid = input("Enter UserId: ")
3353 let s:netrw_passwd = inputsecret("Enter Password: ")
3354 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003355
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003356 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003357 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003358" 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 +02003359 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003360 if g:netrw_machine =~ '[0-9.]\+'
3361 let host= g:netrw_machine
3362 else
3363 let host= substitute(g:netrw_machine,'\..*$','','')
3364 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003365 else
3366 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003367 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003368 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003369" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003370 if exists("g:netrw_passwd")
3371 " ask for password if one not previously entered
3372 let s:netrw_passwd= g:netrw_passwd
3373 else
3374 let s:netrw_passwd = inputsecret("Enter Password: ")
3375 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003376 endif
3377
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003378" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003379 if exists("host")
3380 if !exists('s:netrw_hup[host]')
3381 let s:netrw_hup[host]= {}
3382 endif
3383 let s:netrw_hup[host].uid = g:netrw_uid
3384 let s:netrw_hup[host].passwd = s:netrw_passwd
3385 endif
3386
3387 elseif a:0 == 2
3388 let g:netrw_uid = a:1
3389 let s:netrw_passwd = a:2
3390
3391 elseif a:0 == 3
3392 " enter hostname, user-id, and password into the hup dictionary
3393 let host = substitute(a:1,'^\a\+:','','')
3394 let host = substitute(host,'\..*$','','')
3395 if !exists('s:netrw_hup[host]')
3396 let s:netrw_hup[host]= {}
3397 endif
3398 let s:netrw_hup[host].uid = a:2
3399 let s:netrw_hup[host].passwd = a:3
3400 let g:netrw_uid = s:netrw_hup[host].uid
3401 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003402" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3403" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003405
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003406" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408
Bram Moolenaar85850f32019-07-19 22:05:51 +02003409" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003410" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003411" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003413" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003414" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3415fun! s:ExplorePatHls(pattern)
3416" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3417 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003418" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003419 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003420" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003421 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3422" call Dret("s:ExplorePatHls repat<".repat.">")
3423 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003424endfun
3425
3426" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003427" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003428" 0: (user: <mb>) bookmark current directory
3429" 1: (user: <gb>) change to the bookmarked directory
3430" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003431" 3: (browsing) records current directory history
3432" 4: (user: <u>) go up (previous) directory, using history
3433" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003434" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003435fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003436" 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 +02003437 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3438" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3439 return
3440 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003441
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003442 let ykeep = @@
3443 let curbufnr = bufnr("%")
3444
Bram Moolenaar9964e462007-05-05 17:54:07 +00003445 if a:chg == 0
3446 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003447" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003448 if exists("s:netrwmarkfilelist_{curbufnr}")
3449 call s:NetrwBookmark(0)
3450 echo "bookmarked marked files"
3451 else
3452 call s:MakeBookmark(a:curdir)
3453 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003454 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003455
KSR-Yasudaf4498252023-10-06 03:34:17 +09003456 try
3457 call s:NetrwBookHistSave()
3458 catch
3459 endtry
3460
Bram Moolenaar9964e462007-05-05 17:54:07 +00003461 elseif a:chg == 1
3462 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003463" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003464 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003465" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003466 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003467 else
3468 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3469 endif
3470
3471 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003472" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003473 let didwork= 0
3474 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003475" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003476 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003477" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003478 let cnt= 1
3479 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003480" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003481 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003482 let didwork = 1
3483 let cnt = cnt + 1
3484 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003485 endif
3486
3487 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003488 " Note: history is saved only when PerformListing is done;
3489 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3490 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003491 let first = 1
3492 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003493 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003494 while ( first || cnt != g:netrw_dirhistcnt )
3495" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003496 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003497" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003498 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003499 let didwork= 1
3500 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003501 let histcnt = histcnt + 1
3502 let first = 0
3503 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003504 if cnt < 0
3505 let cnt= cnt + g:netrw_dirhistmax
3506 endif
3507 endwhile
3508 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003509 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003510 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003511 if didwork
3512 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3513 endif
3514
3515 elseif a:chg == 3
3516 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003517" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003518 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 +02003519 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003520 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3521 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003522 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003523" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003524 endif
3525
3526 elseif a:chg == 4
3527 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003528" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003529 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003530 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3531 if g:netrw_dirhistcnt < 0
3532 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003533 endif
3534 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003535 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003536 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003537 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3538" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003539 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003540 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003541" call Decho("setl ma noro",'~'.expand("<slnum>"))
3542 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003543 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003544" call Decho("setl nomod",'~'.expand("<slnum>"))
3545" 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 +00003546 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003547" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3548 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003549 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003550 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003551 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003552 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003553 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003554 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003555 echo "Sorry, no predecessor directory exists yet"
3556 endif
3557
3558 elseif a:chg == 5
3559 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003560" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003561 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003562 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3563 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3564" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003565 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003566" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003567 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003568 sil! NetrwKeepj %d _
3569" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3570" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003571 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003572" 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 +02003573 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003574" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3575 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003576 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003577 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3578 if g:netrw_dirhistcnt < 0
3579 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003580 endif
3581 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003582 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003583 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003584 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003585 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003586 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003587
3588 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003589" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003590 if exists("s:netrwmarkfilelist_{curbufnr}")
3591 call s:NetrwBookmark(1)
3592 echo "removed marked files from bookmarks"
3593 else
3594 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003595 let iremove = v:count
3596 let dremove = g:netrw_bookmarklist[iremove - 1]
3597" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003598 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003599" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3600 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3601 echo "removed ".dremove." from g:netrw_bookmarklist"
3602" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003603 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003604" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003605
3606 try
3607 call s:NetrwBookHistSave()
3608 catch
3609 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003610 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003611 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003612 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003613 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003614" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003615endfun
3616
3617" ---------------------------------------------------------------------
3618" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003619" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003620" Sister function: s:NetrwBookHistSave()
3621fun! s:NetrwBookHistRead()
3622" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003623 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003624" 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 +02003625 return
3626 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003627 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003628
3629 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003630 if !exists("s:netrw_initbookhist")
3631 let home = s:NetrwHome()
3632 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003633 if filereadable(s:NetrwFile(savefile))
3634" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003635 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003636 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003637
3638 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003639 if g:netrw_dirhistmax > 0
3640 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003641 if filereadable(s:NetrwFile(savefile))
3642" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003643 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003644 endif
3645 let s:netrw_initbookhist= 1
3646 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003647 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003648 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003649
Bram Moolenaar97d62492012-11-15 21:28:22 +01003650 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003651" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3652" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003653" call Dret("s:NetrwBookHistRead")
3654endfun
3655
3656" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003657" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003658" Sister function: s:NetrwBookHistRead()
3659" I used to do this via viminfo but that appears to
3660" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003661" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3662" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003663" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003664fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003665" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003666 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003667" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003668 return
3669 endif
3670
Bram Moolenaar5c736222010-01-06 20:54:52 +01003671 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003672" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003673 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003674
3675 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003676 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003677" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003678 if g:netrw_use_noswf
3679 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3680 else
3681 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3682 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003683 setl nocin noai noci magic nospell nohid wig= noaw
3684 setl ma noro write
3685 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003686 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003687
Bram Moolenaar85850f32019-07-19 22:05:51 +02003688 " rename enew'd file: .netrwhist -- no attempt to merge
3689 " record dirhistmax and current dirhistcnt
3690 " save history
3691" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003692 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003693 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003694 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3695 if g:netrw_dirhistmax > 0
3696 let lastline = line("$")
3697 let cnt = g:netrw_dirhistcnt
3698 let first = 1
3699 while ( first || cnt != g:netrw_dirhistcnt )
3700 let lastline= lastline + 1
3701 if exists("g:netrw_dirhist_{cnt}")
3702 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3703" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3704 endif
3705 let first = 0
3706 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3707 if cnt < 0
3708 let cnt= cnt + g:netrw_dirhistmax
3709 endif
3710 endwhile
3711 exe "sil! w! ".savefile
3712" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3713 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003714
Bram Moolenaar85850f32019-07-19 22:05:51 +02003715 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003716 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003717 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003718" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003719 " merge and write .netrwbook
3720 let savefile= s:NetrwHome()."/.netrwbook"
3721
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003722 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003723 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003724 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003725 for bdm in booklist
3726 if index(g:netrw_bookmarklist,bdm) == -1
3727 call add(g:netrw_bookmarklist,bdm)
3728 endif
3729 endfor
3730 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003731 endif
3732
3733 " construct and save .netrwbook
3734 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003735 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003736" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003737 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003738
3739 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003740 let bgone= bufnr("%")
3741 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003742 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003743
3744" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003745endfun
3746
3747" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003748" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3749" list of the contents of a local or remote directory. It is assumed that the
3750" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3751" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003752" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003753fun! s:NetrwBrowse(islocal,dirname)
3754 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003755" 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 +02003756" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3757" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3758" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003759
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003760 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3761 " This is useful when one edits a local file, then :e ., then :Rex
3762 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3763 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003764" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003765 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003766
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003767 " s:NetrwBrowse : initialize history {{{3
3768 if !exists("s:netrw_initbookhist")
3769 NetrwKeepj call s:NetrwBookHistRead()
3770 endif
3771
3772 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003773 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003774 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003775" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003776 else
3777 let dirname= a:dirname
3778 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003779
Bram Moolenaar85850f32019-07-19 22:05:51 +02003780 " repoint t:netrw_lexbufnr if appropriate
3781 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3782" call Decho("set repointlexbufnr to true!")
3783 let repointlexbufnr= 1
3784 endif
3785
3786 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003787 if exists("s:netrw_skipbrowse")
3788 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003789" 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 +01003790" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003791 return
3792 endif
3793 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003794 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003795" call Dret("s:NetrwBrowse : missing shellescape()")
3796 return
3797 endif
3798 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003799 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003800" call Dret("s:NetrwBrowse : missing fnameescape()")
3801 return
3802 endif
3803
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003804 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003805 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003806
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003807 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003808 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3809 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3810" call Decho("clearing marked files",'~'.expand("<slnum>"))
3811 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3812 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003813 endif
3814
3815 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003816 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003817" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3818" 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 +02003819 if s:NetrwLcd(dirname)
3820" call Dret("s:NetrwBrowse : lcd failure")
3821 return
3822 endif
3823 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003824" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003825
Bram Moolenaar5c736222010-01-06 20:54:52 +01003826 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003827 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003828" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003829 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003830" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003831 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003832 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003833 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003834" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003835
3836 " remove any filetype indicator from end of dirname, except for the
3837 " "this is a directory" indicator (/).
3838 " There shouldn't be one of those here, anyway.
3839 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003840" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003841 call s:RemotePathAnalysis(dirname)
3842
3843 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3844 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003845 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003846 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003847" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003848 let b:netrw_curdir = dirname
3849 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003850 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003851 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3852 sil call netrw#NetRead(2,url)
3853 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003854" call Decho("url<".url.">",'~'.expand("<slnum>"))
3855" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3856" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003857 if s:path =~ '.bz2'
3858 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3859 elseif s:path =~ '.gz'
3860 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3861 elseif s:path =~ '.gz'
3862 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3863 else
3864 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3865 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003866 endif
3867
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003868 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003869 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003870 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003871" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003872 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003873" 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 +00003874
Bram Moolenaar446cb832008-06-24 21:56:24 +00003875" call Dret("s:NetrwBrowse : file<".s:fname.">")
3876 return
3877 endif
3878
Bram Moolenaaradc21822011-04-01 18:03:16 +02003879 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003880 call s:UseBufWinVars()
3881
3882 " set up some variables {{{3
3883 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003884 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003885 let s:last_sort_by = g:netrw_sort_by
3886
3887 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003888 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003889
Bram Moolenaar97d62492012-11-15 21:28:22 +01003890 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003891" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003892 let svpos = winsaveview()
3893" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003894 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003895
Bram Moolenaar446cb832008-06-24 21:56:24 +00003896 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003897 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3898 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3899" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3900" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3901 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3902 else
3903" " call Decho("2match none",'~'.expand("<slnum>"))
3904 2match none
3905 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003906 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003907 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003908 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003909" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003910 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003911" 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 +01003912" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003913 return
3914 endif
3915
3916 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003917" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003918 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003919 if b:netrw_curdir =~ '[/\\]$'
3920 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3921 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003922 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003923 let b:netrw_curdir= b:netrw_curdir."/"
3924 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003925 if b:netrw_curdir == ''
3926 if has("amiga")
3927 " On the Amiga, the empty string connotes the current directory
3928 let b:netrw_curdir= getcwd()
3929 else
3930 " under unix, when the root directory is encountered, the result
3931 " from the preceding substitute is an empty string.
3932 let b:netrw_curdir= '/'
3933 endif
3934 endif
3935 if !a:islocal && b:netrw_curdir !~ '/$'
3936 let b:netrw_curdir= b:netrw_curdir.'/'
3937 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003938" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003939
3940 " ------------
3941 " (local only) {{{3
3942 " ------------
3943 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003945
3946 " Set up ShellCmdPost handling. Append current buffer to browselist
3947 call s:LocalFastBrowser()
3948
3949 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3950 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003951" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3952" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003953 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003954 if s:NetrwLcd(b:netrw_curdir)
3955" call Dret("s:NetrwBrowse : lcd failure")
3956 return
3957 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003958 endif
3959 endif
3960
3961 " --------------------------------
3962 " remote handling: {{{3
3963 " --------------------------------
3964 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003965" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003966
Bram Moolenaar97d62492012-11-15 21:28:22 +01003967 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003968" 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 +02003969 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003970 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003971" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003972 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3973 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3974 if dirname !~ '/$'
3975 let dirname= dirname.'/'
3976 endif
3977 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003978" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003979 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003980 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003981" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003982 endif
3983
3984 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3985 if dirname !~ dirpat
3986 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003987 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003988 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003989 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003990" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003991 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003992" 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 +00003993" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3994 return
3995 endif
3996 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003997" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003998 endif " (additional remote handling)
3999
Bram Moolenaar85850f32019-07-19 22:05:51 +02004000 " -------------------------------
4001 " Perform Directory Listing: {{{3
4002 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004003 NetrwKeepj call s:NetrwMaps(a:islocal)
4004 NetrwKeepj call s:NetrwCommands(a:islocal)
4005 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004006
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004007 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004008 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004009" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4010
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004011 " If there is a rexposn: restore position with rexposn
4012 " Otherwise : set rexposn
4013 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004014" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4015 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4016 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4017 NetrwKeepj exe w:netrw_bannercnt
4018 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004019 else
4020 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4021 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004022 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004023 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004024" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004025 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004026 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004027
Bram Moolenaar85850f32019-07-19 22:05:51 +02004028 " repoint t:netrw_lexbufnr if appropriate
4029 if exists("repointlexbufnr")
4030 let t:netrw_lexbufnr= bufnr("%")
4031" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4032 endif
4033
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004034 " restore position
4035 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004036" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4037 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004038 endif
4039
Bram Moolenaara6878372014-03-22 21:02:50 +01004040 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004041 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4042 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004043" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4044" 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 +02004045" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004046 return
4047endfun
4048
4049" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004050" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4051" may not apply correctly; ie. netrw's idea of the current directory may
4052" differ from vim's. This function insures that netrw's idea of the current
4053" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004054" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004055fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004056" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4057" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4058" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4059" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4060" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004061
4062 " clean up any leading treedepthstring
4063 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4064 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004065" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004066 else
4067 let fname= a:fname
4068 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004069
4070 if g:netrw_keepdir
4071 " vim's idea of the current directory possibly may differ from netrw's
4072 if !exists("b:netrw_curdir")
4073 let b:netrw_curdir= getcwd()
4074 endif
4075
Nir Lichtman1e34b952024-05-08 19:19:34 +02004076 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004077 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004078 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004079 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004080" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004081 else
4082 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004083 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004084" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004085 endif
4086
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004087 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004088 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004089 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004090" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004091 else
4092 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004093 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004094" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004095 endif
4096 else
4097 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004098 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004099" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4100" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4101" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004102 endif
4103
Bram Moolenaar85850f32019-07-19 22:05:51 +02004104" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004105 return ret
4106endfun
4107
4108" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004109" s:NetrwFileInfo: supports qf (query for file information) {{{2
4110fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004111" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004112 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004113 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004114 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004115 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004116 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004117 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004118 let lsopt= "-lsadh --si"
4119 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004120" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004121 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004122
4123 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004124 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004125" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004126
Bram Moolenaara6878372014-03-22 21:02:50 +01004127 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004128 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004129" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004130
4131 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004132 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004133" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004134
Bram Moolenaar446cb832008-06-24 21:56:24 +00004135 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004136" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004137 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004138" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004139 endif
4140 else
4141 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004142" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4143 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004144 let fname= substitute(a:fname,".$","","")
4145 else
4146 let fname= a:fname
4147 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004148 let t = getftime(s:NetrwFile(fname))
4149 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004150 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 let sz= s:NetrwHumanReadable(sz)
4152 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004153 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4154" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004155 endif
4156 else
4157 echo "sorry, \"qf\" not supported yet for remote files"
4158 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004159 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004160" call Dret("s:NetrwFileInfo")
4161endfun
4162
4163" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004164" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4165fun! s:NetrwFullPath(filename)
4166" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4167 let filename= a:filename
4168 if filename !~ '^/'
4169 let filename= resolve(getcwd().'/'.filename)
4170 endif
4171 if filename != "/" && filename =~ '/$'
4172 let filename= substitute(filename,'/$','','')
4173 endif
4174" " call Dret("s:NetrwFullPath <".filename.">")
4175 return filename
4176endfun
4177
4178" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004179" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004180" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004181" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004182" 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 +00004183fun! s:NetrwGetBuffer(islocal,dirname)
4184" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004185" 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 +02004186" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4187" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004188 let dirname= a:dirname
4189
4190 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004191" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004192 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004193" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004194 let s:netrwbuf= {}
4195 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004196" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4197" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4198
4199 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4200 let bufnum = -1
4201
4202 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4203 if has_key(s:netrwbuf,"NetrwTreeListing")
4204 let bufnum= s:netrwbuf["NetrwTreeListing"]
4205 else
4206 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4207 endif
4208" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4209 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004210 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004211 let bufnum= -1
4212 endif
4213 elseif bufnr("NetrwTreeListing") != -1
4214 let bufnum= bufnr("NetrwTreeListing")
4215" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4216 else
4217" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4218 let bufnum= -1
4219 endif
4220
4221 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004222 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004223" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004224 if !bufexists(bufnum)
4225 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4226 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004227 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004228
Bram Moolenaar446cb832008-06-24 21:56:24 +00004229 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004230" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004231 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004232 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004233" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4234
Bram Moolenaar71badf92023-04-22 22:40:14 +01004235 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004236 " IF the buffer already has the desired name
4237 " AND it is empty
4238 let curbuf = bufname("%")
4239 if curbuf == '.'
4240 let curbuf = getcwd()
4241 endif
4242" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004243" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004244" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4245" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4246" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4247" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4248 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004249" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4250 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004251 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004252" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004253 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004254 " 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 +00004255
4256 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004257 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004258" 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 +00004259 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004260" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004261 " name the buffer
4262 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4263 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004264" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004265 let w:netrw_treebufnr = bufnr("%")
4266 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004267 if g:netrw_use_noswf
4268 setl nobl bt=nofile noswf
4269 else
4270 setl nobl bt=nofile
4271 endif
4272 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4273 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4274 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4275 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004276" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004277 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004278 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004279 " enter the new buffer into the s:netrwbuf dictionary
4280 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4281" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4282" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004283 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004284" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004285
4286 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004287" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004288 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004289 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004290 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004291
4292 if &ft == "netrw"
4293" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4294 exe "sil! NetrwKeepj noswapfile b ".bufnum
4295" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004296 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004297" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4298 call s:NetrwEditBuf(bufnum)
4299" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004300 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004301" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004302 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004303 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004304 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004305
4306 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004307 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004308
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004309 if line("$") <= 1 && getline(1) == ""
4310 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004311 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004312" 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>"))
4313" 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 +01004314" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4315 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004316
Bram Moolenaar97d62492012-11-15 21:28:22 +01004317 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004318" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004319 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004320 sil NetrwKeepj %d _
4321" 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>"))
4322" 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 +01004323" 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 +00004324 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004325
Bram Moolenaar446cb832008-06-24 21:56:24 +00004326 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004327" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4328" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004329 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004330 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004331 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004332" 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>"))
4333" 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 +01004334" 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 +00004335 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004336
Bram Moolenaar446cb832008-06-24 21:56:24 +00004337 else
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 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004341 return 1
4342 endif
4343 endif
4344
4345 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4346 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4347 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4348 " med 1 D H
4349 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004350" 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 +00004351 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004352 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004353 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004354
4355 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004356" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4357" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4358 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004359
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004360" 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>"))
4361" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4362" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004363 return 0
4364endfun
4365
4366" ---------------------------------------------------------------------
4367" s:NetrwGetcwd: get the current directory. {{{2
4368" Change backslashes to forward slashes, if any.
4369" If doesc is true, escape certain troublesome characters
4370fun! s:NetrwGetcwd(doesc)
4371" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4372 let curdir= substitute(getcwd(),'\\','/','ge')
4373 if curdir !~ '[\/]$'
4374 let curdir= curdir.'/'
4375 endif
4376 if a:doesc
4377 let curdir= fnameescape(curdir)
4378 endif
4379" call Dret("NetrwGetcwd <".curdir.">")
4380 return curdir
4381endfun
4382
4383" ---------------------------------------------------------------------
4384" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4385fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004386" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4387" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4388 let keepsol= &l:sol
4389 setl nosol
4390
Bram Moolenaar446cb832008-06-24 21:56:24 +00004391 call s:UseBufWinVars()
4392
4393 " insure that w:netrw_liststyle is set up
4394 if !exists("w:netrw_liststyle")
4395 if exists("g:netrw_liststyle")
4396 let w:netrw_liststyle= g:netrw_liststyle
4397 else
4398 let w:netrw_liststyle= s:THINLIST
4399 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004400" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004401 endif
4402
4403 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4404 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004405" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004406 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004407 let dirname= "./"
4408 let curline= getline('.')
4409
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004410 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004411 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004412 let s:netrw_skipbrowse= 1
4413 echo 'Pressing "s" also works'
4414
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004415 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004416 let s:netrw_skipbrowse= 1
4417 echo 'Press "S" to edit sorting sequence'
4418
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004419 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004420 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004421 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004422
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004423 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004424 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004425 let s:netrw_skipbrowse= 1
4426 echo 'Pressing "a" also works'
4427
4428 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004429 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004430 endif
4431
4432 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004433" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004434 NetrwKeepj norm! 0
4435 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004436
4437 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004438" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004439 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4441
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004442 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004443" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004444 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004445 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004446
4447 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004448" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004449 let dirname= getline('.')
4450
4451 if !exists("b:netrw_cpf")
4452 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004453 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 +01004454 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004455" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004456 endif
4457
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004458" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004459 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004460" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4461" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004462 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004463 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004464 else
4465 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004466 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004467 endif
Enno3146d632024-07-04 19:44:42 +02004468
4469 let dict={}
4470 " save the unnamed register and register 0-9 and a
4471 let dict.a=[getreg('a'), getregtype('a')]
4472 for i in range(0, 9)
4473 let dict[i] = [getreg(i), getregtype(i)]
4474 endfor
4475 let dict.unnamed = [getreg(''), getregtype('')]
4476
Bram Moolenaarc236c162008-07-13 17:41:49 +00004477 let eofname= filestart + b:netrw_cpf + 1
4478 if eofname <= col("$")
4479 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004480 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004481 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004482 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004483 endif
Enno3146d632024-07-04 19:44:42 +02004484
Bram Moolenaar446cb832008-06-24 21:56:24 +00004485 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004486 call s:RestoreRegister(dict)
4487
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004488" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004490" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004491 endif
4492
4493 " symlinks are indicated by a trailing "@". Remove it before further processing.
4494 let dirname= substitute(dirname,"@$","","")
4495
4496 " executables are indicated by a trailing "*". Remove it before further processing.
4497 let dirname= substitute(dirname,"\*$","","")
4498
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004499 let &l:sol= keepsol
4500
Bram Moolenaar446cb832008-06-24 21:56:24 +00004501" call Dret("s:NetrwGetWord <".dirname.">")
4502 return dirname
4503endfun
4504
4505" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004506" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4507" g:netrw_bufsettings will be used after the listing is produced.
4508" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004509fun! s:NetrwListSettings(islocal)
4510" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004511" 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 +00004512 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004513" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4514 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4515 setl bt=nofile nobl ma nonu nowrap noro nornu
4516 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004517 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004518 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004519 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004520" call Dredir("ls!","s:NetrwListSettings")
4521" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004522 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004523 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004524 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004525 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004526 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004527 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004528 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004529" 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 +00004530" call Dret("s:NetrwListSettings")
4531endfun
4532
4533" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004534" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004535" islocal=0: remote browsing
4536" =1: local browsing
4537fun! s:NetrwListStyle(islocal)
4538" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004539
Bram Moolenaar97d62492012-11-15 21:28:22 +01004540 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004541 let fname = s:NetrwGetWord()
4542 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004543 let svpos = winsaveview()
4544" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004546" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4547" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4548" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004549
Bram Moolenaar85850f32019-07-19 22:05:51 +02004550 " repoint t:netrw_lexbufnr if appropriate
4551 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4552" call Decho("set repointlexbufnr to true!")
4553 let repointlexbufnr= 1
4554 endif
4555
Bram Moolenaar446cb832008-06-24 21:56:24 +00004556 if w:netrw_liststyle == s:THINLIST
4557 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004558" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004559 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4560
4561 elseif w:netrw_liststyle == s:LONGLIST
4562 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004563" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004564 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4565
4566 elseif w:netrw_liststyle == s:WIDELIST
4567 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004568" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004569 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4570
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004571 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004572" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004573 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4574
4575 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004576 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004577 let g:netrw_liststyle = s:THINLIST
4578 let w:netrw_liststyle = g:netrw_liststyle
4579 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4580 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004581 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004582" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004583
4584 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004585" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4586 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004587 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004588" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004589 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004590" 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 +00004591
4592 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004593" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004594 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004595 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004596
Bram Moolenaar85850f32019-07-19 22:05:51 +02004597 " repoint t:netrw_lexbufnr if appropriate
4598 if exists("repointlexbufnr")
4599 let t:netrw_lexbufnr= bufnr("%")
4600" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4601 endif
4602
Bram Moolenaar13600302014-05-22 18:26:40 +02004603 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004604" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4605 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004606 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004607
4608" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4609endfun
4610
4611" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004612" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4613fun! s:NetrwBannerCtrl(islocal)
4614" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4615
Bram Moolenaar97d62492012-11-15 21:28:22 +01004616 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004617 " toggle the banner (enable/suppress)
4618 let g:netrw_banner= !g:netrw_banner
4619
4620 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004621 let svpos= winsaveview()
4622" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004623 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4624
4625 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004626 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4627 let fname= s:NetrwGetWord()
4628 sil NetrwKeepj $
4629 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4630" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4631 if result <= 0 && exists("w:netrw_bannercnt")
4632 exe "NetrwKeepj ".w:netrw_bannercnt
4633 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004634 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004635 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004636" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4637endfun
4638
4639" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004640" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4641"
4642" No bang: enters files/directories into Netrw's bookmark system
4643" No argument and in netrw buffer:
4644" if there are marked files: bookmark marked files
4645" otherwise : bookmark file/directory under cursor
4646" No argument and not in netrw buffer: bookmarks current open file
4647" Has arguments: globs them individually and bookmarks them
4648"
4649" With bang: deletes files/directories from Netrw's bookmark system
4650fun! s:NetrwBookmark(del,...)
4651" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4652 if a:0 == 0
4653 if &ft == "netrw"
4654 let curbufnr = bufnr("%")
4655
4656 if exists("s:netrwmarkfilelist_{curbufnr}")
4657 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004658" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004659 let svpos = winsaveview()
4660" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004661 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004662 for fname in s:netrwmarkfilelist_{curbufnr}
4663 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4664 endfor
4665 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4666 call s:NetrwUnmarkList(curbufnr,curdir)
4667 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004668" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4669 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004670 else
4671 let fname= s:NetrwGetWord()
4672 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4673 endif
4674
4675 else
4676 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004677" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004678 let fname= expand("%")
4679 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4680 endif
4681
4682 else
4683 " bookmark specified files
4684 " attempts to infer if working remote or local
4685 " by deciding if the current file begins with an url
4686 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004687 let islocal= expand("%") !~ '^\a\{3,}://'
4688" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004689 let i = 1
4690 while i <= a:0
4691 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004692 if v:version > 704 || (v:version == 704 && has("patch656"))
4693 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004694 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004695 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004696 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004697 else
4698 let mbfiles= [a:{i}]
4699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004700" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004701 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004702" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004703 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4704 endfor
4705 let i= i + 1
4706 endwhile
4707 endif
4708
4709 " update the menu
4710 call s:NetrwBookmarkMenu()
4711
4712" call Dret("s:NetrwBookmark")
4713endfun
4714
4715" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004716" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4717" .2.[cnt] for bookmarks, and
4718" .3.[cnt] for history
4719" (see s:NetrwMenu())
4720fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004721 if !exists("s:netrw_menucnt")
4722 return
4723 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004724" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004725
4726 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004727 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004728 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004729" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004730 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4731 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004732 endif
4733 if !exists("s:netrw_initbookhist")
4734 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004735 endif
4736
4737 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004738 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004739 let cnt= 1
4740 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004741" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004742 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004743
4744 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004745 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004746
4747 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004748 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 +01004749 let cnt= cnt + 1
4750 endfor
4751
4752 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004753
4754 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004755 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004756 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004757 let first = 1
4758 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004759 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004760 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004761 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004762 if exists("g:netrw_dirhist_{cnt}")
4763 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004764" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004765 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4766 endif
4767 let first = 0
4768 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4769 if cnt < 0
4770 let cnt= cnt + g:netrw_dirhistmax
4771 endif
4772 endwhile
4773 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004774
Bram Moolenaar9964e462007-05-05 17:54:07 +00004775 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004776" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004777endfun
4778
4779" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004780" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4781" directory and a new directory name. Also, if the
4782" "new directory name" is actually a file,
4783" NetrwBrowseChgDir() edits the file.
4784fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004785" 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 +01004786" 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 +00004787
Bram Moolenaar97d62492012-11-15 21:28:22 +01004788 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004789 if !exists("b:netrw_curdir")
4790 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4791 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004792 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004793" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4794" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004795" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004796" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004797 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004798 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004799" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004800
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004801 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004802" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004803 call s:SavePosn(s:netrw_posn)
4804 NetrwKeepj call s:NetrwOptionsSave("s:")
4805 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004806 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004807 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004808 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004809 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004810 endif
4811 let newdir = a:newdir
4812 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004813 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004814" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004815" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004816" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004817
4818 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004819" 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 +01004820 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004821" 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 +01004822 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004823 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004824" 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 +01004825 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004826" 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 +02004827 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004828 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004829 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004830 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004831" 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 +01004832 endif
4833 endif
4834" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004835" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004836 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004837
Bram Moolenaar446cb832008-06-24 21:56:24 +00004838 " set up o/s-dependent directory recognition pattern
4839 if has("amiga")
4840 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004841 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004842 let dirpat= '[\/]$'
4843 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004844" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004845
4846 if dirname !~ dirpat
4847 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004848 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004849 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004850" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004851 endif
4852
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004853" 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 +01004854 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004855 " ------------------------------
4856 " NetrwBrowseChgDir: edit a file {{{3
4857 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004858" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004859
Bram Moolenaar97d62492012-11-15 21:28:22 +01004860 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004861 let s:rexposn_{bufnr("%")}= winsaveview()
4862" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004863" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4864" 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 +01004865
Bram Moolenaar446cb832008-06-24 21:56:24 +00004866 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004867" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4868" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004869" let newdir = s:NetrwTreePath(s:netrw_treetop)
4870" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004871 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004872 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4873" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4874 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004875 if dirname =~ '/$'
4876 let dirname= dirname.newdir
4877 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004878 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004879 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004880" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4881" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004882 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004883" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004884 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004885 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004886 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004887 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004888" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004889 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004890 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004891" 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 +02004892 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004893 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004894 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004895" " 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 +01004896 if type(g:netrw_browse_split) == 3
4897 " open file in server
4898 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004899" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004900 call s:NetrwServerEdit(a:islocal,dirname)
4901" call Dret("s:NetrwBrowseChgDir")
4902 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004903
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004904 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004905 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004906" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004907 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4908 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004909 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004910 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004911 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004912 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004913
Bram Moolenaar446cb832008-06-24 21:56:24 +00004914 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004915 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004916" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004917 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4918 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004919 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004920 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004921 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004922 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004923
Bram Moolenaar446cb832008-06-24 21:56:24 +00004924 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004925 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004926" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004927 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004928 if !exists("b:netrw_curdir")
4929 let b:netrw_curdir= getcwd()
4930 endif
4931 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004932
Bram Moolenaar446cb832008-06-24 21:56:24 +00004933 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004934 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004935" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004936 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004937 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004938" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004939 return
4940 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004941 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004942
Bram Moolenaar9964e462007-05-05 17:54:07 +00004943 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004944 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004945" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004946 call s:NetrwMenu(0)
4947 " optional change to window
4948 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004949" 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 +02004950 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004951 " if g:netrw_chgwin is set to one more than the last window, then
4952 " vertically split the last window to make that window available.
4953 let curwin= winnr()
4954 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4955 vs
4956 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004957 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004958 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004959 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004960 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004961 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004962
Bram Moolenaar9964e462007-05-05 17:54:07 +00004963 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004964
Bram Moolenaar446cb832008-06-24 21:56:24 +00004965 " the point where netrw actually edits the (local) file
4966 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004967 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004968 if !&mod
4969 " if e the new file would fail due to &mod, then don't change any of the flags
4970 let dolockout= 1
4971 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004972 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004973" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004974 " some like c-^ to return to the last edited file
4975 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004976 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4977 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004978 call s:NetrwEditFile("e","",dirname)
4979" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004980 " COMBAK -- cuc cul related
4981 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004982 if &hidden || &bufhidden == "hide"
4983 " file came from vim's hidden storage. Don't "restore" options with it.
4984 let dorestore= 0
4985 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004986 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004987" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004988 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004989
4990 " handle g:Netrw_funcref -- call external-to-netrw functions
4991 " This code will handle g:Netrw_funcref as an individual function reference
4992 " or as a list of function references. It will ignore anything that's not
4993 " a function reference. See :help Funcref for information about function references.
4994 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004995" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004996 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004997" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004998 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004999 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005000" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005001 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005002 if type(Fncref) == 2
5003 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005004 endif
5005 endfor
5006 endif
5007 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005008 endif
5009
5010 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005011 " ----------------------------------------------------
5012 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5013 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005014" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005015 let dirname = newdir
5016 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005017 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005018 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005019
5020 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005021 " ---------------------------------------------
5022 " NetrwBrowseChgDir: refresh the directory list {{{3
5023 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005024" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005025 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005026 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005027
5028 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005029 " --------------------------------------
5030 " NetrwBrowseChgDir: go up one directory {{{3
5031 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005032" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005033
5034 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5035 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005036" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5037" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005038 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005039 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005040 endif
5041
5042 if has("amiga")
5043 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005044" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005045 if a:islocal
5046 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5047 let dirname= substitute(dirname,'/$','','')
5048 else
5049 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5050 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005051" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005052
Nir Lichtman1e34b952024-05-08 19:19:34 +02005053 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005054 " windows
5055 if a:islocal
5056 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5057 if dirname == ""
5058 let dirname= '/'
5059 endif
5060 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005061 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005062 endif
5063 if dirname =~ '^\a:$'
5064 let dirname= dirname.'/'
5065 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005066" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005067
Bram Moolenaar446cb832008-06-24 21:56:24 +00005068 else
5069 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005070" 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 +00005071 if a:islocal
5072 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5073 if dirname == ""
5074 let dirname= '/'
5075 endif
5076 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005077 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005078 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005079" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005080 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005081 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005082 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005083
5084 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005085 " --------------------------------------
5086 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5087 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005088" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005089 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5090" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005091 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005092 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005093" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5094 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005095 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005096 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005097" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005098 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005099 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005100" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005101
5102 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005103" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005104 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005105" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005106 let haskey= 1
5107 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005108" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005109 endif
5110
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005111 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005112" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005113 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005114 if has_key(w:netrw_treedict,treedir."/")
5115 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005116" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005117 let haskey = 1
5118 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005119" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005120 endif
5121 endif
5122
5123 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005124" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005125 if !haskey && treedir =~ '/$'
5126 let treedir= substitute(treedir,'/$','','')
5127 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005128" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005129 let haskey = 1
5130 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005131" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132 endif
5133 endif
5134
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005135" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005136 if haskey
5137 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005138" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005139 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005140" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5141" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005142 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005143 else
5144 " go down one directory
5145 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005146" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5147" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005148 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005149 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005150" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005151 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005152
5153 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005154 " ----------------------------------------
5155 " NetrwBrowseChgDir: Go down one directory {{{3
5156 " ----------------------------------------
5157 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005158" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005159 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005160 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005161 endif
5162
Bram Moolenaar97d62492012-11-15 21:28:22 +01005163 " --------------------------------------
5164 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5165 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005166 if dorestore
5167 " dorestore is zero'd when a local file was hidden or bufhidden;
5168 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005169" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005170 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005171" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005172" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005173 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005174 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005175" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005176 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005177" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5178" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005179 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005180" 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 +02005181 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005182" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5183" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005184 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005185" 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 +02005186 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005187 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005188 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005189 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005190
Bram Moolenaar446cb832008-06-24 21:56:24 +00005191" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5192 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005193endfun
5194
5195" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005196" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5197" for thin, long, and wide: cursor placed just after banner
5198" for tree, keeps cursor on current filename
5199fun! s:NetrwBrowseUpDir(islocal)
5200" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005201 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5202 " this test needed because occasionally this function seems to be incorrectly called
5203 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005204 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005205 " directories.
5206" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5207 return
5208 endif
5209
Bram Moolenaara6878372014-03-22 21:02:50 +01005210 norm! 0
5211 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005212" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005213 let curline= getline(".")
5214 let swwline= winline() - 1
5215 if exists("w:netrw_treetop")
5216 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005217 elseif exists("b:netrw_curdir")
5218 let w:netrw_treetop= b:netrw_curdir
5219 else
5220 let w:netrw_treetop= getcwd()
5221 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005222 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005223 let curfile = getline(".")
5224 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005225 if a:islocal
5226 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5227 else
5228 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5229 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005230" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5231" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5232 if w:netrw_treetop == '/'
5233 keepj call search('^\M'.curfile,"w")
5234 elseif curfile == '../'
5235 keepj call search('^\M'.curfile,"wb")
5236 else
5237" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5238 while 1
5239 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5240 let treepath= s:NetrwTreePath(w:netrw_treetop)
5241" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5242 if treepath == curpath
5243 break
5244 endif
5245 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005246 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005247
Bram Moolenaara6878372014-03-22 21:02:50 +01005248 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005249" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005250 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005251 if exists("b:netrw_curdir")
5252 let curdir= b:netrw_curdir
5253 else
5254 let curdir= expand(getcwd())
5255 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005256 if a:islocal
5257 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5258 else
5259 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5260 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005261 call s:RestorePosn(s:netrw_posn)
5262 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005263 let curdir= '\<'. escape(curdir, '~'). '/'
5264 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005265 endif
5266" call Dret("s:NetrwBrowseUpDir")
5267endfun
5268
5269" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005270" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005271" given filename; typically this means given their extension.
5272" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005273fun! netrw#BrowseX(fname,remote)
Bram Moolenaar91359012019-11-30 17:57:03 +01005274 if a:remote == 0 && isdirectory(a:fname)
5275 " if its really just a local directory, then do a "gf" instead
Bram Moolenaar29634562020-01-09 21:46:04 +01005276 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005277 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5278 " remote directory, not a webpage access, looks like an attempt to do a directory listing
Bram Moolenaar91359012019-11-30 17:57:03 +01005279 norm! gf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005280 endif
5281
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005282 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5283 let remote = a:remote
5284 else
5285 let remote = 0
5286 endif
5287
Bram Moolenaar97d62492012-11-15 21:28:22 +01005288 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005289 let screenposn = winsaveview()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005290
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005291 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5292 let awkeep = &aw
5293 set noaw
5294
Bram Moolenaar5c736222010-01-06 20:54:52 +01005295 " special core dump handler
5296 if a:fname =~ '/core\(\.\d\+\)\=$'
5297 if exists("g:Netrw_corehandler")
5298 if type(g:Netrw_corehandler) == 2
5299 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005300 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005301 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005302 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005303 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005304 if type(Fncref) == 2
5305 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005306 endif
5307 endfor
5308 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005309 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005310 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005311 let &aw= awkeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005312 return
5313 endif
5314 endif
5315
Bram Moolenaar446cb832008-06-24 21:56:24 +00005316 " set up the filename
5317 " (lower case the extension, make a local copy of a remote file)
5318 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005319 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005320 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005321 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005322 if exten =~ "[\\/]"
5323 let exten= ""
5324 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005325
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005326 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005327 " create a local copy
Bram Moolenaarff034192013-04-24 18:51:19 +02005328 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005329 call netrw#NetRead(3,a:fname)
5330 " attempt to rename tempfile
5331 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005332 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02005333 if s:netrw_tmpfile != newname && newname != ""
5334 if rename(s:netrw_tmpfile,newname) == 0
5335 " renaming succeeded
Bram Moolenaar85850f32019-07-19 22:05:51 +02005336 let fname= newname
5337 else
5338 " renaming failed
Bram Moolenaar85850f32019-07-19 22:05:51 +02005339 let fname= s:netrw_tmpfile
5340 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005341 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005342 let fname= s:netrw_tmpfile
5343 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005344 else
5345 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005346 " special ~ handler for local
5347 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005348 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005349 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005350 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005351
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005352 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005353 if exists("g:netrw_browsex_viewer")
5354 if g:netrw_browsex_viewer =~ '\s'
5355 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5356 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5357 let oviewer = ''
5358 let cnt = 1
5359 while !executable(viewer) && viewer != oviewer
5360 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5361 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5362 let cnt = cnt + 1
5363 let oviewer = viewer
Bram Moolenaar446cb832008-06-24 21:56:24 +00005364 endwhile
5365 else
5366 let viewer = g:netrw_browsex_viewer
5367 let viewopt = ""
5368 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005369 endif
5370
Luca Saccarolaa7d45612024-10-21 21:27:03 +02005371 if exists("g:netrw_browsex_viewer") && executable(viewer)
Konfekt3d7e5672024-10-27 22:16:49 +01005372 exe 'Launch' viewer viewopt shellescape(fname, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005373 else
Konfekt3d7e5672024-10-27 22:16:49 +01005374 " though shellescape(..., 1) is used in Open, it's insufficient
5375 exe 'Open' escape(fname, '#%')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005376 endif
5377
Bram Moolenaar446cb832008-06-24 21:56:24 +00005378 " cleanup: remove temporary file,
5379 " delete current buffer if success with handler,
5380 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005381 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005382 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005383" if remote == 1 && fname != a:fname
Bram Moolenaarc236c162008-07-13 17:41:49 +00005384" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005385" endif
5386
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005387 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005388 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005389 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005390 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005391 endif
Christian Brabandt9f320692024-10-30 18:36:20 +01005392 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005393 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005394 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005395 let @@ = ykeep
5396 let &aw= awkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005397endfun
5398
5399" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005400" netrw#GX: gets word under cursor for gx support {{{2
5401" See also: netrw#BrowseXVis
5402" netrw#BrowseX
5403fun! netrw#GX()
5404" call Dfunc("netrw#GX()")
5405 if &ft == "netrw"
5406 let fname= s:NetrwGetWord()
5407 else
Konfekt3d7e5672024-10-27 22:16:49 +01005408 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005409 endif
5410" call Dret("netrw#GX <".fname.">")
5411 return fname
5412endfun
5413
Konfekt3d7e5672024-10-27 22:16:49 +01005414fun! s:GetURL() abort
5415 let URL = ''
5416 if exists('*Netrw_get_URL_' .. &filetype)
5417 let URL = call('Netrw_get_URL_' .. &filetype, [])
5418 endif
5419 if !empty(URL) | return URL | endif
5420 " URLs end in letter, digit or forward slash
5421 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5422 if !empty(URL) | return URL | endif
5423
5424 " Is it a file in the current work dir ...
5425 let file = expand("<cfile>")
5426 if filereadable(file) | return file | endif
5427 " ... or in that of the current buffer?
5428 let path = fnamemodify(expand('%'), ':p')
5429 if isdirectory(path)
5430 let dir = path
5431 elseif filereadable(path)
5432 let dir = fnamemodify(path, ':h')
5433 endif
5434 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5435
5436 return ''
5437endf
5438
Bram Moolenaar85850f32019-07-19 22:05:51 +02005439" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005440" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5441fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005442 let dict={}
5443 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005444 norm! gv"ay
5445 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005446 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005447 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005448endfun
5449
5450" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005451" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5452" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5453" to become an unlisted buffer, so in that case don't bwipe it.
5454fun! s:NetrwBufRename(newname)
5455" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5456" call Dredir("ls!","s:NetrwBufRename (before rename)")
5457 let oldbufname= bufname(bufnr("%"))
5458" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5459
5460 if oldbufname != a:newname
5461" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5462 let b:junk= 1
5463" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5464 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005465" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005466 let oldbufnr= bufnr(oldbufname)
5467" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5468" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5469 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5470" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5471 exe "bwipe! ".oldbufnr
5472" else " Decho
5473" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005474" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5475" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5476" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005477 endif
5478" call Dredir("ls!","s:NetrwBufRename (after rename)")
5479" else " Decho
5480" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5481 endif
5482
5483" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5484endfun
5485
5486" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005487" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005488fun! netrw#CheckIfRemote(...)
5489" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5490 if a:0 > 0
5491 let curfile= a:1
5492 else
5493 let curfile= expand("%")
5494 endif
5495" call Decho("curfile<".curfile.">")
5496 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005497" call Dret("netrw#CheckIfRemote 1")
5498 return 1
5499 else
5500" call Dret("netrw#CheckIfRemote 0")
5501 return 0
5502 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005503endfun
5504
5505" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005506" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5507fun! s:NetrwChgPerm(islocal,curdir)
5508" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005509 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005510 call inputsave()
5511 let newperm= input("Enter new permission: ")
5512 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005513 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5514 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5515" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005516 call system(chgperm)
5517 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005518 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005519 endif
5520 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005521 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005522 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005523 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005524" call Dret("s:NetrwChgPerm")
5525endfun
5526
5527" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005528" s:CheckIfKde: checks if kdeinit is running {{{2
5529" Returns 0: kdeinit not running
5530" 1: kdeinit is running
5531fun! s:CheckIfKde()
5532" call Dfunc("s:CheckIfKde()")
5533 " seems kde systems often have gnome-open due to dependencies, even though
5534 " gnome-open's subsidiary display tools are largely absent. Kde systems
5535 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5536 if !exists("s:haskdeinit")
5537 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005538 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005539 if v:shell_error
5540 let s:haskdeinit = 0
5541 endif
5542 else
5543 let s:haskdeinit= 0
5544 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005545" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005546 endif
5547
5548" call Dret("s:CheckIfKde ".s:haskdeinit)
5549 return s:haskdeinit
5550endfun
5551
5552" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005553" s:NetrwClearExplore: clear explore variables (if any) {{{2
5554fun! s:NetrwClearExplore()
5555" call Dfunc("s:NetrwClearExplore()")
5556 2match none
5557 if exists("s:explore_match") |unlet s:explore_match |endif
5558 if exists("s:explore_indx") |unlet s:explore_indx |endif
5559 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5560 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5561 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5562 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5563 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5564 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5565 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5566" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005567" call Dret("s:NetrwClearExplore")
5568endfun
5569
5570" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005571" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5572fun! s:NetrwEditBuf(bufnum)
5573" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5574 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5575" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5576 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5577 else
5578" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005579 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005580 endif
5581" call Dret("s:NetrwEditBuf")
5582endfun
5583
5584" ---------------------------------------------------------------------
5585" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5586" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5587fun! s:NetrwEditFile(cmd,opt,fname)
5588" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5589 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5590" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5591 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5592 else
5593" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005594 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5595 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5596 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005597 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5598 endif
5599" call Dret("s:NetrwEditFile")
5600endfun
5601
5602" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005603" s:NetrwExploreListUniq: {{{2
5604fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005605" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005606
5607 " this assumes that the list is already sorted
5608 let newexplist= []
5609 for member in a:explist
5610 if !exists("uniqmember") || member != uniqmember
5611 let uniqmember = member
5612 let newexplist = newexplist + [ member ]
5613 endif
5614 endfor
5615
Bram Moolenaar15146672011-10-20 22:22:38 +02005616" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005617 return newexplist
5618endfun
5619
5620" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005621" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5622fun! s:NetrwForceChgDir(islocal,newdir)
5623" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005624 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005625 if a:newdir !~ '/$'
5626 " ok, looks like force is needed to get directory-style treatment
5627 if a:newdir =~ '@$'
5628 let newdir= substitute(a:newdir,'@$','/','')
5629 elseif a:newdir =~ '[*=|\\]$'
5630 let newdir= substitute(a:newdir,'.$','/','')
5631 else
5632 let newdir= a:newdir.'/'
5633 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005634" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005635 else
5636 " should already be getting treatment as a directory
5637 let newdir= a:newdir
5638 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005639 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005640 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005641 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005642" call Dret("s:NetrwForceChgDir")
5643endfun
5644
5645" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005646" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005647" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5648" expr : this is the expression to follow the directory. Will use s:ComposePath()
5649" pare =1: remove the current directory from the resulting glob() filelist
5650" =0: leave the current directory in the resulting glob() filelist
5651fun! s:NetrwGlob(direntry,expr,pare)
5652" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005653 if netrw#CheckIfRemote()
5654 keepalt 1sp
5655 keepalt enew
5656 let keep_liststyle = w:netrw_liststyle
5657 let w:netrw_liststyle = s:THINLIST
5658 if s:NetrwRemoteListing() == 0
5659 keepj keepalt %s@/@@
5660 let filelist= getline(1,$)
5661 q!
5662 else
5663 " remote listing error -- leave treedict unchanged
5664 let filelist= w:netrw_treedict[a:direntry]
5665 endif
5666 let w:netrw_liststyle= keep_liststyle
5667 else
Christian Brabandt14879472024-06-13 21:25:35 +02005668 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005669 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005670 " escape [ so it is not detected as wildcard character, see :h wildcard
5671 let path= substitute(path, '[', '[[]', 'g')
5672 endif
5673 if v:version > 704 || (v:version == 704 && has("patch656"))
5674 let filelist= glob(path,0,1,1)
5675 else
5676 let filelist= glob(path,0,1)
5677 endif
5678 if a:pare
5679 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5680 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005681 endif
5682" call Dret("s:NetrwGlob ".string(filelist))
5683 return filelist
5684endfun
5685
5686" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005687" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5688fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005689" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005690 if a:newfile =~ '[/@*=|\\]$'
5691 let newfile= substitute(a:newfile,'.$','','')
5692 else
5693 let newfile= a:newfile
5694 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005695 if a:islocal
5696 call s:NetrwBrowseChgDir(a:islocal,newfile)
5697 else
5698 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5699 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005700" call Dret("s:NetrwForceFile")
5701endfun
5702
5703" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005704" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5705" and switches the hiding mode. The actual hiding is done by
5706" s:NetrwListHide().
5707" g:netrw_hide= 0: show all
5708" 1: show not-hidden files
5709" 2: show hidden files only
5710fun! s:NetrwHide(islocal)
5711" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005712 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005713 let svpos= winsaveview()
5714" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005715
5716 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005717" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5718" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005719
5720 " hide the files in the markfile list
5721 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005722" 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 +00005723 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5724 " remove fname from hiding list
5725 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5726 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5727 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005728" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005729 else
5730 " append fname to hiding list
5731 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5732 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5733 else
5734 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5735 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005736" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005737 endif
5738 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005739 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005740 let g:netrw_hide= 1
5741
5742 else
5743
5744 " switch between show-all/show-not-hidden/show-hidden
5745 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005746 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005747 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005748 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005749 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005750" call Dret("NetrwHide")
5751 return
5752 endif
5753 endif
5754
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005755 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005756" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5757 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005758 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005759" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005760endfun
5761
5762" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005763" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5764fun! s:NetrwHideEdit(islocal)
5765" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5766
5767 let ykeep= @@
5768 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005769 let svpos= winsaveview()
5770" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005771
5772 " get new hiding list from user
5773 call inputsave()
5774 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5775 call inputrestore()
5776 let g:netrw_list_hide= newhide
5777" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5778
5779 " refresh the listing
5780 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5781
5782 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005783" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5784 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005785 let @@= ykeep
5786
5787" call Dret("NetrwHideEdit")
5788endfun
5789
5790" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005791" s:NetrwHidden: invoked by "gh" {{{2
5792fun! s:NetrwHidden(islocal)
5793" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005794 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005795 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005796 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005797" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005798
5799 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005800 " remove .file pattern from hiding list
5801" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005802 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005803 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005804" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005805 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5806 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005807" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005808 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5809 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005810 if g:netrw_list_hide =~ '^,'
5811 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5812 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005813
5814 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005815 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005816" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5817 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005818 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005819" call Dret("s:NetrwHidden")
5820endfun
5821
5822" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005823" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5824fun! s:NetrwHome()
5825 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005826 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005827 else
5828 " go to vim plugin home
5829 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005830 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005831 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005832 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005833 let home= basehome."/.vim"
5834 break
5835 endif
5836 endfor
5837 if home == ""
5838 " just pick the first directory
5839 let home= substitute(&rtp,',.*$','','')
5840 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005841 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005842 let home= substitute(home,'/','\\','g')
5843 endif
5844 endif
5845 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005846 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005847" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005848 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005849" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005850 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005851 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005852" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005853 call mkdir(home)
5854 endif
5855 endif
5856 let g:netrw_home= home
5857 return home
5858endfun
5859
5860" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005861" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5862fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005863 if exists("s:netrwdrag")
5864 return
5865 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005866 if &ft != "netrw"
5867 return
5868 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005869" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005870
Bram Moolenaar97d62492012-11-15 21:28:22 +01005871 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005872 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005873 while getchar(0) != 0
5874 "clear the input stream
5875 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005876 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005877 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005878 let mouse_lnum = v:mouse_lnum
5879 let wlastline = line('w$')
5880 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005881" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5882" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005883 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5884 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005885 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005886" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5887 return
5888 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005889 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005890 " 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 +01005891 " without this test when its disabled.
5892 " 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 +01005893" 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 +01005894 if v:mouse_col > virtcol('.')
5895 let @@= ykeep
5896" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5897 return
5898 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005899
Bram Moolenaar446cb832008-06-24 21:56:24 +00005900 if a:islocal
5901 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005902 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005903 endif
5904 else
5905 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005906 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005907 endif
5908 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005909 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005910" call Dret("s:NetrwLeftmouse")
5911endfun
5912
5913" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005914" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5915fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005916 if &ft != "netrw"
5917 return
5918 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005919" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
5920 call s:NetrwMarkFileTgt(a:islocal)
5921" call Dret("s:NetrwCLeftmouse")
5922endfun
5923
5924" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005925" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5926" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005927" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005928" a:islocal=2 : <c-r> used, remote
5929" a:islocal=3 : <c-r> used, local
5930fun! s:NetrwServerEdit(islocal,fname)
5931" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5932 let islocal = a:islocal%2 " =0: remote =1: local
5933 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005934" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005935
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005936 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005937 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005938 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005939" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005940 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005941 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005942 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5943 unlet s:netrw_browse_split_{winnr()}
5944 endif
5945 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
5946" call Dret("s:NetrwServerEdit")
5947 return
5948 endif
5949
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005950" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005951 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005952" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005953
5954 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005955" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005956 let srvrname = g:netrw_browse_split[0]
5957 let tabnum = g:netrw_browse_split[1]
5958 let winnum = g:netrw_browse_split[2]
5959
5960 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005961" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005962
5963 if !ctrlr
5964 " user must have closed the server window and the user did not use <c-r>, but
5965 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005966" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005967 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005968 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005969 endif
5970 let g:netrw_browse_split= 0
5971 if exists("s:netrw_browse_split_".winnr())
5972 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5973 endif
5974 call s:NetrwBrowseChgDir(islocal,a:fname)
5975" call Dret("s:NetrwServerEdit")
5976 return
5977
5978 elseif has("win32") && executable("start")
5979 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005980" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005981 call system("start gvim --servername ".srvrname)
5982
5983 else
5984 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005985" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005986 call system("gvim --servername ".srvrname)
5987 endif
5988 endif
5989
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005990" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005991 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5992 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005993 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005994
5995 else
5996
5997 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5998
5999 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006000" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006001 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006002 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006003 endif
6004 let g:netrw_browse_split= 0
6005 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6006" call Dret("s:NetrwServerEdit")
6007 return
6008
6009 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006010" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006011 if has("win32") && executable("start")
6012 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006013" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006014 call system("start gvim --servername ".g:netrw_servername)
6015 else
6016 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006017" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006018 call system("gvim --servername ".g:netrw_servername)
6019 endif
6020 endif
6021 endif
6022
6023 while 1
6024 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006025" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6026 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006027 break
6028 catch /^Vim\%((\a\+)\)\=:E241/
6029 sleep 200m
6030 endtry
6031 endwhile
6032
6033 if exists("g:netrw_browse_split")
6034 if type(g:netrw_browse_split) != 3
6035 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6036 endif
6037 unlet g:netrw_browse_split
6038 endif
6039 let g:netrw_browse_split= [g:netrw_servername,1,1]
6040 endif
6041
6042 else
6043 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6044 endif
6045
6046" call Dret("s:NetrwServerEdit")
6047endfun
6048
6049" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006050" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6051fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006052 if &ft != "netrw"
6053 return
6054 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006055" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006056
Bram Moolenaar8d043172014-01-23 14:24:41 +01006057 let s:ngw= s:NetrwGetWord()
6058 call s:NetrwMarkFile(a:islocal,s:ngw)
6059
6060" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006061endfun
6062
6063" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006064" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6065" Used to mark multiple files.
6066fun! s:NetrwSLeftdrag(islocal)
6067" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6068 if !exists("s:netrwdrag")
6069 let s:netrwdrag = winnr()
6070 if a:islocal
6071 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006072 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006073 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006074 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006075 endif
6076 let ngw = s:NetrwGetWord()
6077 if !exists("s:ngw") || s:ngw != ngw
6078 call s:NetrwMarkFile(a:islocal,ngw)
6079 endif
6080 let s:ngw= ngw
6081" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6082endfun
6083
6084" ---------------------------------------------------------------------
6085" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6086fun! s:NetrwSLeftrelease(islocal)
6087" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6088 if exists("s:netrwdrag")
6089 nunmap <s-leftrelease>
6090 let ngw = s:NetrwGetWord()
6091 if !exists("s:ngw") || s:ngw != ngw
6092 call s:NetrwMarkFile(a:islocal,ngw)
6093 endif
6094 if exists("s:ngw")
6095 unlet s:ngw
6096 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006097 unlet s:netrwdrag
6098 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006099" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006100endfun
6101
6102" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006103" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6104" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006105fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006106" 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 +02006107" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006108 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006109
6110 " 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 +02006111 " How-it-works: take the hiding command, convert it into a range.
6112 " Duplicate characters don't matter.
6113 " Remove all such characters from the '/~@#...890' string.
6114 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006115" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006116 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006117 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006118" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006119
6120 while listhide != ""
6121 if listhide =~ ','
6122 let hide = substitute(listhide,',.*$','','e')
6123 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6124 else
6125 let hide = listhide
6126 let listhide = ""
6127 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006128" 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 +01006129 if g:netrw_sort_by =~ '^[ts]'
6130 if hide =~ '^\^'
6131" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6132 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6133 elseif hide =~ '^\\(\^'
6134 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6135 endif
6136" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6137 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006138
6139 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006140" 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 +00006141 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006142" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006143 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006144 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006145" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006146 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006147 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006148" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006149 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006150
Bram Moolenaar446cb832008-06-24 21:56:24 +00006151 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006152 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006153" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006154 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006155" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006156 endif
6157
Bram Moolenaaradc21822011-04-01 18:03:16 +02006158 " remove any blank lines that have somehow remained.
6159 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006160 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006161
Bram Moolenaar97d62492012-11-15 21:28:22 +01006162 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006163" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006164endfun
6165
6166" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006167" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006168" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006169fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006170" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006171
Bram Moolenaar97d62492012-11-15 21:28:22 +01006172 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006173 " get name of new directory from user. A bare <CR> will skip.
6174 " if its currently a directory, also request will be skipped, but with
6175 " a message.
6176 call inputsave()
6177 let newdirname= input("Please give directory name: ")
6178 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006179" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006180
6181 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006182 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006183" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006184 return
6185 endif
6186
6187 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006188" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006189
6190 " Local mkdir:
6191 " sanity checks
6192 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006193" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6194 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006195 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006196 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006197 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006198 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006199" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006200 return
6201 endif
6202 if s:FileReadable(fullnewdir)
6203 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006204 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006205 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006206 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006207" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006208 return
6209 endif
6210
6211 " requested new local directory is neither a pre-existing file or
6212 " directory, so make it!
6213 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006214 if has("unix")
6215 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6216 else
6217 call mkdir(fullnewdir,"p")
6218 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006219 else
6220 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006221 if s:NetrwLcd(b:netrw_curdir)
6222" call Dret("s:NetrwMakeDir : lcd failure")
6223 return
6224 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006225" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006226 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006227 if v:shell_error != 0
6228 let @@= ykeep
6229 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 +01006230" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006231 return
6232 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006233 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006234" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006235 if s:NetrwLcd(netrw_origdir)
6236" call Dret("s:NetrwBrowse : lcd failure")
6237 return
6238 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006239 endif
6240 endif
6241
6242 if v:shell_error == 0
6243 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006244" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006245 let svpos= winsaveview()
6246" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006247 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006248" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6249 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006250 elseif !exists("g:netrw_quiet")
6251 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6252 endif
6253" redraw!
6254
6255 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006256 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006257" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006258 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6259 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006260 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006261 if v:shell_error == 0
6262 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006263 let svpos= winsaveview()
6264" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006265 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006266" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6267 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006268 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006269 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006270 endif
6271" redraw!
6272
6273 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006274 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006275 let svpos= winsaveview()
6276" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006277" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006278 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006279" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006280 let remotepath= b:netrw_fname
6281 else
6282 let remotepath= ""
6283 endif
6284 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006285 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006286" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6287 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006288
Bram Moolenaar446cb832008-06-24 21:56:24 +00006289 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006290 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006291 let svpos= winsaveview()
6292" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006293" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006294 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006295" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006296 let remotepath= b:netrw_fname
6297 else
6298 let remotepath= ""
6299 endif
6300 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006301 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006302" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6303 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006304 endif
6305
Bram Moolenaar97d62492012-11-15 21:28:22 +01006306 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006307" call Dret("s:NetrwMakeDir")
6308endfun
6309
6310" ---------------------------------------------------------------------
6311" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6312fun! s:TreeSqueezeDir(islocal)
6313" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6314 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6315 " its a tree-listing style
6316 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006317 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006318 let depth = strchars(substitute(curdepth,' ','','g'))
6319 let srch = -1
6320" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6321" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006322" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006323" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6324 if depth >= 2
6325 NetrwKeepj norm! 0
6326 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6327 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6328" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6329" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6330 elseif depth == 1
6331 NetrwKeepj norm! 0
6332 let treedepthchr= substitute(s:treedepthstring,' ','','')
6333 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6334" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6335 endif
6336 if srch > 0
6337" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6338 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6339 exe srch
6340 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006341 endif
6342" call Dret("s:TreeSqueezeDir")
6343endfun
6344
6345" ---------------------------------------------------------------------
6346" s:NetrwMaps: {{{2
6347fun! s:NetrwMaps(islocal)
6348" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6349
Bram Moolenaar85850f32019-07-19 22:05:51 +02006350 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006351 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006352" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006353 if !hasmapto("<Plug>NetrwReturn")
6354 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006355" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006356 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6357 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006358" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006359 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6360 endif
6361 endif
6362 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006363" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006364 endif
6365
Bram Moolenaar85850f32019-07-19 22:05:51 +02006366 " generate default <Plug> maps {{{3
6367 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006368 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006369 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6370 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6371 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6372 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6373 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6374 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6375 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6376 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6377 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6378 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6379" ---------------------------------------------------------------------
6380" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6381" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6382" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6383" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6384" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6385" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6386" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6387" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6388" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6389" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6390" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6391" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6392" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6393" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6394" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6395" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6396" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6397" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6398" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6399" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6400" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6401" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6402" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6403" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6404" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6405" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6406" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6407" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6408" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6409" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6410" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6411" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6412" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6413" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6414" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6415" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6416" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6417" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6418" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6419" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6420" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6421" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6422" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6423" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6424" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6425" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6426" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6427
Bram Moolenaara6878372014-03-22 21:02:50 +01006428 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006429" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006430 " local normal-mode maps {{{3
6431 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6432 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6433 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6434 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6435 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6436 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6437 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6438 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6439 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6440 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6441 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6442" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006443 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6444 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6445 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006446 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006447 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006448 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6449 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6450 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6451 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006452 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6453 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6454 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6455 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6456 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6457 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6458 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6459 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6460 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6461 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6462 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6463 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6464 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006465 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006466 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006467 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6468 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6469 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6470 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6471 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006472 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006473 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006474 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6475 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006476 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6477 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6478 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006479 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006480 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006481 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6482 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006483 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006484 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006485 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6486 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6487 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006488 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6489 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006490
6491 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 +01006492 if !hasmapto('<Plug>NetrwHideEdit')
6493 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006494 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006495 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006496 if !hasmapto('<Plug>NetrwRefresh')
6497 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006498 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006499 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 +01006500 if s:didstarstar || !mapcheck("<s-down>","n")
6501 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006502 endif
6503 if s:didstarstar || !mapcheck("<s-up>","n")
6504 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006505 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006506 if !hasmapto('<Plug>NetrwTreeSqueeze')
6507 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006508 endif
6509 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006510 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6511 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006512 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6513 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6514 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6515 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6516 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6517 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6518 imap <buffer> <leftmouse> <Plug>ILeftmouse
6519 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006520 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6521 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6522 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6523 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6524 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006525 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006526 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6527 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006528 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006529 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6530 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6531 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6532 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6533 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6534 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6535 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006536 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6537
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006538 " support user-specified maps
6539 call netrw#UserMaps(1)
6540
Bram Moolenaar85850f32019-07-19 22:05:51 +02006541 else
6542 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006543" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006544 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006545 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6546 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6547 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6548 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6549 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6550 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6551 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6552 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6553 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6554 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6555 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6556" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006557 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6558 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6559 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6560 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6561 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6562 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6563 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6564 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006565 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006566 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006567 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6568 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6569 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6570 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6571 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6572 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6573 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6574 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6575 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6576 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6577 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006578 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006579 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006580 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6581 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6582 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6583 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6584 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006585 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6586 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6587 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6588 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006589 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006590 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6591 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006592 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006593 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 +01006594 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6595 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6596 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6597 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6598 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6599 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6600 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6601 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6602 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006603 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006604 if !hasmapto('<Plug>NetrwHideEdit')
6605 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006606 endif
6607 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6608 if !hasmapto('<Plug>NetrwRefresh')
6609 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006610 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006611 if !hasmapto('<Plug>NetrwTreeSqueeze')
6612 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006613 endif
6614 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006615
6616 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006617 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006618
6619 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6620 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006621 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006622 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006623 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006624 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006625 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006626 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006627 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006628 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006629 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006630 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006631 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6632 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6633 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006634 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006635 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006636 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6637 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006638 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006639 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6640 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6641 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6642 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6643 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6644 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6645 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006646 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006647
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006648 " support user-specified maps
6649 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006650 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006651
6652" call Dret("s:NetrwMaps")
6653endfun
6654
6655" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006656" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006657" If -buffer, the command is only available from within netrw buffers
6658" Otherwise, the command is available from any window, so long as netrw
6659" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006660fun! s:NetrwCommands(islocal)
6661" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6662
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006663 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6664 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006665 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 +01006666 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006667 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006668 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006669 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006670 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006671 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006672
6673" call Dret("s:NetrwCommands")
6674endfun
6675
6676" ---------------------------------------------------------------------
6677" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6678" glob()ing only works with local files
6679fun! s:NetrwMarkFiles(islocal,...)
6680" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006681 let curdir = s:NetrwGetCurdir(a:islocal)
6682 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006683 while i <= a:0
6684 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006685 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006686 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006687 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006688 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006689 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006690 else
6691 let mffiles= [a:{i}]
6692 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006693" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006694 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006695" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006696 call s:NetrwMarkFile(a:islocal,mffile)
6697 endfor
6698 let i= i + 1
6699 endwhile
6700" call Dret("s:NetrwMarkFiles")
6701endfun
6702
6703" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006704" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006705fun! s:NetrwMarkTarget(...)
6706" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6707 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006708 let curdir = s:NetrwGetCurdir(1)
6709 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006710 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006711 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6712 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006713 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006714" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006715 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006716 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6717 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006718 let svpos = winsaveview()
6719" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006720 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006721" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6722 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006723" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006724endfun
6725
6726" ---------------------------------------------------------------------
6727" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6728" mark and unmark files. If a markfile list exists,
6729" then the rename and delete functions will use it instead
6730" of whatever may happen to be under the cursor at that
6731" moment. When the mouse and gui are available,
6732" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006733"
6734" Creates two lists
6735" s:netrwmarkfilelist -- holds complete paths to all marked files
6736" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6737"
6738" Creates a marked file match string
6739" s:netrwmarfilemtch_# -- used with 2match to display marked files
6740"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006741" Creates a buffer version of islocal
6742" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006743fun! s:NetrwMarkFile(islocal,fname)
6744" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006745" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006746
6747 " sanity check
6748 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006749" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006750 return
6751 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006752 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006753
Bram Moolenaar97d62492012-11-15 21:28:22 +01006754 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006755 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006756 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006757 if a:fname =~ '\a$'
6758 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6759 else
6760 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6761 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006762
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006763 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006764 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006765" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6766" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6767" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006768 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006769
6770 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006771 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006772" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006773 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006774 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006775
6776 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006777 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006778" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006779 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6780 if s:netrwmarkfilelist_{curbufnr} == []
6781 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006782" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006783 call s:NetrwUnmarkList(curbufnr,curdir)
6784 else
6785 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006786" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006787 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006788 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006789 for fname in s:netrwmarkfilelist_{curbufnr}
6790 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006791 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006792 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006793 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006794 endif
6795 let first= 0
6796 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006797" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006798 endif
6799 endif
6800
6801 else
6802 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006803" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006804
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006805" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006806 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006807 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6808" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006809
6810 " build initial markfile matching pattern
6811 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006812 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006813 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006814 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006816" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006817 endif
6818
6819 " handle global markfilelist
6820 if exists("s:netrwmarkfilelist")
6821 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6822 if index(s:netrwmarkfilelist,dname) == -1
6823 " append new filename to global markfilelist
6824 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006825" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006826 else
6827 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006828" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6829" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006830 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006831" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006832 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006833" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006834 unlet s:netrwmarkfilelist
6835 endif
6836 endif
6837 else
6838 " initialize new global-directory markfilelist
6839 let s:netrwmarkfilelist= []
6840 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006841" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006842 endif
6843
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006844 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006845 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6846 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6847" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6848 if exists("g:did_drchip_netrwlist_syntax")
6849 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6850 endif
6851 else
6852" " call Decho("2match none",'~'.expand("<slnum>"))
6853 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006854 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006855 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006856 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006857" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6858" 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 +00006859endfun
6860
6861" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006862" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6863" mA: move the argument list to marked file list (tomflist=1)
6864" Uses the global marked file list
6865fun! s:NetrwMarkFileArgList(islocal,tomflist)
6866" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6867
6868 let svpos = winsaveview()
6869" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6870 let curdir = s:NetrwGetCurdir(a:islocal)
6871 let curbufnr = bufnr("%")
6872
6873 if a:tomflist
6874 " mA: move argument list to marked file list
6875 while argc()
6876 let fname= argv(0)
6877" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6878 exe "argdel ".fnameescape(fname)
6879 call s:NetrwMarkFile(a:islocal,fname)
6880 endwhile
6881
6882 else
6883 " ma: move marked file list to argument list
6884 if exists("s:netrwmarkfilelist")
6885
6886 " for every filename in the marked list
6887 for fname in s:netrwmarkfilelist
6888" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6889 exe "argadd ".fnameescape(fname)
6890 endfor " for every file in the marked list
6891
6892 " unmark list and refresh
6893 call s:NetrwUnmarkList(curbufnr,curdir)
6894 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6895" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6896 NetrwKeepj call winrestview(svpos)
6897 endif
6898 endif
6899
6900" call Dret("s:NetrwMarkFileArgList")
6901endfun
6902
6903" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006904" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6905" compress/decompress files using the programs
6906" in g:netrw_compress and g:netrw_uncompress,
6907" using g:netrw_compress_suffix to know which to
6908" do. By default:
6909" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006910" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006911fun! s:NetrwMarkFileCompress(islocal)
6912" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006913 let svpos = winsaveview()
6914" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006915 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006916 let curbufnr = bufnr("%")
6917
Bram Moolenaarff034192013-04-24 18:51:19 +02006918 " sanity check
6919 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006920 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006921" call Dret("s:NetrwMarkFileCompress")
6922 return
6923 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006924" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006925
Bram Moolenaar446cb832008-06-24 21:56:24 +00006926 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006927
6928 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006929 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006930 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006931" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006932 if exists("g:netrw_decompress['".sfx."']")
6933 " fname has a suffix indicating that its compressed; apply associated decompression routine
6934 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006935" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006936 let exe= netrw#WinPath(exe)
6937 if a:islocal
6938 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006939 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006940 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006941 call system(exe." ".fname)
6942 if v:shell_error
6943 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006944 endif
6945 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006946 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6947 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006948 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006949
Bram Moolenaarff034192013-04-24 18:51:19 +02006950 endif
6951 unlet sfx
6952
Bram Moolenaar446cb832008-06-24 21:56:24 +00006953 if exists("exe")
6954 unlet exe
6955 elseif a:islocal
6956 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006957 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006958 if v:shell_error
6959 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6960 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006961 else
6962 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006963 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006964 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006965 endfor " for every file in the marked list
6966
Bram Moolenaar446cb832008-06-24 21:56:24 +00006967 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006968 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006969" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6970 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006971 endif
6972" call Dret("s:NetrwMarkFileCompress")
6973endfun
6974
6975" ---------------------------------------------------------------------
6976" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6977" If no marked files, then set up directory as the
6978" target. Currently does not support copying entire
6979" directories. Uses the local-buffer marked file list.
6980" Returns 1=success (used by NetrwMarkFileMove())
6981" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006982fun! s:NetrwMarkFileCopy(islocal,...)
6983" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6984
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006985 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006986 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006987 if b:netrw_curdir !~ '/$'
6988 if !exists("b:netrw_curdir")
6989 let b:netrw_curdir= curdir
6990 endif
6991 let b:netrw_curdir= b:netrw_curdir."/"
6992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006993
Bram Moolenaarff034192013-04-24 18:51:19 +02006994 " sanity check
6995 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006996 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006997" call Dret("s:NetrwMarkFileCopy")
6998 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006999 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007000" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007001
Bram Moolenaar446cb832008-06-24 21:56:24 +00007002 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007003 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007004" call Dret("s:NetrwMarkFileCopy 0")
7005 return 0
7006 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007007" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007008
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007009 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007010 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007011" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007012 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007013 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7014" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7015 return
7016 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007017
7018 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007019 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007020 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7021 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007022" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007023 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007024 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7025 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007026" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007027 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007028 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007029 let oldname = a:1
7030 else
7031 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007032" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007033 let s:recursive= 1
7034 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7035 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7036 if ret == 0
7037 break
7038 endif
7039 endfor
7040 unlet s:recursive
7041 call s:NetrwUnmarkList(curbufnr,curdir)
7042" call Dret("s:NetrwMarkFileCopy ".ret)
7043 return ret
7044 endif
7045
7046 call inputsave()
7047 let newname= input("Copy ".oldname." to : ",oldname,"file")
7048 call inputrestore()
7049 if newname == ""
7050" call Dret("s:NetrwMarkFileCopy 0")
7051 return 0
7052 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007053 let args= s:ShellEscape(oldname)
7054 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007055 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007056 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7057 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007058 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007059 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007060 let args= substitute(args,'/','\\','g')
7061 let tgt = substitute(tgt, '/','\\','g')
7062 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007063 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7064 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7065 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7066 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7067" call Decho("args <".args.">",'~'.expand("<slnum>"))
7068" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007069 if isdirectory(s:NetrwFile(args))
7070" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007071 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007072" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007073 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007074 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7075 " contents to a target. One must append the source directory name to the target to get xcopy to
7076 " do the right thing.
7077 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007078" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007079 endif
7080 else
7081 let copycmd= g:netrw_localcopycmd
7082 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007083 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007084 let copycmd = substitute(copycmd,'\s.*$','','')
7085 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007086 let copycmd = netrw#WinPath(copycmd).copycmdargs
7087 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007088 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007089 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007090" call Decho("args <".args.">",'~'.expand("<slnum>"))
7091" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7092" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7093" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007094 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007095 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007096 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007097 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 +01007098 else
7099 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7100 endif
7101" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007102 return 0
7103 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007104
7105 elseif a:islocal && !s:netrwmftgt_islocal
7106 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007107" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007108 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007109
7110 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007111 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007112" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007113 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007114
7115 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007116 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007117" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007118 let curdir = getcwd()
7119 let tmpdir = s:GetTempfile("")
7120 if tmpdir !~ '/'
7121 let tmpdir= curdir."/".tmpdir
7122 endif
7123 if exists("*mkdir")
7124 call mkdir(tmpdir)
7125 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007126 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007127 if v:shell_error != 0
7128 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 +01007129" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007130 return
7131 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007132 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007133 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007134 if s:NetrwLcd(tmpdir)
7135" call Dret("s:NetrwMarkFileCopy : lcd failure")
7136 return
7137 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007138 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007139 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007140 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007141 if getcwd() == tmpdir
7142 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007143 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007144 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007145 if s:NetrwLcd(curdir)
7146" call Dret("s:NetrwMarkFileCopy : lcd failure")
7147 return
7148 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007149 if delete(tmpdir,"d")
7150 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007151 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007152 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007153 if s:NetrwLcd(curdir)
7154" call Dret("s:NetrwMarkFileCopy : lcd failure")
7155 return
7156 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007157 endif
7158 endif
7159 endif
7160
7161 " -------
7162 " cleanup
7163 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007164" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007165 " remove markings from local buffer
7166 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007167" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7168" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7169" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7170" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7171" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7172" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7173 if exists("s:recursive")
7174" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7175 else
7176" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007177 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007178 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007179 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007180 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007181 else
7182 " refresh local and targets for fast browsing
7183 if !exists("s:recursive")
7184 " remove markings from local buffer
7185" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7186 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7187 endif
7188
7189 " refresh buffers
7190 if s:netrwmftgt_islocal
7191" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7192 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7193 endif
7194 if a:islocal && s:netrwmftgt != curdir
7195" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7196 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7197 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007198 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007199
Bram Moolenaar446cb832008-06-24 21:56:24 +00007200" call Dret("s:NetrwMarkFileCopy 1")
7201 return 1
7202endfun
7203
7204" ---------------------------------------------------------------------
7205" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7206" invoke vim's diff mode on the marked files.
7207" Either two or three files can be so handled.
7208" Uses the global marked file list.
7209fun! s:NetrwMarkFileDiff(islocal)
7210" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7211 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007212
Bram Moolenaarff034192013-04-24 18:51:19 +02007213 " sanity check
7214 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007215 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007216" call Dret("s:NetrwMarkFileDiff")
7217 return
7218 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007219 let curdir= s:NetrwGetCurdir(a:islocal)
7220" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007221
Bram Moolenaara6878372014-03-22 21:02:50 +01007222 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007223 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007224 for fname in s:netrwmarkfilelist
7225 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007226 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007227" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007228 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007229 diffthis
7230 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007231 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007232" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007233 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007234 diffthis
7235 else
7236 break
7237 endif
7238 endfor
7239 call s:NetrwUnmarkList(curbufnr,curdir)
7240 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007241
Bram Moolenaar446cb832008-06-24 21:56:24 +00007242" call Dret("s:NetrwMarkFileDiff")
7243endfun
7244
7245" ---------------------------------------------------------------------
7246" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7247" Uses global markfilelist
7248fun! s:NetrwMarkFileEdit(islocal)
7249" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7250
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007251 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007252 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007253
7254 " sanity check
7255 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007256 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007257" call Dret("s:NetrwMarkFileEdit")
7258 return
7259 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007260" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007261
Bram Moolenaar446cb832008-06-24 21:56:24 +00007262 if exists("s:netrwmarkfilelist_{curbufnr}")
7263 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007264 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007265 " unmark markedfile list
7266" call s:NetrwUnmarkList(curbufnr,curdir)
7267 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007268" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007269 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007270 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007271 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007272
Bram Moolenaar446cb832008-06-24 21:56:24 +00007273" call Dret("s:NetrwMarkFileEdit")
7274endfun
7275
7276" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007277" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007278fun! s:NetrwMarkFileQFEL(islocal,qfel)
7279" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7280 call s:NetrwUnmarkAll()
7281 let curbufnr= bufnr("%")
7282
7283 if !empty(a:qfel)
7284 for entry in a:qfel
7285 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007286" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007287 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007288" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007289 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7290 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7291 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7292 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007293" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007294 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7295 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007296" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007297 endif
7298 endfor
7299 echo "(use me to edit marked files)"
7300 else
7301 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7302 endif
7303
7304" call Dret("s:NetrwMarkFileQFEL")
7305endfun
7306
7307" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007308" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7309" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7310" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7311fun! s:NetrwMarkFileExe(islocal,enbloc)
7312" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007313 let svpos = winsaveview()
7314" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007315 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007316 let curbufnr = bufnr("%")
7317
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007318 if a:enbloc == 0
7319 " individually apply command to files, one at a time
7320 " sanity check
7321 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7322 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7323" call Dret("s:NetrwMarkFileExe")
7324 return
7325 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007326" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007327
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007328 if exists("s:netrwmarkfilelist_{curbufnr}")
7329 " get the command
7330 call inputsave()
7331 let cmd= input("Enter command: ","","file")
7332 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007333" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007334 if cmd == ""
7335" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7336 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007337 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007338
7339 " apply command to marked files, individually. Substitute: filename -> %
7340 " If no %, then append a space and the filename to the command
7341 for fname in s:netrwmarkfilelist_{curbufnr}
7342 if a:islocal
7343 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007344 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007345 endif
7346 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007347 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007348 endif
7349 if cmd =~ '%'
7350 let xcmd= substitute(cmd,'%',fname,'g')
7351 else
7352 let xcmd= cmd.' '.fname
7353 endif
7354 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007355" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007356 let ret= system(xcmd)
7357 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007358" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007359 let ret= s:RemoteSystem(xcmd)
7360 endif
7361 if v:shell_error < 0
7362 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7363 break
7364 else
yasudac75dad02024-08-22 21:06:32 +02007365 if ret !=# ''
7366 echo "\n"
7367 " skip trailing new line
7368 echo ret[0:-2]
7369 else
7370 echo ret
7371 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007372 endif
7373 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007374
7375 " unmark marked file list
7376 call s:NetrwUnmarkList(curbufnr,curdir)
7377
7378 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007379 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007380" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7381 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007382 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007383 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007384 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007385
7386 else " apply command to global list of files, en bloc
7387
7388 call inputsave()
7389 let cmd= input("Enter command: ","","file")
7390 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007391" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007392 if cmd == ""
7393" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7394 return
7395 endif
7396 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007397 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007398 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007399 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007400 endif
7401 if a:islocal
7402 call system(cmd)
7403 if v:shell_error < 0
7404 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7405 endif
7406 else
7407 let ret= s:RemoteSystem(cmd)
7408 endif
7409 call s:NetrwUnmarkAll()
7410
7411 " refresh the listing
7412 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007413" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7414 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007415
7416 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007417
Bram Moolenaar446cb832008-06-24 21:56:24 +00007418" call Dret("s:NetrwMarkFileExe")
7419endfun
7420
7421" ---------------------------------------------------------------------
7422" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7423" as the marked file(s) (toggles suffix presence)
7424" Uses the local marked file list.
7425fun! s:NetrwMarkHideSfx(islocal)
7426" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007427 let svpos = winsaveview()
7428" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007429 let curbufnr = bufnr("%")
7430
7431 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7432 if exists("s:netrwmarkfilelist_{curbufnr}")
7433
7434 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007435" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007436 " construct suffix pattern
7437 if fname =~ '\.'
7438 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7439 else
7440 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7441 endif
7442 " determine if its in the hiding list or not
7443 let inhidelist= 0
7444 if g:netrw_list_hide != ""
7445 let itemnum = 0
7446 let hidelist= split(g:netrw_list_hide,',')
7447 for hidepat in hidelist
7448 if sfxpat == hidepat
7449 let inhidelist= 1
7450 break
7451 endif
7452 let itemnum= itemnum + 1
7453 endfor
7454 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007455" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007456 if inhidelist
7457 " remove sfxpat from list
7458 call remove(hidelist,itemnum)
7459 let g:netrw_list_hide= join(hidelist,",")
7460 elseif g:netrw_list_hide != ""
7461 " append sfxpat to non-empty list
7462 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7463 else
7464 " set hiding list to sfxpat
7465 let g:netrw_list_hide= sfxpat
7466 endif
7467 endfor
7468
7469 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007470 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007471" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7472 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007473 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007474 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007475 endif
7476
7477" call Dret("s:NetrwMarkHideSfx")
7478endfun
7479
7480" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007481" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007482" Uses the local marked-file list.
7483fun! s:NetrwMarkFileVimCmd(islocal)
7484" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007485 let svpos = winsaveview()
7486" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007487 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007488 let curbufnr = bufnr("%")
7489
Bram Moolenaarff034192013-04-24 18:51:19 +02007490 " sanity check
7491 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007492 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007493" call Dret("s:NetrwMarkFileVimCmd")
7494 return
7495 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007496" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007497
Bram Moolenaar15146672011-10-20 22:22:38 +02007498 if exists("s:netrwmarkfilelist_{curbufnr}")
7499 " get the command
7500 call inputsave()
7501 let cmd= input("Enter vim command: ","","file")
7502 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007503" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007504 if cmd == ""
7505" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7506 return
7507 endif
7508
7509 " apply command to marked files. Substitute: filename -> %
7510 " If no %, then append a space and the filename to the command
7511 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007512" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007513 if a:islocal
7514 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007515 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007516" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007517 exe cmd
7518 exe "sil! keepalt wq!"
7519 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007520" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007521 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007522 endif
7523 endfor
7524
7525 " unmark marked file list
7526 call s:NetrwUnmarkList(curbufnr,curdir)
7527
7528 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007529 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007530" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7531 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007532 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007533 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007534 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007535
Bram Moolenaar15146672011-10-20 22:22:38 +02007536" call Dret("s:NetrwMarkFileVimCmd")
7537endfun
7538
7539" ---------------------------------------------------------------------
7540" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7541" as the marked file(s) (toggles suffix presence)
7542" Uses the local marked file list.
7543fun! s:NetrwMarkHideSfx(islocal)
7544" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007545 let svpos = winsaveview()
7546" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007547 let curbufnr = bufnr("%")
7548
7549 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7550 if exists("s:netrwmarkfilelist_{curbufnr}")
7551
7552 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007553" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007554 " construct suffix pattern
7555 if fname =~ '\.'
7556 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7557 else
7558 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7559 endif
7560 " determine if its in the hiding list or not
7561 let inhidelist= 0
7562 if g:netrw_list_hide != ""
7563 let itemnum = 0
7564 let hidelist= split(g:netrw_list_hide,',')
7565 for hidepat in hidelist
7566 if sfxpat == hidepat
7567 let inhidelist= 1
7568 break
7569 endif
7570 let itemnum= itemnum + 1
7571 endfor
7572 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007573" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007574 if inhidelist
7575 " remove sfxpat from list
7576 call remove(hidelist,itemnum)
7577 let g:netrw_list_hide= join(hidelist,",")
7578 elseif g:netrw_list_hide != ""
7579 " append sfxpat to non-empty list
7580 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7581 else
7582 " set hiding list to sfxpat
7583 let g:netrw_list_hide= sfxpat
7584 endif
7585 endfor
7586
7587 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007588 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007589" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7590 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007591 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007592 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007593 endif
7594
7595" call Dret("s:NetrwMarkHideSfx")
7596endfun
7597
7598" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007599" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7600" Uses the global markfilelist
7601fun! s:NetrwMarkFileGrep(islocal)
7602" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007603 let svpos = winsaveview()
7604" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007605 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007606 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007607
7608 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007609" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007610 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007611" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007612 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007613 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007614" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007615 let netrwmarkfilelist= "*"
7616 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007617
Bram Moolenaarff034192013-04-24 18:51:19 +02007618 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007619" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007620 call inputsave()
7621 let pat= input("Enter pattern: ","")
7622 call inputrestore()
7623 let patbang = ""
7624 if pat =~ '^!'
7625 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007626 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007627 endif
7628 if pat =~ '^\i'
7629 let pat = escape(pat,'/')
7630 let pat = '/'.pat.'/'
7631 else
7632 let nonisi = pat[0]
7633 endif
7634
7635 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007636" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007637 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007638 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007639 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007640 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007641" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7642 return
7643 endtry
7644 echo "(use :cn, :cp to navigate, :Rex to return)"
7645
7646 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007647" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7648 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007649
7650 if exists("nonisi")
7651 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007653 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007654 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007655 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007656 endif
7657
7658" call Dret("s:NetrwMarkFileGrep")
7659endfun
7660
7661" ---------------------------------------------------------------------
7662" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7663" uses the global marked file list
7664" s:netrwmfloc= 0: target directory is remote
7665" = 1: target directory is local
7666fun! s:NetrwMarkFileMove(islocal)
7667" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007668 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007669 let curbufnr = bufnr("%")
7670
7671 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007672 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007673 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007674" call Dret("s:NetrwMarkFileMove")
7675 return
7676 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007677" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007678
Bram Moolenaar446cb832008-06-24 21:56:24 +00007679 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007680 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007681" call Dret("s:NetrwMarkFileCopy 0")
7682 return 0
7683 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007684" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007685
7686 if a:islocal && s:netrwmftgt_islocal
7687 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007688" call Decho("move from local to local",'~'.expand("<slnum>"))
7689" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007690 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007691 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7692" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7693 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007694 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007695 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007696" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007697 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007698 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007699" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007700 if g:netrw_localmovecmd =~ '\s'
7701 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7702 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7703 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007704" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007705 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007706 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007707" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007708 endif
7709 else
7710 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007711" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007712 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007713 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007714 if g:netrw_keepdir
7715 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7716 let fname= b:netrw_curdir."/".fname
7717 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007718 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007719 let fname= substitute(fname,'/','\\','g')
7720 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007721" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007722 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007723 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007724 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007725 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 +01007726 else
7727 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7728 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007729 break
7730 endif
7731 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007732
7733 elseif a:islocal && !s:netrwmftgt_islocal
7734 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007735" call Decho("move from local to remote",'~'.expand("<slnum>"))
7736" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007737 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007738 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007739" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007740 for fname in mflist
7741 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7742 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7743 endfor
7744 unlet mflist
7745
7746 elseif !a:islocal && s:netrwmftgt_islocal
7747 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007748" call Decho("move from remote to local",'~'.expand("<slnum>"))
7749" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007750 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007751 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007752" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007753 for fname in mflist
7754 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7755 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7756 endfor
7757 unlet mflist
7758
7759 elseif !a:islocal && !s:netrwmftgt_islocal
7760 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007761" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7762" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007763 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007764 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007765" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007766 for fname in mflist
7767 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7768 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7769 endfor
7770 unlet mflist
7771 endif
7772
7773 " -------
7774 " cleanup
7775 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007776" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007777
7778 " remove markings from local buffer
7779 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7780
7781 " refresh buffers
7782 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007783" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007784 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007785 endif
7786 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007787" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007788 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007789 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007790 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007791" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007792 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007793 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007794
Bram Moolenaar446cb832008-06-24 21:56:24 +00007795" call Dret("s:NetrwMarkFileMove")
7796endfun
7797
7798" ---------------------------------------------------------------------
7799" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7800" using the hardcopy command. Local marked-file list only.
7801fun! s:NetrwMarkFilePrint(islocal)
7802" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7803 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007804
7805 " sanity check
7806 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007807 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007808" call Dret("s:NetrwMarkFilePrint")
7809 return
7810 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007811" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7812 let curdir= s:NetrwGetCurdir(a:islocal)
7813
Bram Moolenaar446cb832008-06-24 21:56:24 +00007814 if exists("s:netrwmarkfilelist_{curbufnr}")
7815 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007816 call s:NetrwUnmarkList(curbufnr,curdir)
7817 for fname in netrwmarkfilelist
7818 if a:islocal
7819 if g:netrw_keepdir
7820 let fname= s:ComposePath(curdir,fname)
7821 endif
7822 else
7823 let fname= curdir.fname
7824 endif
7825 1split
7826 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007827" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007828 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007829" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007830 hardcopy
7831 q
7832 endfor
7833 2match none
7834 endif
7835" call Dret("s:NetrwMarkFilePrint")
7836endfun
7837
7838" ---------------------------------------------------------------------
7839" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7840" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007841" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007842fun! s:NetrwMarkFileRegexp(islocal)
7843" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7844
7845 " get the regular expression
7846 call inputsave()
7847 let regexp= input("Enter regexp: ","","file")
7848 call inputrestore()
7849
7850 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007851 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007852" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007853 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007854" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007855 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007856 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007857 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007858 else
7859 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007860 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007861 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007862" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007863
7864 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007865 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007866 if fname =~ '^'.fnameescape(curdir)
7867" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7868 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7869 else
7870" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7871 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7872 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007873 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007874
7875 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007876" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007877
7878 " convert displayed listing into a filelist
7879 let eikeep = &ei
7880 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007881 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007882 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007883" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007884 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007885 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007886 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007887 sil NetrwKeepj norm! "ap
7888 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007889 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007890 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007891 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007892 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007893 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007894 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007896 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007897 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007898 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007899 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7900 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007901 call histdel("/",-1)
7902 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007903 endif
7904 " convert regexp into the more usual glob-style format
7905 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007906" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007907 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007908 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909 let filelist= getline(1,line("$"))
7910 q!
7911 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007912 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007913 endfor
7914 unlet filelist
7915 let @a = areg
7916 let &ei = eikeep
7917 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007918 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007919
7920" call Dret("s:NetrwMarkFileRegexp")
7921endfun
7922
7923" ---------------------------------------------------------------------
7924" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7925" Uses the local marked file list.
7926fun! s:NetrwMarkFileSource(islocal)
7927" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7928 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007929
7930 " sanity check
7931 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007932 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007933" call Dret("s:NetrwMarkFileSource")
7934 return
7935 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007936" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7937 let curdir= s:NetrwGetCurdir(a:islocal)
7938
Bram Moolenaar446cb832008-06-24 21:56:24 +00007939 if exists("s:netrwmarkfilelist_{curbufnr}")
7940 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007941 call s:NetrwUnmarkList(curbufnr,curdir)
7942 for fname in netrwmarkfilelist
7943 if a:islocal
7944 if g:netrw_keepdir
7945 let fname= s:ComposePath(curdir,fname)
7946 endif
7947 else
7948 let fname= curdir.fname
7949 endif
7950 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007951" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007952 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007953 endfor
7954 2match none
7955 endif
7956" call Dret("s:NetrwMarkFileSource")
7957endfun
7958
7959" ---------------------------------------------------------------------
7960" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7961" Uses the global markfilelist
7962fun! s:NetrwMarkFileTag(islocal)
7963" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007964 let svpos = winsaveview()
7965" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007966 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007967 let curbufnr = bufnr("%")
7968
Bram Moolenaarff034192013-04-24 18:51:19 +02007969 " sanity check
7970 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007971 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007972" call Dret("s:NetrwMarkFileTag")
7973 return
7974 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007975" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007976
Bram Moolenaar446cb832008-06-24 21:56:24 +00007977 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007978" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
7979 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007980 call s:NetrwUnmarkAll()
7981
7982 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007983
7984" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
7985 call system(g:netrw_ctags." ".netrwmarkfilelist)
7986 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007987 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7988 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007989
Bram Moolenaar446cb832008-06-24 21:56:24 +00007990 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007991 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007992 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007993 let curdir= b:netrw_curdir
7994 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007995 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007996 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007997" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007998 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007999 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008000 wq!
8001 endif
8002 2match none
8003 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008004" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8005 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006 endif
8007
8008" call Dret("s:NetrwMarkFileTag")
8009endfun
8010
8011" ---------------------------------------------------------------------
8012" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008013" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008014" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008015" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008016" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008017fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008018" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8019 let svpos = winsaveview()
8020" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008021 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008022 let hadtgt = exists("s:netrwmftgt")
8023 if !exists("w:netrw_bannercnt")
8024 let w:netrw_bannercnt= b:netrw_bannercnt
8025 endif
8026
8027 " set up target
8028 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008029" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008030 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8031 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008032" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008033 unlet s:netrwmftgt s:netrwmftgt_islocal
8034 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008035 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008036 endif
8037 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008038" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8039 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008040" call Dret("s:NetrwMarkFileTgt : removed target")
8041 return
8042 else
8043 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008044" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008045 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008046
8047 else
8048 " get word under cursor.
8049 " * If directory, use it for the target.
8050 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008051" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008052 let curword= s:NetrwGetWord()
8053 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008054 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008055 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008056" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008057 elseif !a:islocal && tgtdir =~ '/$'
8058 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008059" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008060 else
8061 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008062" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008063 endif
8064 endif
8065 if a:islocal
8066 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8067 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008068" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008069 endif
8070 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008071 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008072 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8073 endif
8074 let s:netrwmftgt_islocal= a:islocal
8075
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008076 " need to do refresh so that the banner will be updated
8077 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008078 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008079" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008080 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008081 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008082" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008083 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008084 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8085 else
8086 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8087 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008088" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8089 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008090 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008091 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008092 endif
8093
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008094" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8095" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008096" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8097endfun
8098
8099" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008100" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8101fun! s:NetrwGetCurdir(islocal)
8102" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8103
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008104 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008105 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8106" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8107 elseif !exists("b:netrw_curdir")
8108 let b:netrw_curdir= getcwd()
8109" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8110 endif
8111
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008112" 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 +01008113 if b:netrw_curdir !~ '\<\a\{3,}://'
8114 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008115" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008116 if g:netrw_keepdir == 0
8117 call s:NetrwLcd(curdir)
8118 endif
8119 endif
8120
8121" call Dret("s:NetrwGetCurdir <".curdir.">")
8122 return b:netrw_curdir
8123endfun
8124
8125" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008126" s:NetrwOpenFile: query user for a filename and open it {{{2
8127fun! s:NetrwOpenFile(islocal)
8128" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008129 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008130 call inputsave()
8131 let fname= input("Enter filename: ")
8132 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008133" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8134
8135 " determine if Lexplore is in use
8136 if exists("t:netrw_lexbufnr")
8137 " check if t:netrw_lexbufnr refers to a netrw window
8138" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8139 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8140 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8141" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8142 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8143 exe "NetrwKeepj e ".fnameescape(fname)
8144 let @@= ykeep
8145" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8146 endif
8147 endif
8148
8149 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008150 if fname !~ '[/\\]'
8151 if exists("b:netrw_curdir")
8152 if exists("g:netrw_quiet")
8153 let netrw_quiet_keep = g:netrw_quiet
8154 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008155 let g:netrw_quiet = 1
8156 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008157 let s:rexposn_{bufnr("%")}= winsaveview()
8158" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008159 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008160 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008161 else
8162 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8163 endif
8164 if exists("netrw_quiet_keep")
8165 let g:netrw_quiet= netrw_quiet_keep
8166 else
8167 unlet g:netrw_quiet
8168 endif
8169 endif
8170 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008171 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008172 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008173 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008174" call Dret("s:NetrwOpenFile")
8175endfun
8176
8177" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008178" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8179" For the mapping to this function be made via
8180" netrwPlugin, you'll need to have had
8181" g:netrw_usetab set to non-zero.
8182fun! netrw#Shrink()
8183" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8184 let curwin = winnr()
8185 let wiwkeep = &wiw
8186 set wiw=1
8187
8188 if &ft == "netrw"
8189 if winwidth(0) > g:netrw_wiw
8190 let t:netrw_winwidth= winwidth(0)
8191 exe "vert resize ".g:netrw_wiw
8192 wincmd l
8193 if winnr() == curwin
8194 wincmd h
8195 endif
8196" call Decho("vert resize 0",'~'.expand("<slnum>"))
8197 else
8198 exe "vert resize ".t:netrw_winwidth
8199" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8200 endif
8201
8202 elseif exists("t:netrw_lexbufnr")
8203 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8204 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8205 let t:netrw_winwidth= winwidth(0)
8206 exe "vert resize ".g:netrw_wiw
8207 wincmd l
8208 if winnr() == curwin
8209 wincmd h
8210 endif
8211" call Decho("vert resize 0",'~'.expand("<slnum>"))
8212 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8213 exe "vert resize ".t:netrw_winwidth
8214" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8215 else
8216 call netrw#Lexplore(0,0)
8217 endif
8218
8219 else
8220 call netrw#Lexplore(0,0)
8221 endif
8222 let wiw= wiwkeep
8223
8224" call Dret("netrw#Shrink")
8225endfun
8226
8227" ---------------------------------------------------------------------
8228" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8229fun! s:NetSortSequence(islocal)
8230" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8231
8232 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008233 let svpos= winsaveview()
8234" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008235 call inputsave()
8236 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8237 call inputrestore()
8238
8239 " refresh the listing
8240 let g:netrw_sort_sequence= newsortseq
8241 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008242" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8243 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008244 let @@= ykeep
8245
8246" call Dret("NetSortSequence")
8247endfun
8248
8249" ---------------------------------------------------------------------
8250" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8251" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008252" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008253fun! s:NetrwUnmarkList(curbufnr,curdir)
8254" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8255
8256 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008257 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008258 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8259 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8260 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8261 call remove(s:netrwmarkfilelist,idx) " remove from global list
8262 endfor
8263 if s:netrwmarkfilelist == []
8264 unlet s:netrwmarkfilelist
8265 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008266
Bram Moolenaar446cb832008-06-24 21:56:24 +00008267 " getting rid of the local marked-file lists is easy
8268 unlet s:netrwmarkfilelist_{a:curbufnr}
8269 endif
8270 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8271 unlet s:netrwmarkfilemtch_{a:curbufnr}
8272 endif
8273 2match none
8274" call Dret("s:NetrwUnmarkList")
8275endfun
8276
8277" ---------------------------------------------------------------------
8278" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8279fun! s:NetrwUnmarkAll()
8280" call Dfunc("s:NetrwUnmarkAll()")
8281 if exists("s:netrwmarkfilelist")
8282 unlet s:netrwmarkfilelist
8283 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008284 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008285 2match none
8286" call Dret("s:NetrwUnmarkAll")
8287endfun
8288
8289" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008290" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008291fun! s:NetrwUnmarkAll2()
8292" call Dfunc("s:NetrwUnmarkAll2()")
8293 redir => netrwmarkfilelist_let
8294 let
8295 redir END
8296 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008297 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008298 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8299 for flist in netrwmarkfilelist_list
8300 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8301 unlet s:netrwmarkfilelist_{curbufnr}
8302 unlet s:netrwmarkfilemtch_{curbufnr}
8303 endfor
8304" call Dret("s:NetrwUnmarkAll2")
8305endfun
8306
8307" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008308" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8309"
8310" Marked files are in two types of lists:
8311" s:netrwmarkfilelist -- holds complete paths to all marked files
8312" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8313"
8314" Marked files suitable for use with 2match are in:
8315" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008316fun! s:NetrwUnMarkFile(islocal)
8317" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008318 let svpos = winsaveview()
8319" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008320 let curbufnr = bufnr("%")
8321
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008322 " unmark marked file list
8323 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8324 if exists("s:netrwmarkfilelist")
8325" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008326 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008327 endif
8328
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008329 let ibuf= 1
8330 while ibuf < bufnr("$")
8331 if exists("s:netrwmarkfilelist_".ibuf)
8332 unlet s:netrwmarkfilelist_{ibuf}
8333 unlet s:netrwmarkfilemtch_{ibuf}
8334 endif
8335 let ibuf = ibuf + 1
8336 endwhile
8337 2match none
8338
Bram Moolenaar446cb832008-06-24 21:56:24 +00008339" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008340"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8341call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008342" call Dret("s:NetrwUnMarkFile")
8343endfun
8344
8345" ---------------------------------------------------------------------
8346" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8347fun! s:NetrwMenu(domenu)
8348
8349 if !exists("g:NetrwMenuPriority")
8350 let g:NetrwMenuPriority= 80
8351 endif
8352
Bram Moolenaaradc21822011-04-01 18:03:16 +02008353 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008354" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8355
8356 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008357" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008358 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008359 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8360 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8361 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8362 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8363 if g:netrw_dirhistmax > 0
8364 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8365 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8366 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8367 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8368 else
8369 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8370 endif
8371 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8372 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8373 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8374 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8375 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8376 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8377 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8378 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8379 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8380 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8381 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8382 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8383 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8384 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8385 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 +01008386 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 +02008387 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8388 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8389 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8390 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8391 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8392 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8393 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8394 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8395 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8396 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8397 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8398 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8399 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8400 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8401 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8402 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8403 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8404 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8405 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8406 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8407 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8408 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8409 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8410 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8411 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8412 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8413 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8414 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8415 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8416 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>'
8417 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>'
8418 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>'
8419 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8420 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>'
8421 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>'
8422 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 +01008423 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 +02008424 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8425 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008426 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008427 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8428 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008429
8430 elseif !a:domenu
8431 let s:netrwcnt = 0
8432 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008433 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008434 exe curwin."wincmd w"
8435
8436 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008437" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008438 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008439" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008440 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008441 endif
8442 endif
8443" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008444 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008445 endif
8446
8447endfun
8448
8449" ---------------------------------------------------------------------
8450" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8451" Used by the O maps (as <SID>NetrwObtain())
8452fun! s:NetrwObtain(islocal)
8453" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8454
Bram Moolenaar97d62492012-11-15 21:28:22 +01008455 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008456 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008457 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008458 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8460 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008461 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008462 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008463 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008464
8465" call Dret("NetrwObtain")
8466endfun
8467
8468" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008469" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8470" If there's only one window, then the window will first be split.
8471" Returns:
8472" choice = 0 : didn't have to choose
8473" choice = 1 : saved modified file in window first
8474" choice = 2 : didn't save modified file, opened window
8475" choice = 3 : cancel open
8476fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008477" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008478
Bram Moolenaar97d62492012-11-15 21:28:22 +01008479 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008480 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008481 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008482" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008483
8484 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008485 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008486 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008487" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8488" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8489 let curword = s:NetrwGetWord()
8490 let choice = 0
8491 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8492" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008493 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008494" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008495 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008496" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008497" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008498" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008499
Bram Moolenaar8d043172014-01-23 14:24:41 +01008500 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008501 if lastwinnr == 1
8502 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008503" 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 +02008504 " g:netrw_preview=0: preview window shown in a horizontally split window
8505 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008506 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008507 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008508 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008509" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008510 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008511 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008512 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008513 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008514" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008515 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008516 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008517 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008518" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008519
8520 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008521" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008522 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008523" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008524 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008525" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008526 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008527" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008528 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008529" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008530" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008531" call Decho("COMBAK#12: mod=".&mod)
8532
8533 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8534 " whoops -- user trying to open file in the Lexplore window.
8535 " Use Lexplore's opening-file window instead.
8536" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8537" exe g:netrw_chgwin."wincmd w"
8538 wincmd p
8539 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8540 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008541
8542 " prevwinnr: the window number of the "prev" window
8543 " prevbufnr: the buffer number of the buffer in the "prev" window
8544 " bnrcnt : the qty of windows open on the "prev" buffer
8545 let prevwinnr = winnr()
8546 let prevbufnr = bufnr("%")
8547 let prevbufname = bufname("%")
8548 let prevmod = &mod
8549 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008550" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008551 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008552" 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 +01008553" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008554
8555 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008556 " and it doesn't appear in any other extant window, then ask the
8557 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008558 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008559" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008560 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008561" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008562 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008563" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008564
8565 if bnrcnt == 1 && &hidden == 0
8566 " only one copy of the modified buffer in a window, and
8567 " hidden not set, so overwriting will lose the modified file. Ask first...
8568 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008569" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008570 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008571" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008572
8573 if choice == 1
8574 " Yes -- write file & then browse
8575 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008576 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008577 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008578 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008579 exe origwin."wincmd w"
8580 let &ei = eikeep
8581 let @@ = ykeep
8582" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008583 return choice
8584 endif
8585
8586 elseif choice == 2
8587 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008588" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008589 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008590
8591 else
8592 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008593" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008594 exe origwin."wincmd w"
8595 let &ei= eikeep
8596 let @@ = ykeep
8597" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008598 return choice
8599 endif
8600 endif
8601 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008602 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008603 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008604" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008605
8606 " restore b:netrw_curdir (window split/enew may have lost it)
8607 let b:netrw_curdir= curdir
8608 if a:islocal < 2
8609 if a:islocal
8610 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8611 else
8612 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8613 endif
8614 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008615 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008616" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008617 return choice
8618endfun
8619
8620" ---------------------------------------------------------------------
8621" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8622" Always assumed to be local -> remote
8623" call s:NetrwUpload(filename, target)
8624" call s:NetrwUpload(filename, target, fromdirectory)
8625fun! s:NetrwUpload(fname,tgt,...)
8626" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8627
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008628 if a:tgt =~ '^\a\{3,}://'
8629 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008630 else
8631 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8632 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008633" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008634
8635 if a:0 > 0
8636 let fromdir= a:1
8637 else
8638 let fromdir= getcwd()
8639 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008640" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008641
8642 if type(a:fname) == 1
8643 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008644" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008646" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8647 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8648" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008649 if a:tgt =~ '/$'
8650 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008651" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008652 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008653 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008654" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008655 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008656" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008657 endif
8658 q!
8659
8660 elseif type(a:fname) == 3
8661 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008662" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008663 let curdir= getcwd()
8664 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008665 if s:NetrwLcd(fromdir)
8666" call Dret("s:NetrwUpload : lcd failure")
8667 return
8668 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008669 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008670 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008671 if exists("g:netrw_port") && g:netrw_port != ""
8672 let useport= " ".g:netrw_scpport." ".g:netrw_port
8673 else
8674 let useport= ""
8675 endif
8676 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8677 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008678 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 +02008679 if s:NetrwLcd(curdir)
8680" call Dret("s:NetrwUpload : lcd failure")
8681 return
8682 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008683
8684 elseif a:tgt =~ '^ftp:'
8685 call s:NetrwMethod(a:tgt)
8686
8687 if b:netrw_method == 2
8688 " handle uploading a list of files via ftp+.netrc
8689 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008690 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008691" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008692
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008693 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008694" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008695
8696 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008697 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008698" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008699 endif
8700
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008701 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008702" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008703
Bram Moolenaaradc21822011-04-01 18:03:16 +02008704 if tgtdir == ""
8705 let tgtdir= '/'
8706 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008707 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008708" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709
8710 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008711 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8712" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008713 endfor
8714
8715 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008716 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 +00008717 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008718" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8719 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008720 endif
8721 " 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 +01008722 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008723 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008724 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8725 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8726 else
8727 bw!|q
8728 endif
8729
8730 elseif b:netrw_method == 3
8731 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8732 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008733 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008734 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008735 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008736
8737 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008738 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008739" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008740 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008741 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008742" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008743 endif
8744
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008745 if exists("g:netrw_uid") && g:netrw_uid != ""
8746 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008747 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008748" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008749 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008750 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008751 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008752" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008753 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008754 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008755" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008756 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008757 endif
8758
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008759 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008760" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008761
8762 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008763 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008764" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008765 endif
8766
8767 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008768 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008769" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770 endif
8771
8772 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008773 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008774" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008775 endfor
8776
8777 " perform ftp:
8778 " -i : turns off interactive prompting from ftp
8779 " -n unix : DON'T use <.netrc>, even though it exists
8780 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008781 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008782 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008783 " 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 +01008784 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008785 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008786 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8787 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008788 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008789 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8790 let &debug = debugkeep
8791 let mod = 1
8792 else
8793 bw!|q
8794 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008795 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008796" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008797 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008798 endif
8799 else
8800 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8801 endif
8802 endif
8803
8804" call Dret("s:NetrwUpload")
8805endfun
8806
8807" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008808" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008809fun! s:NetrwPreview(path) range
8810" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008811" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8812" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008813 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008814 NetrwKeepj call s:NetrwOptionsSave("s:")
8815 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8816 NetrwKeepj call s:NetrwOptionsSafe(1)
8817 else
8818 NetrwKeepj call s:NetrwOptionsSafe(0)
8819 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008820 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008821" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008822 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008823" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8824 if g:netrw_preview
8825 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008826 let pvhkeep = &pvh
8827 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8828 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008829" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8830 else
8831 " horizontal split
8832 let pvhkeep = &pvh
8833 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8834 let &pvh = winheight(0) - winsz
8835" 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 +02008836 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008837 " g:netrw_preview g:netrw_alto
8838 " 1 : vert 1: top -- preview window is vertically split off and on the left
8839 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8840 " 0 : 1: top -- preview window is horizontally split off and on the top
8841 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8842 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008843 " 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 +02008844 " the BufEnter event set up in netrwPlugin.vim
8845" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8846 let eikeep = &ei
8847 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008848 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008849 let &ei= eikeep
8850" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008851 if exists("pvhkeep")
8852 let &pvh= pvhkeep
8853 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008854 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008855 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856 endif
8857 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008858 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 +00008859 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008860 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008861 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008862" call Dret("NetrwPreview")
8863endfun
8864
8865" ---------------------------------------------------------------------
8866" s:NetrwRefresh: {{{2
8867fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008868" 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 +00008869 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008870 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008871" call Decho("setl ma noro",'~'.expand("<slnum>"))
8872" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008873 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008874 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8875 if !exists("w:netrw_treetop")
8876 if exists("b:netrw_curdir")
8877 let w:netrw_treetop= b:netrw_curdir
8878 else
8879 let w:netrw_treetop= getcwd()
8880 endif
8881 endif
8882 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8883 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008884
8885 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008886 let screenposn = winsaveview()
8887" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008888
8889" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8890" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8891 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008892 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008893 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008894 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008895 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008896 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008897
8898 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008899" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8900 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008901
8902 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008903 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8904 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8905" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8906 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8907 else
8908" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8909 2match none
8910 endif
8911 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008912
Bram Moolenaar97d62492012-11-15 21:28:22 +01008913" restore
8914 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008915" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008916endfun
8917
8918" ---------------------------------------------------------------------
8919" s:NetrwRefreshDir: refreshes a directory by name {{{2
8920" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008921" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008922fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008923" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008924 if g:netrw_fastbrowse == 0
8925 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008926" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008927 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008928" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008929
8930 if tgtwin > 0
8931 " tgtwin is being displayed, so refresh it
8932 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008933" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008934 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008935 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008936 exe curwin."wincmd w"
8937
8938 elseif bufnr(a:dirname) > 0
8939 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008940" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
8941 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008942 endif
8943
8944 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008945" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008946 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008947 endif
8948" call Dret("s:NetrwRefreshDir")
8949endfun
8950
8951" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008952" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8953" window number to do its editing in.
8954" Supports [count]C where the count, if present, is used to specify
8955" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008956fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008957" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008958 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008959" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008960 if a:1 == "" " :NetrwC win#
8961 let g:netrw_chgwin= winnr()
8962 else " :NetrwC
8963 let g:netrw_chgwin= a:1
8964 endif
8965 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008966 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008967 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008968 let g:netrw_chgwin= winnr()
8969 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008970 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008971" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008972endfun
8973
8974" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008975" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8976" What this function does is to compute a priority for the patterns
8977" in the g:netrw_sort_sequence. It applies a substitute to any
8978" "files" that satisfy each pattern, putting the priority / in
8979" front. An "*" pattern handles the default priority.
8980fun! s:NetrwSetSort()
8981" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008982 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008983 if w:netrw_liststyle == s:LONGLIST
8984 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8985 else
8986 let seqlist = g:netrw_sort_sequence
8987 endif
8988 " sanity check -- insure that * appears somewhere
8989 if seqlist == ""
8990 let seqlist= '*'
8991 elseif seqlist !~ '\*'
8992 let seqlist= seqlist.',*'
8993 endif
8994 let priority = 1
8995 while seqlist != ""
8996 if seqlist =~ ','
8997 let seq = substitute(seqlist,',.*$','','e')
8998 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8999 else
9000 let seq = seqlist
9001 let seqlist = ""
9002 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009003 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009004 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009005 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009006 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009007 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009008 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009009 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009010" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009011
9012 " sanity check
9013 if w:netrw_bannercnt > line("$")
9014 " apparently no files were left after a Hiding pattern was used
9015" call Dret("SetSort : no files left after hiding")
9016 return
9017 endif
9018 if seq == '*'
9019 let starpriority= spriority
9020 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009021 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009022 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009023 " sometimes multiple sorting patterns will match the same file or directory.
9024 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009025 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9026 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009027 endif
9028 let priority = priority + 1
9029 endwhile
9030 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009031 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9032 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009033 endif
9034
9035 " Following line associated with priority -- items that satisfy a priority
9036 " pattern get prefixed by ###/ which permits easy sorting by priority.
9037 " Sometimes files can satisfy multiple priority patterns -- only the latest
9038 " priority pattern needs to be retained. So, at this point, these excess
9039 " priority prefixes need to be removed, but not directories that happen to
9040 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009041 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9042 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009043 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009044
9045" call Dret("SetSort")
9046endfun
9047
Bram Moolenaarff034192013-04-24 18:51:19 +02009048" ---------------------------------------------------------------------
9049" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9050" Implements [count]Tb (bookhist<b>)
9051" [count]Th (bookhist<h>)
9052" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009053fun! s:NetrwSetTgt(islocal,bookhist,choice)
9054" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009055
9056 if a:bookhist == 'b'
9057 " supports choosing a bookmark as a target using a qb-generated list
9058 let choice= a:choice - 1
9059 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009060 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009061 else
9062 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9063 endif
9064
9065 elseif a:bookhist == 'h'
9066 " supports choosing a history stack entry as a target using a qb-generated list
9067 let choice= (a:choice % g:netrw_dirhistmax) + 1
9068 if exists("g:netrw_dirhist_".choice)
9069 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009070 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009071 else
9072 echomsg "Sorry, history#".a:choice." not available!"
9073 endif
9074 endif
9075
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009076 " refresh the display
9077 if !exists("b:netrw_curdir")
9078 let b:netrw_curdir= getcwd()
9079 endif
9080 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9081
Bram Moolenaarff034192013-04-24 18:51:19 +02009082" call Dret("s:NetrwSetTgt")
9083endfun
9084
Bram Moolenaar446cb832008-06-24 21:56:24 +00009085" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009086" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009087fun! s:NetrwSortStyle(islocal)
9088" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009089 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009090 let svpos= winsaveview()
9091" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009092
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009093 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 +01009094 NetrwKeepj norm! 0
9095 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009096" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9097 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009098
9099" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9100endfun
9101
9102" ---------------------------------------------------------------------
9103" s:NetrwSplit: mode {{{2
9104" =0 : net and o
9105" =1 : net and t
9106" =2 : net and v
9107" =3 : local and o
9108" =4 : local and t
9109" =5 : local and v
9110fun! s:NetrwSplit(mode)
9111" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9112
Bram Moolenaar97d62492012-11-15 21:28:22 +01009113 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009114 call s:SaveWinVars()
9115
9116 if a:mode == 0
9117 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009118 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009119 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009120" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009121 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009122 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009123 NetrwKeepj call s:RestoreWinVars()
9124 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009125 unlet s:didsplit
9126
9127 elseif a:mode == 1
9128 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009129 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009130" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009131 tabnew
9132 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009133 NetrwKeepj call s:RestoreWinVars()
9134 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009135 unlet s:didsplit
9136
9137 elseif a:mode == 2
9138 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009139 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009140 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009141" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009142 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009143 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009144 NetrwKeepj call s:RestoreWinVars()
9145 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009146 unlet s:didsplit
9147
9148 elseif a:mode == 3
9149 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009150 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009151 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009152" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009153 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009154 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009155 NetrwKeepj call s:RestoreWinVars()
9156 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009157 unlet s:didsplit
9158
9159 elseif a:mode == 4
9160 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009161 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009162 let eikeep = &ei
9163 let netrw_winnr = winnr()
9164 let netrw_line = line(".")
9165 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009166 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009167 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009168 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009169 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9170 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009171 let &ei = eikeep
9172 let netrw_curdir = s:NetrwTreeDir(0)
9173" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009174 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009175 let b:netrw_curdir = netrw_curdir
9176 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009177 NetrwKeepj call s:RestoreWinVars()
9178 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009179 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009180 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009181 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9182 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009183 let &ei= eikeep
9184 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009185 unlet s:didsplit
9186
9187 elseif a:mode == 5
9188 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009189 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009190 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009191" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009192 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009193 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009194 NetrwKeepj call s:RestoreWinVars()
9195 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009196 unlet s:didsplit
9197
9198 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009199 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009200 endif
9201
Bram Moolenaar97d62492012-11-15 21:28:22 +01009202 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009203" call Dret("s:NetrwSplit")
9204endfun
9205
9206" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009207" s:NetrwTgtMenu: {{{2
9208fun! s:NetrwTgtMenu()
9209 if !exists("s:netrw_menucnt")
9210 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009211 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009212" call Dfunc("s:NetrwTgtMenu()")
9213
9214 " the following test assures that gvim is running, has menus available, and has menus enabled.
9215 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9216 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009217" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009218 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9219 endif
9220 if !exists("s:netrw_initbookhist")
9221 call s:NetrwBookHistRead()
9222 endif
9223
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009224 " try to cull duplicate entries
9225 let tgtdict={}
9226
Bram Moolenaarff034192013-04-24 18:51:19 +02009227 " target bookmarked places
9228 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009229" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009230 let cnt= 1
9231 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009232 if has_key(tgtdict,bmd)
9233 let cnt= cnt + 1
9234 continue
9235 endif
9236 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009237 let ebmd= escape(bmd,g:netrw_menu_escape)
9238 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009239" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009240 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 +02009241 let cnt= cnt + 1
9242 endfor
9243 endif
9244
9245 " target directory browsing history
9246 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009247" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009248 let histcnt = 1
9249 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009250 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009251 if exists("g:netrw_dirhist_{histcnt}")
9252 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009253 if has_key(tgtdict,histentry)
9254 let histcnt = histcnt + 1
9255 continue
9256 endif
9257 let tgtdict[histentry] = histcnt
9258 let ehistentry = escape(histentry,g:netrw_menu_escape)
9259" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009260 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 +02009261 endif
9262 let histcnt = histcnt + 1
9263 endwhile
9264 endif
9265 endif
9266" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267endfun
9268
9269" ---------------------------------------------------------------------
9270" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9271" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009272fun! s:NetrwTreeDir(islocal)
9273" 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 +02009274" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009275" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9276" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9277" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009278" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009279
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009280 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009281 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009282" 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 +01009283 let treedir= s:treedir
9284 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009285 unlet s:prevwinopen
9286" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009287 return treedir
9288 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009289 if exists("s:prevwinopen")
9290 unlet s:prevwinopen
9291 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009292" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009293
Bram Moolenaar8d043172014-01-23 14:24:41 +01009294 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9295 let b:netrw_curdir= getcwd()
9296 endif
9297 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009298" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009299" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009300
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009301 let s:treecurpos= winsaveview()
9302" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009303" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009304
9305 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009306" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9307" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009308" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009309
9310 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009311 let curline= substitute(getline('.'),"\t -->.*$",'','')
9312 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009313" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009314 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009315" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9316 elseif curline =~ '@$'
9317" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009318 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009319" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009320 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009321" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009322 let treedir= ""
9323 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009324" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009325
9326 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009327" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9328" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009329" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009330 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009331" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009333" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9334 sil! NetrwKeepj %d _
9335" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009336 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009337" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009338" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009339 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009340" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009341
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009342" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009343" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009344" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009345
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009346 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9347" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9348" let newdir = w:netrw_treetop.'/'.potentialdir
9349" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9350" let treedir = s:NetrwTreePath(newdir)
9351" let w:netrw_treetop = newdir
9352" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9353" else
9354" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009355 if a:islocal && curline =~ '@$'
9356 if isdirectory(s:NetrwFile(potentialdir))
9357 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9358 let w:netrw_treetop = treedir
9359 endif
9360 else
9361 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9362 let treedir = s:NetrwTreePath(w:netrw_treetop)
9363 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009364 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009365" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009366
9367 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009368 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009369" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009370" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009371
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009372" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009373 return treedir
9374endfun
9375
9376" ---------------------------------------------------------------------
9377" s:NetrwTreeDisplay: recursive tree display {{{2
9378fun! s:NetrwTreeDisplay(dir,depth)
9379" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9380
9381 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009382 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009383
9384 " install ../ and shortdir
9385 if a:depth == ""
9386 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009387" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009388 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009389 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009390 if a:dir == w:netrw_treetop
9391 let shortdir= a:dir
9392 else
9393 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9394 endif
9395 call setline(line("$")+1,a:depth.shortdir)
9396 else
9397 let shortdir= substitute(a:dir,'^.*/','','e')
9398 call setline(line("$")+1,a:depth.shortdir.'/')
9399 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009400" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009401 " append a / to dir if its missing one
9402 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009403
9404 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009405 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009406" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009407
Bram Moolenaar85850f32019-07-19 22:05:51 +02009408 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9409 if g:netrw_hide == 1
9410 " hide given patterns
9411 let listhide= split(g:netrw_list_hide,',')
9412" call Decho("listhide=".string(listhide))
9413 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009414 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009415 endfor
9416
9417 elseif g:netrw_hide == 2
9418 " show given patterns (only)
9419 let listhide= split(g:netrw_list_hide,',')
9420" call Decho("listhide=".string(listhide))
9421 let entries=[]
9422 for entry in w:netrw_treedict[dir]
9423 for pat in listhide
9424 if entry =~ pat
9425 call add(entries,entry)
9426 break
9427 endif
9428 endfor
9429 endfor
9430 let w:netrw_treedict[dir]= entries
9431 endif
9432 if depth != ""
9433 " always remove "." and ".." entries when there's depth
9434 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9435 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9436 endif
9437
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009438" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009439 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009440 if dir =~ '/$'
9441 let direntry= substitute(dir.entry,'[@/]$','','e')
9442 else
9443 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9444 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009445" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009446 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009447" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009448 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009449 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009450" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9451 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9452 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9453" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009454 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009455 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009456" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009457 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009458 endif
9459 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009460" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009461
Bram Moolenaar446cb832008-06-24 21:56:24 +00009462" call Dret("NetrwTreeDisplay")
9463endfun
9464
9465" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009466" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9467fun! s:NetrwRefreshTreeDict(dir)
9468" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009469 if !exists("w:netrw_treedict")
9470" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9471 return
9472 endif
9473
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009474 for entry in w:netrw_treedict[a:dir]
9475 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9476" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9477
9478 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9479" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9480 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009481 let liststar = s:NetrwGlob(direntry,'*',1)
9482 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009483 let w:netrw_treedict[direntry] = liststar + listdotstar
9484" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9485
9486 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9487" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9488 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009489 let liststar = s:NetrwGlob(direntry.'/','*',1)
9490 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009491 let w:netrw_treedict[direntry]= liststar + listdotstar
9492" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9493
9494 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9495" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9496 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009497 let liststar = s:NetrwGlob(direntry.'/','*',1)
9498 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009499" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9500
9501 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009502" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009503 endif
9504 endfor
9505" call Dret("s:NetrwRefreshTreeDict")
9506endfun
9507
9508" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009509" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009510" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009511fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009512 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009513" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009514" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9515" call Decho("win#".winnr().": w:netrw_treetop ".(exists("w:netrw_treetop")? "exists" : "doesn't exist")." w:netrw_treedict ".(exists("w:netrw_treedict")? "exists" : "doesn't exit"),'~'.expand("<slnum>"))
9516" 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 +00009517
9518 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009519 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009520" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009521 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009522 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009523" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009524 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009525" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009526 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009527 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009528" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009529 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009530 if exists("w:netrw_treetop")
9531 let s:netrw_treetop= w:netrw_treetop
9532 else
9533 let w:netrw_treetop= getcwd()
9534 let s:netrw_treetop= w:netrw_treetop
9535 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009536
Bram Moolenaar446cb832008-06-24 21:56:24 +00009537 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009538 " insure that we have a treedict, albeit empty
9539" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009540 let w:netrw_treedict= {}
9541 endif
9542
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009543 " update the dictionary for the current directory
9544" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009545" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009546 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009547 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009548" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009549 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009550
9551 " if past banner, record word
9552 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9553 let fname= expand("<cword>")
9554 else
9555 let fname= ""
9556 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009557" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9558" 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 +00009559
9560 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009561" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009562 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009563" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009564
9565 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9566 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009567" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009568 1d
9569 endwhile
9570
Bram Moolenaar13600302014-05-22 18:26:40 +02009571 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009572
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009573" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009574 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009575 endif
9576endfun
9577
9578" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009579" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009580" Normally, treetop is w:netrw_treetop, but a
9581" user of the function ( netrw#SetTreetop() )
9582" wipes that out prior to calling this function
9583fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009584" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9585 if line(".") < w:netrw_bannercnt + 2
9586 let treedir= a:treetop
9587 if treedir !~ '/$'
9588 let treedir= treedir.'/'
9589 endif
9590" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9591 return treedir
9592 endif
9593
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009594 let svpos = winsaveview()
9595" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009596 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009597" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009598 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009599" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9600 let curline= getline('.')
9601" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9602 if curline =~ '/$'
9603" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9604 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9605" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9606 elseif curline =~ '@\s\+-->'
9607" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9608 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9609 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9610" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009611 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009612" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009613 let treedir= ""
9614 endif
9615 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009616" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9617" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009618 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9619 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9620 let treedir= dirname.treedir
9621 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009622" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009623 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009624" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009625 if a:treetop =~ '/$'
9626 let treedir= a:treetop.treedir
9627 else
9628 let treedir= a:treetop.'/'.treedir
9629 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009630" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009631 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009632" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009633" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9634 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009635" call Dret("s:NetrwTreePath <".treedir.">")
9636 return treedir
9637endfun
9638
9639" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009640" s:NetrwWideListing: {{{2
9641fun! s:NetrwWideListing()
9642
9643 if w:netrw_liststyle == s:WIDELIST
9644" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9645 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009646 " cpf: characters per filename
9647 " fpl: filenames per line
9648 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009649 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009650 let dict={}
9651 " save the unnamed register and register 0-9 and a
9652 let dict.a=[getreg('a'), getregtype('a')]
9653 for i in range(0, 9)
9654 let dict[i] = [getreg(i), getregtype(i)]
9655 endfor
9656 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009657" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 let b:netrw_cpf= 0
9659 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009660 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009661 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9662 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009663 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009664 " restore stored registers
9665 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009666" call Dret("NetrwWideListing")
9667 return
9668 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009669 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009670 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009671" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009672
9673 " determine qty files per line (fpl)
9674 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9675 if w:netrw_fpl <= 0
9676 let w:netrw_fpl= 1
9677 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009678" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679
9680 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009681 " fpc: files per column of wide listing
9682 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009683 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009684 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9685 let newcolstart = w:netrw_bannercnt + fpc
9686 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009687" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009688 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009689" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009690 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009691 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009692 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009693 while line("$") >= newcolstart
9694 if newcolend > line("$") | let newcolend= line("$") | endif
9695 let newcolqty= newcolend - newcolstart
9696 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009697 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009698 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009699 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009700 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009701 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009702 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009703 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009704 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009705 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009706 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009707" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009708 if @* != keepregstar | sil! let @* = keepregstar | endif
9709 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009710 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009711 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9712 NetrwKeepj call histdel("/",-1)
9713 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9714 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009715" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009716 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009717 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009718" 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 +00009719" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009720 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009721 else
9722 if hasmapto("w","n")
9723 sil! nunmap <buffer> w
9724 endif
9725 if hasmapto("b","n")
9726 sil! nunmap <buffer> b
9727 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009728 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009729endfun
9730
9731" ---------------------------------------------------------------------
9732" s:PerformListing: {{{2
9733fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009734" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9735" 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 +02009736" 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>"))
9737 sil! NetrwKeepj %d _
9738" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009739
Bram Moolenaar15146672011-10-20 22:22:38 +02009740 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009741" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009742 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009743
Bram Moolenaar85850f32019-07-19 22:05:51 +02009744 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009745 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009746" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009747
9748" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009749" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009750" endif " Decho
9751
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009752" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009753 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9754 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009755" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9756 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009757 endif
9758
9759 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009760 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009761
9762 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009763 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009764" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009765 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009766 if exists("g:netrw_pchk")
9767 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9768 " failure detections.
9769 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009770 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009771 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9772 endif
9773 if exists("g:netrw_pchk")
9774 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9775 else
9776 let curdir= b:netrw_curdir
9777 endif
9778 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9779 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9780 else
9781 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009782 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009783 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009784 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009785 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009786" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009787 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009788 let w:netrw_bannercnt= 1
9789 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009790" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9791" 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 +00009792
Bram Moolenaar85850f32019-07-19 22:05:51 +02009793 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009794 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009795 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009796 let sortby= sortby." reversed"
9797 endif
9798
9799 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009800 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009801" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009802 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009803" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009804 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009805 NetrwKeepj put ='\" Sorted by '.sortby
9806 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009807 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9808 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009809" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009810 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009811 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009812 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9813 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009814 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009815" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009816" 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 +00009817 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009818
Bram Moolenaar85850f32019-07-19 22:05:51 +02009819 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009820 if g:netrw_banner
9821 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009822" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009823 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009824 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009825 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009826 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009827 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009828 endif
9829 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009830 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009831" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009832 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009833 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009835
9836 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009837 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009838" 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 +01009839 if g:netrw_list_hide != "" && g:netrw_hide
9840 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009841 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009842 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009843 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009844 endif
9845 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009846 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009847 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009848
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009849" 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 +01009850 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009851" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009852 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009853" 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 +01009854 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009855 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009856" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009857" 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 +00009858 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009859
9860 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009861 if g:netrw_banner
9862 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009863 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009864" 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 +01009865" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009866" 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 +01009867 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009868
Bram Moolenaar446cb832008-06-24 21:56:24 +00009869 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009870" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009871 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009872 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009873 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009874 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009875 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009876" 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 +01009877" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9878 return
9879 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009880 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009881
9882 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009883 if !exists("w:netrw_bannercnt")
9884 let w:netrw_bannercnt= 0
9885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009886" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9887" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9888" 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 +01009889
Bram Moolenaar5c736222010-01-06 20:54:52 +01009890 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009891" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009892" 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 +00009893 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009894 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009895 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009896 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009897" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009898
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009899 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009900 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009901" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009902 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009903
Bram Moolenaar5c736222010-01-06 20:54:52 +01009904 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009905" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009906 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009907 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009908 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009909 else
9910 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009911 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009912 endif
9913 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009914
Bram Moolenaar446cb832008-06-24 21:56:24 +00009915 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009916" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009917 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9918 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009919
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009920 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009921 " exten: sort by extension
9922 " The histdel(...,-1) calls remove the last search from the search history
9923" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009924 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9925 NetrwKeepj call histdel("/",-1)
9926 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9927 NetrwKeepj call histdel("/",-1)
9928 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9929 NetrwKeepj call histdel("/",-1)
9930 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9931" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009932 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009933 " normal direction sorting
9934 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9935 else
9936 " reverse direction sorting
9937 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9938 endif
9939 endif
9940 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9941 NetrwKeepj call histdel("/",-1)
9942
Bram Moolenaar446cb832008-06-24 21:56:24 +00009943 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009944 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009945" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009946 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009947" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009948 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009949 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009950" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009951 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009952 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009953" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009954 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9955 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009956 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009957 endif
9958
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009959 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009960" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009961 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009962 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009963 call histdel("/",-1)
9964 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009965 endif
9966 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009967" 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 +00009968
9969 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009970" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9971" 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 +01009972 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009973" 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 +01009974 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009975" 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 +00009976
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009977 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009978 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009979" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009980 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009981 endif
9982
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009983 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009984 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009985" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9986 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009987 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009988" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9989 else
9990" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9991" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9992" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9993" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009994 endif
9995
9996 " record previous current directory
9997 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009999
10000 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010001" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10002" 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 +010010003 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010004" 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 +020010005 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010006" 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 +000010007
10008 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010009" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010010 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010011" 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 +010010012 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010013" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010014 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10015 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010016" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010017" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018
Bram Moolenaar8d043172014-01-23 14:24:41 +010010019 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010020" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10021" 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 +010010022" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10023 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010024 unlet s:treecurpos
10025 endif
10026
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. " (return)",'~'.expand("<slnum>"))
10028" 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 +000010029" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10030endfun
10031
10032" ---------------------------------------------------------------------
10033" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010034fun! s:SetupNetrwStatusLine(statline)
10035" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10036
10037 if !exists("s:netrw_setup_statline")
10038 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010039" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010040
10041 if !exists("s:netrw_users_stl")
10042 let s:netrw_users_stl= &stl
10043 endif
10044 if !exists("s:netrw_users_ls")
10045 let s:netrw_users_ls= &laststatus
10046 endif
10047
10048 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010049 let dict={}
10050 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010051 redir @a
10052 try
10053 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010054 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010055 if &bg == "dark"
10056 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10057 else
10058 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10059 endif
10060 endtry
10061 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010062 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010063 endif
10064
10065 " set up status line (may use User9 highlighting)
10066 " insure that windows have a statusline
10067 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010068 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010069 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010070" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010071 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010072
10073" call Dret("SetupNetrwStatusLine : stl=".&stl)
10074endfun
10075
Bram Moolenaar85850f32019-07-19 22:05:51 +020010076" =========================================
10077" Remote Directory Browsing Support: {{{1
10078" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010079
10080" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010081" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10082" This function assumes that a long listing will be received. Size, time,
10083" and reverse sorts will be requested of the server but not otherwise
10084" enforced here.
10085fun! s:NetrwRemoteFtpCmd(path,listcmd)
10086" 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 +010010087" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010088 " sanity check: {{{3
10089 if !exists("w:netrw_method")
10090 if exists("b:netrw_method")
10091 let w:netrw_method= b:netrw_method
10092 else
10093 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10094" call Dret("NetrwRemoteFtpCmd")
10095 return
10096 endif
10097 endif
10098
10099 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10100 let ffkeep= &ff
10101 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010102" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010103
10104 " clear off any older non-banner lines " {{{3
10105 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010106" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10107 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010108
10109 ".........................................
10110 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10111 " ftp + <.netrc>: Method #2
10112 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010113 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010114 endif
10115 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010116 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010117" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010118 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010119 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010121 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010122" 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>"))
10123 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 +010010124 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010125" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10126 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 +010010127 endif
10128
10129 ".........................................
10130 elseif w:netrw_method == 3 " {{{3
10131 " ftp + machine,id,passwd,filename: Method #3
10132 setl ff=unix
10133 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010134 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010135 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010136 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010137 endif
10138
10139 " handle userid and password
10140 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010141" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010142 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10143 call NetUserPass("ftp:".host)
10144 endif
10145 if exists("g:netrw_uid") && g:netrw_uid != ""
10146 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010147 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010148 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010149 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010150 endif
10151 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010152 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010153 endif
10154 endif
10155
10156 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010157 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010158 endif
10159 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010160 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010161" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010162 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010163 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010164
10165 " perform ftp:
10166 " -i : turns off interactive prompting from ftp
10167 " -n unix : DON'T use <.netrc>, even though it exists
10168 " -n win32: quit being obnoxious about password
10169 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010170" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010171 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010172" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010173" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10174" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010175 endif
10176
10177 ".........................................
10178 elseif w:netrw_method == 9 " {{{3
10179 " sftp username@machine: Method #9
10180 " s:netrw_sftp_cmd
10181 setl ff=unix
10182
10183 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010184 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010185" call Dret("NetrwRemoteFtpCmd")
10186 return
10187
10188 ".........................................
10189 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010190 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010191 endif
10192
10193 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010194 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010195 sil! NetrwKeepj %s/\r$//e
10196 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010197 endif
10198 if a:listcmd == "dir"
10199 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010200 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10201 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10202 NetrwKeepj call histdel("/",-1)
10203 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010204 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 +010010205 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10206 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010207 endif
10208 endif
10209
10210 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10211 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010212 exe 'NetrwKeepj '.w:netrw_bannercnt
10213 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010214 endif
10215 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010216 exe 'NetrwKeepj '.w:netrw_bannercnt
10217 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010218 endif
10219
10220 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010221 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010222" call Dret("NetrwRemoteFtpCmd")
10223endfun
10224
10225" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010226" s:NetrwRemoteListing: {{{2
10227fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010228" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010229
Bram Moolenaara6878372014-03-22 21:02:50 +010010230 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10231 let w:netrw_bannercnt= s:bannercnt
10232 endif
10233 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010234 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010235 endif
10236
Bram Moolenaar446cb832008-06-24 21:56:24 +000010237 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010238
Bram Moolenaar446cb832008-06-24 21:56:24 +000010239 " sanity check:
10240 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010241" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010242 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010243" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010244 if !exists("g:netrw_quiet")
10245 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10246 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010247 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010248" call Dret("s:NetrwRemoteListing -1")
10249 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010250 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010251
Bram Moolenaar8d043172014-01-23 14:24:41 +010010252 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010253" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010254 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010255 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010256 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 +000010257 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010258 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 +000010259 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010260 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010261
Bram Moolenaar85850f32019-07-19 22:05:51 +020010262 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010263" call Dret("s:NetrwRemoteListing -1")
10264 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010265 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010266" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010267
Bram Moolenaar446cb832008-06-24 21:56:24 +000010268 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010269" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010270 let w:netrw_method= b:netrw_method
10271 endif
10272
Bram Moolenaar13600302014-05-22 18:26:40 +020010273 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010274 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010275" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010276 let s:method = "ftp"
10277 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010278 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010279 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010280 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010281 let listcmd= g:netrw_ftp_sizelist_cmd
10282 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010283" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010284 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010285" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010286
Bram Moolenaara6878372014-03-22 21:02:50 +010010287 " report on missing file or directory messages
10288 if search('[Nn]o such file or directory\|Failed to change directory')
10289 let mesg= getline(".")
10290 if exists("w:netrw_bannercnt")
10291 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010292 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010293 setl noma
10294 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010295 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010296 call netrw#ErrorMsg(s:WARNING,mesg,96)
10297" call Dret("s:NetrwRemoteListing : -1")
10298 return -1
10299 endif
10300
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010301 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 +000010302 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010303" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010304 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010305
10306 " cleanup
10307 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010308 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10309 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010310 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010311 sil! NetrwKeepj %s/\r$//e
10312 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010313
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010314 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010315 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010316 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010317 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010318" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010319 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010320" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010321 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010322 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010323 exe "sil! NetrwKeepj ".line1
10324 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010325
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010326" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010327 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010328" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010329 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10330 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010331 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010332" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010333 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10334 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10335 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10336 NetrwKeepj call histdel("/",-1)
10337 NetrwKeepj call histdel("/",-1)
10338 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010339 endif
10340 endif
10341
Bram Moolenaar13600302014-05-22 18:26:40 +020010342 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010343 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010344" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010345 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010346" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010347 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010348" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10349 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010350 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010351 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10352 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10353 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10354 NetrwKeepj call histdel("/",-1)
10355 NetrwKeepj call histdel("/",-1)
10356 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010357 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010358 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10359 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010360 endif
10361 else
10362 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010363" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010364 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010365 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010366" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10367 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10368" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010369 endif
10370 endif
10371
10372 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010373 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010374" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010375 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10376 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010377 endif
10378 endif
10379
10380 if w:netrw_liststyle == s:LONGLIST
10381 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010382" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383
10384 if s:method == "ftp"
10385 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010386 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010387 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010388 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010389 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010390 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010391 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010392 sil! NetrwKeepj 1
10393 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010394 let line2= line(".")
10395 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010396 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010397 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010398 endif
10399 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010400 exe "sil! NetrwKeepj ".line1
10401 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010402 endif
10403
10404 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010405" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010406 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 +000010407 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010408" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010409 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010410 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010411 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10412 NetrwKeepj call histdel("/",-1)
10413 NetrwKeepj call histdel("/",-1)
10414 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010415 endif
10416 endif
10417
10418" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010419" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010420" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010421
10422" call Dret("s:NetrwRemoteListing 0")
10423 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010424endfun
10425
Bram Moolenaar446cb832008-06-24 21:56:24 +000010426" ---------------------------------------------------------------------
10427" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10428fun! s:NetrwRemoteRm(usrhost,path) range
10429" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010430" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010431 let svpos= winsaveview()
10432" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010433
10434 let all= 0
10435 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10436 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010437" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010438 for fname in s:netrwmarkfilelist_{bufnr("%")}
10439 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010440 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010441 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010442 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010443 let all= 1
10444 endif
10445 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010446 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447
10448 else
10449 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010450" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010451
10452 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010453 let keepsol = &l:sol
10454 setl nosol
10455 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010456
10457 " remove multiple files and directories
10458 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010459 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010460 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010461 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010462 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010463 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010464 let all= 1
10465 endif
10466 let ctr= ctr + 1
10467 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010468 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010469 endif
10470
10471 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010472" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010473 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010474" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10475 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010476
10477" call Dret("s:NetrwRemoteRm")
10478endfun
10479
10480" ---------------------------------------------------------------------
10481" s:NetrwRemoteRmFile: {{{2
10482fun! s:NetrwRemoteRmFile(path,rmfile,all)
10483" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10484
10485 let all= a:all
10486 let ok = ""
10487
10488 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10489 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010490" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010491 if !all
10492 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010493" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010494 call inputsave()
10495 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10496 call inputrestore()
10497 echohl NONE
10498 if ok == ""
10499 let ok="no"
10500 endif
10501 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010502 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010503 let all= 1
10504 endif
10505 endif
10506
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010507 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010508" 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 +000010509 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010510" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010511 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010512 if path =~ '^\a\{3,}://'
10513 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010515 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010516 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10517 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010518" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010519 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010520" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010521 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010522 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 let ok="q"
10524 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010525 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010526" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10527" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10528" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010529 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010530 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010532 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010533 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010534" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010535 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010536 if v:shell_error != 0
10537 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010538 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 +010010539 else
10540 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10541 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010542 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010543 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010544 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010545" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010546 endif
10547 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010548 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010549" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010550 endif
10551
10552 else
10553 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010554" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010555 if !all
10556 call inputsave()
10557 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10558 call inputrestore()
10559 if ok == ""
10560 let ok="no"
10561 endif
10562 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010563 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010564 let all= 1
10565 endif
10566 endif
10567
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010568 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010569 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010570 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010571 else
10572 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010573 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10574" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010575 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010576" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010577
10578 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010579" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10580 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10581" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010582 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010583" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010584
10585 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010586 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010587 endif
10588 endif
10589 endif
10590
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010591 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010592" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010593 endif
10594 endif
10595
10596" call Dret("s:NetrwRemoteRmFile ".ok)
10597 return ok
10598endfun
10599
10600" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601" s:NetrwRemoteRename: rename a remote file or directory {{{2
10602fun! s:NetrwRemoteRename(usrhost,path) range
10603" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10604
10605 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010606 let svpos = winsaveview()
10607" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010608 let ctr = a:firstline
10609 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10610
10611 " rename files given by the markfilelist
10612 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10613 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010614" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010615 if exists("subfrom")
10616 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010617" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010618 else
10619 call inputsave()
10620 let newname= input("Moving ".oldname." to : ",oldname)
10621 call inputrestore()
10622 if newname =~ '^s/'
10623 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10624 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10625 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010626" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010627 endif
10628 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010629
Bram Moolenaar446cb832008-06-24 21:56:24 +000010630 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010631 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010632 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010633 let oldname= s:ShellEscape(a:path.oldname)
10634 let newname= s:ShellEscape(a:path.newname)
10635" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010636 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010637 endif
10638
10639 endfor
10640 call s:NetrwUnMarkFile(1)
10641
10642 else
10643
10644 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010645 let keepsol= &l:sol
10646 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010647 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010648 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010649
10650 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010651" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010652
10653 call inputsave()
10654 let newname= input("Moving ".oldname." to : ",oldname)
10655 call inputrestore()
10656
10657 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10658 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10659 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010660 let oldname= s:ShellEscape(a:path.oldname)
10661 let newname= s:ShellEscape(a:path.newname)
10662" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010663 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010664 endif
10665
10666 let ctr= ctr + 1
10667 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010669 endif
10670
10671 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010672 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010673" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10674 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675
10676" call Dret("NetrwRemoteRename")
10677endfun
10678
Bram Moolenaar85850f32019-07-19 22:05:51 +020010679" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010680" Local Directory Browsing Support: {{{1
10681" ==========================================
10682
10683" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010684" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010685" Should accept: file://localhost/etc/fstab
10686" file:///etc/fstab
10687" file:///c:/WINDOWS/clock.avi
10688" file:///c|/WINDOWS/clock.avi
10689" file://localhost/c:/WINDOWS/clock.avi
10690" file://localhost/c|/WINDOWS/clock.avi
10691" file://c:/foo.txt
10692" file:///c:/foo.txt
10693" 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 +020010694fun! netrw#FileUrlEdit(fname)
10695" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010696 let fname = a:fname
10697 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010698" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010699 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010700" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010701 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010702 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010703 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010704" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010705 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010706" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010707 endif
10708 endif
10709 let fname2396 = netrw#RFC2396(fname)
10710 let fname2396e= fnameescape(fname2396)
10711 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010712 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010713" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010714 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010715" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010716 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10717 endif
10718 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010719
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010720" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10721" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010722 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010723 exe 'NetrwKeepj keepalt edit '.plainfname
10724 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10725
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010726" 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 +020010727" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010728 exe "sil doau BufReadPost ".fname2396e
10729endfun
10730
10731" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010732" netrw#LocalBrowseCheck: {{{2
10733fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010734 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010735 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10736 "
10737 " unfortunate interaction -- split window debugging can't be used here, must use
10738 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10739 " another call to LocalBrowseCheck() when attempts to write
10740 " to the DBG buffer are made.
10741 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010742 " The &ft == "netrw" test was installed because the BufEnter event
10743 " would hit when re-entering netrw windows, creating unexpected
10744 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010745" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010746" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010747" 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 +010010748 " getting E930: Cannot use :redir inside execute
10749"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010750" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10751" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010752
Bram Moolenaar97d62492012-11-15 21:28:22 +010010753 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010754 if isdirectory(s:NetrwFile(a:dirname))
10755" 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 +010010756
Bram Moolenaar97d62492012-11-15 21:28:22 +010010757 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010758" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10759" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010760 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010761
Bram Moolenaar446cb832008-06-24 21:56:24 +000010762 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010763" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010764 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010765
Bram Moolenaar5c736222010-01-06 20:54:52 +010010766 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010767" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010768 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010769 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010770 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010771" 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 +010010772" call Dret("netrw#LocalBrowseCheck")
10773 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010774 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010775
Bram Moolenaar85850f32019-07-19 22:05:51 +020010776 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010777 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10778 " AND IF the listing style is not a tree listing
10779 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010780" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010781 let ibuf = 1
10782 let buflast = bufnr("$")
10783 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010784 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10785 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010786 endif
10787 let ibuf= ibuf + 1
10788 endwhile
10789 endif
10790 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010791" 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>"))
10792" 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 +000010793 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010794" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010795endfun
10796
10797" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010798" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010799" performed any shell command. The idea is to cause all local-browsing
10800" buffers to be refreshed after a user has executed some shell command,
10801" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010802fun! s:LocalBrowseRefresh()
10803" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010804" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10805" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010806
Bram Moolenaar446cb832008-06-24 21:56:24 +000010807 " determine which buffers currently reside in a tab
10808 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010809" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010810 return
10811 endif
10812 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010813" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010814 return
10815 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010816 if !empty(getcmdwintype())
10817 " cannot move away from cmdline window, see :h E11
10818 return
10819 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010820 if exists("s:netrw_events") && s:netrw_events == 1
10821 " s:LocalFastBrowser gets called (indirectly) from a
10822 let s:netrw_events= 2
10823" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10824 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010825 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010826 let itab = 1
10827 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010829 while itab <= tabpagenr("$")
10830 let buftablist = buftablist + tabpagebuflist()
10831 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010832 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010833 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010834" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10835" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010836 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10837 " | refresh any netrw window
10838 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010839 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010840 let ibl = 0
10841 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010842" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010843 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10844 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010845 " (ibuf not shown in a current window AND
10846 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010847" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10848 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010849 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010850" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010851 continue
10852 elseif index(tabpagebuflist(),ibuf) != -1
10853 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010854" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010855 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010856 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010857 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10858 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10859 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10860 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010861" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010862 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10863 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10864 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010865 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010866 endif
10867 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010868" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010869 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010870" call Decho("restore window: win_gotoid(".curwinid.")")
10871 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010872 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010873
Bram Moolenaara6878372014-03-22 21:02:50 +010010874" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010875endfun
10876
10877" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010878" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10879"
10880" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010881" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010882" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10883" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010884" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010885"
10886" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10887" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010888" (re-using a buffer may not be as accurate)
10889"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010890" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010891" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10892" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10893" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10894" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010895fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010896" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10897" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10898" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10899" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010900
10901 " initialize browselist, a list of buffer numbers that the local browser has used
10902 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010903" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010904 let s:netrw_browselist= []
10905 endif
10906
10907 " append current buffer to fastbrowse list
10908 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010910 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010911" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010912 endif
10913
10914 " enable autocmd events to handle refreshing/removing local browser buffers
10915 " If local browse buffer is currently showing: refresh it
10916 " If local browse buffer is currently hidden : wipe it
10917 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10918 " =1 : medium speed, re-use directory listing for remote only
10919 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010920 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10921 let s:netrw_events= 1
10922 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010923 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010924 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010925" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010926 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010927 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010928" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010929 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010930 endif
10931 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010932
10933 " user must have changed fastbrowse to its fast setting, so remove
10934 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010935 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010936" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010937 unlet s:netrw_events
10938 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010939 au!
10940 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010941 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010942 endif
10943
Bram Moolenaar85850f32019-07-19 22:05:51 +020010944" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010945endfun
10946
10947" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010948" s:LocalListing: does the job of "ls" for local directories {{{2
10949fun! s:LocalListing()
10950" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010951" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
10952" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
10953" 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 +010010954
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010955" 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
10956" 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
10957" 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 +010010958
10959 " get the list of files contained in the current directory
10960 let dirname = b:netrw_curdir
10961 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010962 let filelist = s:NetrwGlob(dirname,"*",0)
10963 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010964" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010965
Nir Lichtman1e34b952024-05-08 19:19:34 +020010966 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010967" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010968 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
10969 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010970" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010971 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010972" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010973 endif
10974
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010975" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010976" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010977" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010978
10979 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
10980 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10981 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010982" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
10983" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010984 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010985" 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 +010010986
10987 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010988" call Decho(" ",'~'.expand("<slnum>"))
10989" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010990
10991 if getftype(filename) == "link"
10992 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010993" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010994 let pfile= filename."@"
10995
10996 elseif getftype(filename) == "socket"
10997 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010998" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010999 let pfile= filename."="
11000
11001 elseif getftype(filename) == "fifo"
11002 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011003" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011004 let pfile= filename."|"
11005
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011006 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011007 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011008" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011009 let pfile= filename."/"
11010
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011011 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011012 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011013 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11014 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011015" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011016 let pfile= filename."*"
11017 else
11018 " normal file
11019 let pfile= filename
11020 endif
11021 elseif executable(filename)
11022 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011023" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011024 let pfile= filename."*"
11025 else
11026 " normal file
11027 let pfile= filename
11028 endif
11029
11030 else
11031 " normal file
11032 let pfile= filename
11033 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011034" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011035
11036 if pfile =~ '//$'
11037 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011038" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011039 endif
11040 let pfile= strpart(pfile,dirnamelen)
11041 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011042" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11043" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011044
11045 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011046 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11047 let sz = getfsize(filename)
11048 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11049 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011050
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011051 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011052 let sz= s:NetrwHumanReadable(sz)
11053 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011054 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011055 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011056" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011057 endif
11058
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011059 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011060 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011061 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011062" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011063" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011064 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011065 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011066" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011067 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011068 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011069
11070 elseif g:netrw_sort_by =~ "^s"
11071 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011072" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011073" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011074 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011075 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011076" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011077 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011078 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011079
11080 else
11081 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011082" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011083" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011084 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011085 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011086" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011087 endfor
11088
11089 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011090 sil! NetrwKeepj g/^$/d
11091 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011092 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011093" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011094 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11095
11096" call Dret("s:LocalListing")
11097endfun
11098
11099" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011100" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11101fun! s:NetrwLocalExecute(cmd)
11102" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11103 let ykeep= @@
11104 " sanity check
11105 if !executable(a:cmd)
11106 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11107 let @@= ykeep
11108" call Dret("s:NetrwLocalExecute")
11109 return
11110 endif
11111
11112 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011113" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011114 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011115" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011116
11117 " strip any ansi escape sequences off
11118 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11119
11120 " show user the result(s)
11121 echomsg result
11122 let @@= ykeep
11123
11124" call Dret("s:NetrwLocalExecute")
11125endfun
11126
11127" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011128" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011129fun! s:NetrwLocalRename(path) range
11130" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11131
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011132 if !exists("w:netrw_bannercnt")
11133 let w:netrw_bannercnt= b:netrw_bannercnt
11134 endif
11135
Bram Moolenaar97d62492012-11-15 21:28:22 +010011136 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011137 let ykeep = @@
11138 let ctr = a:firstline
11139 let svpos = winsaveview()
11140 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011141" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011142
11143 " rename files given by the markfilelist
11144 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11145 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011146" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011147 if exists("subfrom")
11148 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011149" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011150 else
11151 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011152 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011153 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011154 if newname =~ ''
11155 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11156 let newname = substitute(newname,'^.*','','')
11157 elseif newname =~ ''
11158 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11159 let newname = substitute(newname,'[^/]*','','')
11160 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011161 if newname =~ '^s/'
11162 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11163 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011164" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011165 let newname = substitute(oldname,subfrom,subto,'')
11166 endif
11167 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011168 if !all && filereadable(newname)
11169 call inputsave()
11170 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11171 call inputrestore()
11172 if response == "all"
11173 let all= 1
11174 elseif response != "y" && response != "yes"
11175 " refresh the directory
11176" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11177 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11178" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11179 NetrwKeepj call winrestview(svpos)
11180 let @@= ykeep
11181" call Dret("NetrwLocalRename")
11182 return
11183 endif
11184 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011185 call rename(oldname,newname)
11186 endfor
11187 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011188
Bram Moolenaar97d62492012-11-15 21:28:22 +010011189 else
11190
11191 " attempt to rename files/directories
11192 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011193 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011194
11195 " sanity checks
11196 if line(".") < w:netrw_bannercnt
11197 let ctr= ctr + 1
11198 continue
11199 endif
11200 let curword= s:NetrwGetWord()
11201 if curword == "./" || curword == "../"
11202 let ctr= ctr + 1
11203 continue
11204 endif
11205
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011206 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011207 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011208" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011209
11210 call inputsave()
11211 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11212 call inputrestore()
11213
11214 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011215" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011216
11217 let ctr= ctr + 1
11218 endwhile
11219 endif
11220
11221 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011222" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011223 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011224" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11225 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011226 let @@= ykeep
11227
11228" call Dret("NetrwLocalRename")
11229endfun
11230
11231" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011232" s:NetrwLocalRm: {{{2
11233fun! s:NetrwLocalRm(path) range
11234" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011235" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011236
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011237 if !exists("w:netrw_bannercnt")
11238 let w:netrw_bannercnt= b:netrw_bannercnt
11239 endif
11240
Bram Moolenaar446cb832008-06-24 21:56:24 +000011241 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011242 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011243 let ret = 0
11244 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011245 let svpos = winsaveview()
11246" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011247
11248 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11249 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011250" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011251 for fname in s:netrwmarkfilelist_{bufnr("%")}
11252 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011253 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011254 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011255 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011256 let all= 1
11257 endif
11258 endfor
11259 call s:NetrwUnMarkFile(1)
11260
11261 else
11262 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011263" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011264
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011265 let keepsol= &l:sol
11266 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011267 let ctr = a:firstline
11268 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011269 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011270
11271 " sanity checks
11272 if line(".") < w:netrw_bannercnt
11273 let ctr= ctr + 1
11274 continue
11275 endif
11276 let curword= s:NetrwGetWord()
11277 if curword == "./" || curword == "../"
11278 let ctr= ctr + 1
11279 continue
11280 endif
11281 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011282 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011283 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011284 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011285 let all= 1
11286 endif
11287 let ctr= ctr + 1
11288 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011289 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011290 endif
11291
11292 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011293" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011294 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011295 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011296" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11297 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011298 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011299 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011300
11301" call Dret("s:NetrwLocalRm")
11302endfun
11303
11304" ---------------------------------------------------------------------
11305" s:NetrwLocalRmFile: remove file fname given the path {{{2
11306" Give confirmation prompt unless all==1
11307fun! s:NetrwLocalRmFile(path,fname,all)
11308" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011309
Bram Moolenaar446cb832008-06-24 21:56:24 +000011310 let all= a:all
11311 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011312 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011313 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011314" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011315
11316 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11317 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011318" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011319 if !all
11320 echohl Statement
11321 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011322 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011323 call inputrestore()
11324 echohl NONE
11325 if ok == ""
11326 let ok="no"
11327 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011328" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011329 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011330" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011331 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011332 let all= 1
11333 endif
11334 endif
11335
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011336 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011337 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011338" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011339 endif
11340
11341 else
11342 " attempt to remove directory
11343 if !all
11344 echohl Statement
11345 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011346 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011347 call inputrestore()
11348 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11349 if ok == ""
11350 let ok="no"
11351 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011352 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011353 let all= 1
11354 endif
11355 endif
11356 let rmfile= substitute(rmfile,'[\/]$','','e')
11357
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011358 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011359 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011360 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011361 endif
11362 endif
11363 endif
11364
11365" call Dret("s:NetrwLocalRmFile ".ok)
11366 return ok
11367endfun
11368
Bram Moolenaar85850f32019-07-19 22:05:51 +020011369" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011370" Support Functions: {{{1
11371
Bram Moolenaar488c6512005-08-11 20:09:58 +000011372" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011373" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11374" 0: marked file list of current buffer
11375" 1: marked file target
11376fun! netrw#Access(ilist)
11377 if a:ilist == 0
11378 if exists("s:netrwmarkfilelist_".bufnr('%'))
11379 return s:netrwmarkfilelist_{bufnr('%')}
11380 else
11381 return "no-list-buf#".bufnr('%')
11382 endif
11383 elseif a:ilist == 1
11384 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011385 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011386endfun
11387
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011388" ---------------------------------------------------------------------
11389" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11390fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011391 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011392endfun
11393
Bram Moolenaara6878372014-03-22 21:02:50 +010011394" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011395" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11396" I expect this function to be used in
11397" :PChkAssert netrw#Expose("netrwmarkfilelist")
11398" for example.
11399fun! netrw#Expose(varname)
11400" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011401 if exists("s:".a:varname)
11402 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011403" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011404 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011405" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011406 if type(retval) == 3
11407 let retval = copy(retval)
11408 let i = 0
11409 while i < len(retval)
11410 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11411 let i = i + 1
11412 endwhile
11413 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011414" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011415 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011416 else
11417" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011418 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011419 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011420" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011421 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011422 endif
11423
11424" call Dret("netrw#Expose ".string(retval))
11425 return retval
11426endfun
11427
11428" ---------------------------------------------------------------------
11429" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11430fun! netrw#Modify(varname,newvalue)
11431" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11432 exe "let s:".a:varname."= ".string(a:newvalue)
11433" call Dret("netrw#Modify")
11434endfun
11435
11436" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011437" netrw#RFC2396: converts %xx into characters {{{2
11438fun! netrw#RFC2396(fname)
11439" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011440 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011441" call Dret("netrw#RFC2396 ".fname)
11442 return fname
11443endfun
11444
11445" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011446" netrw#UserMaps: supports user-specified maps {{{2
11447" see :help function()
11448"
11449" g:Netrw_UserMaps is a List with members such as:
11450" [[keymap sequence, function reference],...]
11451"
11452" The referenced function may return a string,
11453" refresh : refresh the display
11454" -other- : this string will be executed
11455" or it may return a List of strings.
11456"
11457" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011458" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011459" Related functions:
11460" netrw#Expose(varname) -- see s:varname variables
11461" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11462" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11463fun! netrw#UserMaps(islocal)
11464" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11465" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11466
11467 " set up usermaplist
11468 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11469" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11470 for umap in g:Netrw_UserMaps
11471" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11472" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11473 " if umap[0] is a string and umap[1] is a string holding a function name
11474 if type(umap[0]) == 1 && type(umap[1]) == 1
11475" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11476 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11477 else
11478 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11479 endif
11480 endfor
11481 endif
11482" call Dret("netrw#UserMaps")
11483endfun
11484
11485" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011486" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11487fun! netrw#WinPath(path)
11488" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011489 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011490 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011491 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011492 " remove trailing slash (Win95)
11493 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11494 " remove escaped spaces
11495 let path = substitute(path, '\ ', ' ', 'g')
11496 " convert slashes to backslashes
11497 let path = substitute(path, '/', '\', 'g')
11498 else
11499 let path= a:path
11500 endif
11501" call Dret("netrw#WinPath <".path.">")
11502 return path
11503endfun
11504
11505" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011506" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11507fun! s:StripTrailingSlash(path)
11508 " remove trailing slash
11509 return substitute(a:path, '[/\\]$', '', 'g')
11510endfun
11511
Travis Sheltone34d0e32024-07-30 21:08:56 +020011512" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011513" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11514" cb : bl2mf=0 add marked files to buffer list
11515" cB : bl2mf=1 use bufferlist to mark files
11516" (mnemonic: cb = copy (marked files) to buffer list)
11517fun! s:NetrwBadd(islocal,bl2mf)
11518" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11519 if a:bl2mf
11520 " cB: add buffer list to marked files
11521 redir => bufl
11522 ls
11523 redir END
11524 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11525 for fname in bufl
11526 call s:NetrwMarkFile(a:islocal,fname)
11527 endfor
11528 else
11529 " cb: add marked files to buffer list
11530 for fname in s:netrwmarkfilelist_{bufnr("%")}
11531" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11532 exe "badd ".fnameescape(fname)
11533 endfor
11534 let curbufnr = bufnr("%")
11535 let curdir = s:NetrwGetCurdir(a:islocal)
11536 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11537 endif
11538" call Dret("s:NetrwBadd")
11539endfun
11540
11541" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011542" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11543fun! s:ComposePath(base,subdir)
11544" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11545
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011546 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011547" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011548 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011549 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011550 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011551 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011552 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011553 endif
11554
Bram Moolenaar85850f32019-07-19 22:05:51 +020011555 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011556 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011557" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011558 let ret= a:subdir
11559
Nir Lichtman1e34b952024-05-08 19:19:34 +020011560 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011561" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011562 if a:base =~ '[/\\]$'
11563 let ret= a:base.a:subdir
11564 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011565 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011566 endif
11567
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011568 elseif a:base =~ '^\a\{3,}://'
11569" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011570 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11571 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11572 if a:subdir == '../'
11573 if curpath =~ '[^/]/[^/]\+/$'
11574 let curpath= substitute(curpath,'[^/]\+/$','','')
11575 else
11576 let curpath=""
11577 endif
11578 let ret= urlbase.curpath
11579 else
11580 let ret= urlbase.curpath.a:subdir
11581 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011582" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11583" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11584" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011585
11586 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011587" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011588 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11589 if a:base =~ '^//'
11590 " keeping initial '//' for the benefit of network share listing support
11591 let ret= '/'.ret
11592 endif
11593 let ret= simplify(ret)
11594 endif
11595
11596" call Dret("s:ComposePath ".ret)
11597 return ret
11598endfun
11599
11600" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011601" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11602" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11603fun! s:DeleteBookmark(fname)
11604" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11605 call s:MergeBookmarks()
11606
11607 if exists("g:netrw_bookmarklist")
11608 let indx= index(g:netrw_bookmarklist,a:fname)
11609 if indx == -1
11610 let indx= 0
11611 while indx < len(g:netrw_bookmarklist)
11612 if g:netrw_bookmarklist[indx] =~ a:fname
11613 call remove(g:netrw_bookmarklist,indx)
11614 let indx= indx - 1
11615 endif
11616 let indx= indx + 1
11617 endwhile
11618 else
11619 " remove exact match
11620 call remove(g:netrw_bookmarklist,indx)
11621 endif
11622 endif
11623
11624" call Dret("s:DeleteBookmark")
11625endfun
11626
11627" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011628" s:FileReadable: o/s independent filereadable {{{2
11629fun! s:FileReadable(fname)
11630" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11631
11632 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011633 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011634 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011635 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011636 endif
11637
11638" call Dret("s:FileReadable ".ret)
11639 return ret
11640endfun
11641
11642" ---------------------------------------------------------------------
11643" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11644" Places correct suffix on end of temporary filename,
11645" using the suffix provided with fname
11646fun! s:GetTempfile(fname)
11647" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11648
11649 if !exists("b:netrw_tmpfile")
11650 " get a brand new temporary filename
11651 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011652" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011653
Bram Moolenaarc236c162008-07-13 17:41:49 +000011654 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011655" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011656
Bram Moolenaar9964e462007-05-05 17:54:07 +000011657 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011658 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11659" 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 +010011660 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011661" call Dret("s:GetTempfile getcwd<".getcwd().">")
11662 return ""
11663 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011664
Bram Moolenaar9964e462007-05-05 17:54:07 +000011665 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011666 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011667" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011668
Bram Moolenaar9964e462007-05-05 17:54:07 +000011669 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011670 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011671 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011672 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011673 if !exists("+shellslash") || !&ssl
11674 let tmpfile = substitute(tmpfile,'/','\','g')
11675 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011676 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011677 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011678 endif
11679 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011680" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011681 else
11682 " re-use temporary filename
11683 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011684" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011685 endif
11686
11687 " use fname's suffix for the temporary file
11688 if a:fname != ""
11689 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011690" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011691 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011692 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011693 elseif a:fname =~ '.txz$'
11694 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011695 else
11696 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11697 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011698" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011699 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011700" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011701 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011702" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011703 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11704 endif
11705 endif
11706
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011707" 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 +000011708" call Dret("s:GetTempfile <".tmpfile.">")
11709 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011710endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011711
11712" ---------------------------------------------------------------------
11713" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011714" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011715fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011716" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011717 if s:user == ""
11718 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11719 else
11720 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11721 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011722 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011723 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011724 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011725 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011726 else
11727 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11728 endif
11729" call Dret("s:MakeSshCmd <".sshcmd.">")
11730 return sshcmd
11731endfun
11732
11733" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011734" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11735fun! s:MakeBookmark(fname)
11736" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11737
11738 if !exists("g:netrw_bookmarklist")
11739 let g:netrw_bookmarklist= []
11740 endif
11741
11742 if index(g:netrw_bookmarklist,a:fname) == -1
11743 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011744 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011745 call add(g:netrw_bookmarklist,a:fname.'/')
11746 elseif a:fname !~ '/'
11747 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11748 else
11749 call add(g:netrw_bookmarklist,a:fname)
11750 endif
11751 call sort(g:netrw_bookmarklist)
11752 endif
11753
11754" call Dret("s:MakeBookmark")
11755endfun
11756
11757" ---------------------------------------------------------------------
11758" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11759fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011760" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011761 " get bookmarks from .netrwbook file
11762 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011763 if filereadable(s:NetrwFile(savefile))
11764" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011765 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011766" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011767 NetrwKeepj call delete(savefile)
11768 endif
11769" call Dret("s:MergeBookmarks")
11770endfun
11771
11772" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011773" s:NetrwBMShow: {{{2
11774fun! s:NetrwBMShow()
11775" call Dfunc("s:NetrwBMShow()")
11776 redir => bmshowraw
11777 menu
11778 redir END
11779 let bmshowlist = split(bmshowraw,'\n')
11780 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011781 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011782 if bmshowfuncs != []
11783 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011784 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011785 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011786 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011787 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011788 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011789" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11790endfun
11791
11792" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011793" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011794fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011795 if !exists("w:netrw_liststyle")
11796 let w:netrw_liststyle= g:netrw_liststyle
11797 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011798" 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 +020011799
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011800" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11801
Bram Moolenaaradc21822011-04-01 18:03:16 +020011802 if &ft != "netrw"
11803 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11804 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011805" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011806
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011807 elseif g:netrw_cursor == 8
11808 if w:netrw_liststyle == s:WIDELIST
11809 setl cursorline
11810 setl cursorcolumn
11811 else
11812 setl cursorline
11813 endif
11814 elseif g:netrw_cursor == 7
11815 setl cursorline
11816 elseif g:netrw_cursor == 6
11817 if w:netrw_liststyle == s:WIDELIST
11818 setl cursorline
11819 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011820 elseif g:netrw_cursor == 4
11821 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011822" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011823 setl cursorline
11824 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011825
11826 elseif g:netrw_cursor == 3
11827 " thin-long-tree: cursorline, user's cursorcolumn
11828 " wide : cursorline, cursorcolumn
11829 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011830" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011831 setl cursorline
11832 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011833 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011834" 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 +020011835 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011836 endif
11837
11838 elseif g:netrw_cursor == 2
11839 " thin-long-tree: cursorline, user's cursorcolumn
11840 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011841" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011842 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011843
11844 elseif g:netrw_cursor == 1
11845 " thin-long-tree: user's cursorline, user's cursorcolumn
11846 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011847 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011848" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011849 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011850 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011851" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011852 endif
11853
11854 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011855 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011856" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011857 let &l:cursorline = s:netrw_usercul
11858 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011859 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011860
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011861" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011862" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011863endfun
11864
11865" ---------------------------------------------------------------------
11866" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11867fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011868" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011869 if exists("s:netrw_usercul")
11870 let &l:cursorline = s:netrw_usercul
11871 endif
11872 if exists("s:netrw_usercuc")
11873 let &l:cursorcolumn = s:netrw_usercuc
11874 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011875" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011876" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11877endfun
11878
Christian Brabandt62f7b552024-06-23 20:23:40 +020011879" s:RestoreRegister: restores all registers given in the dict {{{2
11880fun! s:RestoreRegister(dict)
11881 for [key, val] in items(a:dict)
11882 if key == 'unnamed'
11883 let key = ''
11884 endif
11885 call setreg(key, val[0], val[1])
11886 endfor
11887endfun
11888
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011889" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011890" s:NetrwDelete: Deletes a file. {{{2
11891" Uses Steve Hall's idea to insure that Windows paths stay
11892" acceptable. No effect on Unix paths.
11893" Examples of use: let result= s:NetrwDelete(path)
11894fun! s:NetrwDelete(path)
11895" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11896
Bram Moolenaar5c736222010-01-06 20:54:52 +010011897 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011898 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011899 if exists("+shellslash")
11900 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011901 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011902 let result = delete(path)
11903 let &shellslash = sskeep
11904 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011905" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011906 let result= delete(path)
11907 endif
11908 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011909" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011910 let result= delete(path)
11911 endif
11912 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011913 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011914 endif
11915
11916" call Dret("s:NetrwDelete ".result)
11917 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011918endfun
11919
11920" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011921" s:NetrwBufRemover: removes a buffer that: {{{2s
11922" has buffer-id > 1
11923" is unlisted
11924" is unnamed
11925" does not appear in any window
11926fun! s:NetrwBufRemover(bufid)
11927" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11928" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11929" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11930" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11931" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11932
yasuda4dbb2662023-10-04 20:50:35 +020011933 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011934" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020011935 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011936 endif
11937
11938" call Dret("s:NetrwBufRemover")
11939endfun
11940
11941" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011942" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011943fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011944" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011945" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011946
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011947 " Clean out the last buffer:
11948 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11949 " If so, delete it.
11950 call s:NetrwBufRemover(bufnr("$"))
11951
Bram Moolenaar446cb832008-06-24 21:56:24 +000011952 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011953" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011954 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11955 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11956 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11957 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11958 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11959 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11960 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11961 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11962 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11963 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11964 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11965 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11966 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11967 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11968 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11969 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11970
Bram Moolenaar85850f32019-07-19 22:05:51 +020011971 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011972" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011973 " when tree listing uses file TreeListing... a new buffer is made.
11974 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011975 " COMBAK: this causes a problem, see P43
11976" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011977 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010011978 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011979 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011980" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011981 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011982
Bram Moolenaar446cb832008-06-24 21:56:24 +000011983 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011984" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011985 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11986 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11987 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11988 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11989 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11990 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11991 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11992 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11993 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11994 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11995 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11996 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11997 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11998 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11999 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12000 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12001
Bram Moolenaar5c736222010-01-06 20:54:52 +010012002 if a:0 > 0
12003 let b:netrw_curdir= a:1
12004 if b:netrw_curdir =~ '/$'
12005 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012006 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012007 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012008 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012009 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12010 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012011 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012012 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012013 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012014 endif
12015 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012016 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12017 let &l:bexpr = "netrw#BalloonHelp()"
12018 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012019
Bram Moolenaar8d043172014-01-23 14:24:41 +010012020" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012021endfun
12022
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012023" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012024" s:NetrwExe: executes a string using "!" {{{2
12025fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012026" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Konfekt3d7e5672024-10-27 22:16:49 +010012027 if has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012028" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012029 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12030 set shell& shellcmdflag& shellxquote& shellxescape&
12031 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010012032 try
12033 exe a:cmd
12034 finally
12035 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12036 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012037 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012038" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012039 exe a:cmd
12040 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012041 if v:shell_error
12042 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12043 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012044" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012045endfun
12046
12047" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012048" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12049fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012050 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012051" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012052 let curbuf = bufnr("%")
12053 let curwin = winnr()
12054 let iwin = 1
12055 while iwin <= winnr("$")
12056 exe iwin."wincmd w"
12057 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12058 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12059 let winvars= w:
12060 break
12061 endif
12062 let iwin= iwin + 1
12063 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012064 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012065 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012066" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012067 for k in keys(winvars)
12068 let w:{k}= winvars[k]
12069 endfor
12070 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012071" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012072 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012073endfun
12074
Bram Moolenaara6878372014-03-22 21:02:50 +010012075" ---------------------------------------------------------------------
12076" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012077" Returns: 0=success
12078" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012079fun! s:NetrwLcd(newdir)
12080" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012081" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012082
Bram Moolenaar85850f32019-07-19 22:05:51 +020012083 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012084 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012085 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012086 catch /^Vim\%((\a\+)\)\=:E344/
12087 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12088 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012089 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012090 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12091 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012092 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012093 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12094 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012095 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012096 endif
12097 endif
12098 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012099 let err472= 1
12100 endtry
12101
12102 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012103 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12104 if exists("w:netrw_prvdir")
12105 let a:newdir= w:netrw_prvdir
12106 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012107 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012108" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012109 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012110" 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 +010012111 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012112 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012113" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12114 return -1
12115 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012116
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012117" call Decho("getcwd <".getcwd().">")
12118" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012119" call Dret("s:NetrwLcd 0")
12120 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012121endfun
12122
Bram Moolenaar9964e462007-05-05 17:54:07 +000012123" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012124" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12125" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12126fun! s:NetrwSaveWordPosn()
12127" call Dfunc("NetrwSaveWordPosn()")
12128 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12129" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12130endfun
12131
12132" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012133" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12134" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12135fun! s:NetrwHumanReadable(sz)
12136" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12137
12138 if g:netrw_sizestyle == 'h'
12139 if a:sz >= 1000000000
12140 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12141 elseif a:sz >= 10000000
12142 let sz = printf("%d",a:sz/1000000)."m"
12143 elseif a:sz >= 1000000
12144 let sz = printf("%.1f",a:sz/1000000.0)."m"
12145 elseif a:sz >= 10000
12146 let sz = printf("%d",a:sz/1000)."k"
12147 elseif a:sz >= 1000
12148 let sz = printf("%.1f",a:sz/1000.0)."k"
12149 else
12150 let sz= a:sz
12151 endif
12152
12153 elseif g:netrw_sizestyle == 'H'
12154 if a:sz >= 1073741824
12155 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12156 elseif a:sz >= 10485760
12157 let sz = printf("%d",a:sz/1048576)."M"
12158 elseif a:sz >= 1048576
12159 let sz = printf("%.1f",a:sz/1048576.0)."M"
12160 elseif a:sz >= 10240
12161 let sz = printf("%d",a:sz/1024)."K"
12162 elseif a:sz >= 1024
12163 let sz = printf("%.1f",a:sz/1024.0)."K"
12164 else
12165 let sz= a:sz
12166 endif
12167
12168 else
12169 let sz= a:sz
12170 endif
12171
12172" call Dret("s:NetrwHumanReadable ".sz)
12173 return sz
12174endfun
12175
12176" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012177" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12178" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12179fun! s:NetrwRestoreWordPosn()
12180" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012181 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012182" call Dret("NetrwRestoreWordPosn")
12183endfun
12184
12185" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012186" s:RestoreBufVars: {{{2
12187fun! s:RestoreBufVars()
12188" call Dfunc("s:RestoreBufVars()")
12189
12190 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12191 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12192 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12193 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12194 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12195 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12196
12197" call Dret("s:RestoreBufVars")
12198endfun
12199
12200" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012201" s:RemotePathAnalysis: {{{2
12202fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012203" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012204
Bram Moolenaara6878372014-03-22 21:02:50 +010012205 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012206 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012207 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012208 let s:user = substitute(a:dirname,dirpat,'\3','')
12209 let s:machine = substitute(a:dirname,dirpat,'\4','')
12210 let s:port = substitute(a:dirname,dirpat,'\5','')
12211 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012212 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012213 if s:machine =~ '@'
12214 let dirpat = '^\(.*\)@\(.\{-}\)$'
12215 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12216 let s:machine = substitute(s:machine,dirpat,'\2','')
12217 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012218
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012219" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12220" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12221" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12222" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12223" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12224" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012225
12226" call Dret("s:RemotePathAnalysis")
12227endfun
12228
12229" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012230" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12231" Returns status
12232" Runs system() on
12233" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012234" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012235fun! s:RemoteSystem(cmd)
12236" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12237 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012238 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 +000012239 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012240 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012241 else
12242 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12243 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12244 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012245 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012246 else
12247 let cmd= cmd.' '
12248 endif
12249 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012250" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012251 let ret= system(cmd)
12252 endif
12253" call Dret("s:RemoteSystem ".ret)
12254 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012255endfun
12256
12257" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012258" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012259fun! s:RestoreWinVars()
12260" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012261 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012262 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12263 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12264 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12265 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12266 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12267 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12268 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12269 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12270 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12271 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12272 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12273 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012274 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12275 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012276 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12277 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12278 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12279" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012280endfun
12281
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012282" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012283" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12284"
12285" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12286" is true) and a command, :Rexplore, which call this function.
12287"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012288" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012289"
12290" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012291fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012292 if exists("s:netrwdrag")
12293 return
12294 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012295" 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 +010012296" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12297" 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 +010012298
12299 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012300 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012301" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012302 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012303 unlet w:netrw_rexfile
12304" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012305 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012306" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012307" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12308" 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 +020012309 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012310
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012311 " ---------------------------
12312 " :Rex issued while in a file
12313 " ---------------------------
12314
Bram Moolenaara6878372014-03-22 21:02:50 +010012315 " record current file so :Rex can return to it from netrw
12316 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012317" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012318
12319 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012320" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012321 return
12322 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012323" 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 +020012324 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012325 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012326 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012327 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012328 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012329 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012330 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012331 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012332 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012333" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12334 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012335" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12336 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012337 if exists("s:rexposn_".bufnr('%'))
12338 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012339 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012340 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012341" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012342 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012343
Bram Moolenaar85850f32019-07-19 22:05:51 +020012344 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12345 if exists("s:explore_match")
12346 exe "2match netrwMarkFile /".s:explore_match."/"
12347 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012348 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012349
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012350" 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 +010012351" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012352endfun
12353
12354" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012355" s:SaveBufVars: save selected b: variables to s: variables {{{2
12356" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012357fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012358" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012359
12360 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12361 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12362 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12363 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12364 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12365 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12366
12367" call Dret("s:SaveBufVars")
12368endfun
12369
12370" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012371" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12372fun! s:SavePosn(posndict)
12373" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12374
Bram Moolenaar85850f32019-07-19 22:05:51 +020012375 if !exists("a:posndict[bufnr('%')]")
12376 let a:posndict[bufnr("%")]= []
12377 endif
12378" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12379 call add(a:posndict[bufnr("%")],winsaveview())
12380" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012381
12382" call Dret("s:SavePosn posndict")
12383 return a:posndict
12384endfun
12385
12386" ---------------------------------------------------------------------
12387" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12388fun! s:RestorePosn(posndict)
12389" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012390 if exists("a:posndict")
12391 if has_key(a:posndict,bufnr("%"))
12392" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12393 let posnlen= len(a:posndict[bufnr("%")])
12394 if posnlen > 0
12395 let posnlen= posnlen - 1
12396" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12397 call winrestview(a:posndict[bufnr("%")][posnlen])
12398 call remove(a:posndict[bufnr("%")],posnlen)
12399" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12400 endif
12401 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012402 endif
12403" call Dret("s:RestorePosn")
12404endfun
12405
12406" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012407" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012408fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012409" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012410 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12411 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12412 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12413 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12414 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12415 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12416 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12417 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12418 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12419 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12420 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12421 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12422 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12423 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12424 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12425 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12426 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12427 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12428" call Dret("s:SaveWinVars")
12429endfun
12430
12431" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012432" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012433" To allow separate windows to have their own activities, such as
12434" Explore **/pattern, several variables have been made window-oriented.
12435" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012436" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012437" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012438fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012439" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012440 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12441 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12442 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12443 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12444 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12445 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12446 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12447 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12448 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12449 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12450" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012451endfun
12452
12453" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012454" s:SetRexDir: set directory for :Rexplore {{{2
12455fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012456" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012457 let w:netrw_rexdir = a:dirname
12458 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012459 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012460" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12461" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012462" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012463" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012464" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012465endfun
12466
12467" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012468" s:ShowLink: used to modify thin and tree listings to show links {{{2
12469fun! s:ShowLink()
12470" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012471" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12472" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012473 if exists("b:netrw_curdir")
12474 norm! $?\a
12475 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12476 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012477" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12478" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12479" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12480 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012481 let dirlen = strlen(b:netrw_curdir)
12482 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012483" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012484 endif
12485 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012486" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12487" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012488 setl noro ma
12489 call setline(".",modline)
12490 setl ro noma nomod
12491 endif
12492" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12493endfun
12494
12495" ---------------------------------------------------------------------
12496" s:ShowStyle: {{{2
12497fun! s:ShowStyle()
12498 if !exists("w:netrw_liststyle")
12499 let liststyle= g:netrw_liststyle
12500 else
12501 let liststyle= w:netrw_liststyle
12502 endif
12503 if liststyle == s:THINLIST
12504 return s:THINLIST.":thin"
12505 elseif liststyle == s:LONGLIST
12506 return s:LONGLIST.":long"
12507 elseif liststyle == s:WIDELIST
12508 return s:WIDELIST.":wide"
12509 elseif liststyle == s:TREELIST
12510 return s:TREELIST.":tree"
12511 else
12512 return 'n/a'
12513 endif
12514endfun
12515
12516" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012517" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12518" Solution from Nicolai Weibull, vim docs (:help strlen()),
12519" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012520fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012521" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12522
12523 if v:version >= 703 && exists("*strdisplaywidth")
12524 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012525
Bram Moolenaar8d043172014-01-23 14:24:41 +010012526 elseif type(g:Align_xstrlen) == 1
12527 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12528 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012529
Bram Moolenaar8d043172014-01-23 14:24:41 +010012530 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012531 " number of codepoints (Latin a + combining circumflex is two codepoints)
12532 " (comment from TM, solution from NW)
12533 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012534
Bram Moolenaar8d043172014-01-23 14:24:41 +010012535 elseif g:Align_xstrlen == 2
12536 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012537 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12538 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012539 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012540
Bram Moolenaar8d043172014-01-23 14:24:41 +010012541 elseif g:Align_xstrlen == 3
12542 " virtual length (counting, for instance, tabs as anything between 1 and
12543 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012544 " preceded by lam, one otherwise, etc.)
12545 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012546 let modkeep= &l:mod
12547 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012548 call setline(line("."),a:x)
12549 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012550 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012551 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012552 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012553
Bram Moolenaar446cb832008-06-24 21:56:24 +000012554 else
12555 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012556 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012557 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012558" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012559 return ret
12560endfun
12561
12562" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012563" s:ShellEscape: shellescape(), or special windows handling {{{2
12564fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012565 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012566 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12567 endif
12568 let f = a:0 > 0 ? a:1 : 0
12569 return shellescape(a:s, f)
12570endfun
12571
12572" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012573" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012574fun! s:TreeListMove(dir)
12575" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012576 let curline = getline('.')
12577 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12578 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12579 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12580 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12581 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12582 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12583" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12584" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12585" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12586" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12587" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12588 " COMBAK : need to handle when on a directory
12589 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012590 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012591 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012592 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012593 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012594" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012595 elseif a:dir == '[]' && nxtline != ''
12596 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012597" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012598 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12599 if nl != 0
12600 NetrwKeepj norm! k
12601 else
12602 NetrwKeepj norm! G
12603 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012604" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012605 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012606 endif
12607
12608" call Dret("s:TreeListMove")
12609endfun
12610
12611" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012612" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12613" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12614" can't be called except via emenu. But due to locale, that menu line may not be called
12615" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12616fun! s:UpdateBuffersMenu()
12617" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012618 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012619 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012620 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012621 catch /^Vim\%((\a\+)\)\=:E/
12622 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012623 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012624 endtry
12625 endif
12626" call Dret("s:UpdateBuffersMenu")
12627endfun
12628
12629" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012630" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012631" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012632fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012633" call Dfunc("s:UseBufWinVars()")
12634 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012635 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12636 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12637 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12638 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12639 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12640 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12641 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12642 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12643 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 +000012644" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012645endfun
12646
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012647" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012648" s:UserMaps: supports user-defined UserMaps {{{2
12649" * calls a user-supplied funcref(islocal,curdir)
12650" * interprets result
12651" See netrw#UserMaps()
12652fun! s:UserMaps(islocal,funcname)
12653" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12654
12655 if !exists("b:netrw_curdir")
12656 let b:netrw_curdir= getcwd()
12657 endif
12658 let Funcref = function(a:funcname)
12659 let result = Funcref(a:islocal)
12660
12661 if type(result) == 1
12662 " if result from user's funcref is a string...
12663" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12664 if result == "refresh"
12665" call Decho("refreshing display",'~'.expand("<slnum>"))
12666 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12667 elseif result != ""
12668" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12669 exe result
12670 endif
12671
12672 elseif type(result) == 3
12673 " if result from user's funcref is a List...
12674" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12675 for action in result
12676 if action == "refresh"
12677" call Decho("refreshing display",'~'.expand("<slnum>"))
12678 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12679 elseif action != ""
12680" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12681 exe action
12682 endif
12683 endfor
12684 endif
12685
12686" call Dret("s:UserMaps")
12687endfun
12688
Bram Moolenaar85850f32019-07-19 22:05:51 +020012689" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012690" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012691" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012692let &cpo= s:keepcpo
12693unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012694
Bram Moolenaar85850f32019-07-19 22:05:51 +020012695" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012696" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012697" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012698" vim:ts=8 fdm=marker