blob: d55fb071a407c9f912deb32273d1826c16bf9dd0 [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
6" Last Change:
7" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09008" 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
Christian Brabandtf9ca1392024-02-19 20:37:11 +010013" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000014" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010015" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000016" Permission is hereby granted to use and distribute this code,
17" with or without modifications, provided that this copyright
18" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000019" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000020" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000021" expressed or implied. By using this plugin, you agree that
22" in no event will the copyright holder be liable for any damages
23" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010024"
25" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
26" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
27"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020028"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000029"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000030" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000031" (James 1:22 RSV)
32" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000033" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000034if &cp || exists("g:loaded_netrw")
35 finish
36endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020037
38" Check that vim has patches that netrw requires.
39" Patches needed for v7.4: 1557, and 213.
40" (netrw will benefit from vim's having patch#656, too)
41let s:needspatches=[1557,213]
42if exists("s:needspatches")
43 for ptch in s:needspatches
44 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
45 if !exists("s:needpatch{ptch}")
46 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
47 endif
48 let s:needpatch{ptch}= 1
49 finish
50 endif
51 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020052endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020053
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010054let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000055if !exists("s:NOTE")
56 let s:NOTE = 0
57 let s:WARNING = 1
58 let s:ERROR = 2
59endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000060
Bram Moolenaar1afcace2005-11-25 19:54:28 +000061let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010062setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020063"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010064"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010065"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000066
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000067" ======================
68" Netrw Variables: {{{1
69" ======================
70
Bram Moolenaar071d4272004-06-13 20:20:40 +000071" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020072" netrw#ErrorMsg: {{{2
73" 0=note = s:NOTE
74" 1=warning = s:WARNING
75" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010076" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
77" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
78" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010079" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020080fun! netrw#ErrorMsg(level,msg,errnum)
81" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
82
83 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020084" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020085 return
86 endif
87
88 if a:level == 1
89 let level= "**warning** (netrw) "
90 elseif a:level == 2
91 let level= "**error** (netrw) "
92 else
93 let level= "**note** (netrw) "
94 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010095" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020096
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020097 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
98 " use popup window
99 if type(a:msg) == 3
100 let msg = [level]+a:msg
101 else
102 let msg= level.a:msg
103 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200104 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200105 let s:popuperr_text= ""
106 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200107 " (default) netrw creates a one-line window to show error/warning
108 " messages (reliably displayed)
109
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100110 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200111 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100112" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200113
114 " getting messages out reliably is just plain difficult!
115 " This attempt splits the current window, creating a one line window.
116 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100117" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200118 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100119" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200120 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100121 if type(a:msg) == 3
122 for msg in a:msg
123 NetrwKeepj call setline(line("$")+1,level.msg)
124 endfor
125 else
126 NetrwKeepj call setline(line("$")+1,level.a:msg)
127 endif
128 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200129 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100130" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200131 bo 1split
132 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200133 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200134 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100135 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100136" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200137 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100138 if type(a:msg) == 3
139 for msg in a:msg
140 NetrwKeepj call setline(line("$")+1,level.msg)
141 endfor
142 else
143 NetrwKeepj call setline(line("$"),level.a:msg)
144 endif
145 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200146 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100147" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200148 if &fo !~ '[ta]'
149 syn clear
150 syn match netrwMesgNote "^\*\*note\*\*"
151 syn match netrwMesgWarning "^\*\*warning\*\*"
152 syn match netrwMesgError "^\*\*error\*\*"
153 hi link netrwMesgWarning WarningMsg
154 hi link netrwMesgError Error
155 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100156" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200157 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200158
159 else
160 " (optional) netrw will show messages using echomsg. Even if the
161 " message doesn't appear, at least it'll be recallable via :messages
162" redraw!
163 if a:level == s:WARNING
164 echohl WarningMsg
165 elseif a:level == s:ERROR
166 echohl Error
167 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100168
169 if type(a:msg) == 3
170 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100171 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100172 endfor
173 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100174 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100175 endif
176
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100177" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200178 echohl None
179 endif
180
181" call Dret("netrw#ErrorMsg")
182endfun
183
184" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100185" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100186" Loosely, varname = value.
187fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100188" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100189 if !exists(a:varname)
190 if type(a:value) == 0
191 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200192 elseif type(a:value) == 1 && a:value =~ '^[{[]'
193 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100194 elseif type(a:value) == 1
195 exe "let ".a:varname."="."'".a:value."'"
196 else
197 exe "let ".a:varname."=".a:value
198 endif
199 endif
200endfun
201
202" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000203" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200204call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000205if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100206 call s:NetrwInit("s:THINLIST",0)
207 call s:NetrwInit("s:LONGLIST",1)
208 call s:NetrwInit("s:WIDELIST",2)
209 call s:NetrwInit("s:TREELIST",3)
210 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000211endif
212
213" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200214" Default option values: {{{2
215let g:netrw_localcopycmdopt = ""
216let g:netrw_localcopydircmdopt = ""
217let g:netrw_localmkdiropt = ""
218let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200219
220" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000221" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200222if (v:version > 802 || (v:version == 802 && has("patch486"))) && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on") && has("mouse")
223 call s:NetrwInit("g:netrw_use_errorwindow",2)
224else
225 call s:NetrwInit("g:netrw_use_errorwindow",1)
226endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200227
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000228if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100229 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000230 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100231 elseif executable("curl")
232 let g:netrw_dav_cmd = "curl"
233 else
234 let g:netrw_dav_cmd = ""
235 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000236endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000237if !exists("g:netrw_fetch_cmd")
238 if executable("fetch")
239 let g:netrw_fetch_cmd = "fetch -o"
240 else
241 let g:netrw_fetch_cmd = ""
242 endif
243endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100244if !exists("g:netrw_file_cmd")
245 if executable("elinks")
246 call s:NetrwInit("g:netrw_file_cmd","elinks")
247 elseif executable("links")
248 call s:NetrwInit("g:netrw_file_cmd","links")
249 endif
250endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000251if !exists("g:netrw_ftp_cmd")
252 let g:netrw_ftp_cmd = "ftp"
253endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200254let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200255if !exists("g:netrw_ftp_options")
256 let g:netrw_ftp_options= "-i -n"
257endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000258if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100259 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100260 let g:netrw_http_cmd = "wget"
261 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100262 elseif executable("curl")
263 let g:netrw_http_cmd = "curl"
264 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200265 elseif executable("elinks")
266 let g:netrw_http_cmd = "elinks"
267 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000268 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100269 let g:netrw_http_cmd = "fetch"
270 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200271 elseif executable("links")
272 let g:netrw_http_cmd = "links"
273 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000274 else
275 let g:netrw_http_cmd = ""
276 endif
277endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100278call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100279call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100280call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
281call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200282call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200283if !exists("g:netrw_scp_cmd")
284 if executable("scp")
285 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
286 elseif executable("pscp")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200287 if has("win32") && filereadable('c:\private.ppk')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200288 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
289 else
290 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
291 endif
292 else
293 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
294 endif
295endif
296
Bram Moolenaar5c736222010-01-06 20:54:52 +0100297call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
298call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000299
Nir Lichtman1e34b952024-05-08 19:19:34 +0200300if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000301 \ && exists("g:netrw_use_nt_rcp")
302 \ && g:netrw_use_nt_rcp
303 \ && executable( $SystemRoot .'/system32/rcp.exe')
304 let s:netrw_has_nt_rcp = 1
305 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000306else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000307 let s:netrw_has_nt_rcp = 0
308 let s:netrw_rcpmode = ''
309endif
310
311" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000312" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000313" Cygwin Detection ------- {{{3
314if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200315 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
316 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000317 else
318 let g:netrw_cygwin= 0
319 endif
320endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000321" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100322call s:NetrwInit("g:netrw_alto" , &sb)
323call s:NetrwInit("g:netrw_altv" , &spr)
324call s:NetrwInit("g:netrw_banner" , 1)
325call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200326call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100327call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200328call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100329call s:NetrwInit("g:netrw_compress" , "gzip")
330call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200331if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
332 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
333 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000334endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200335call s:NetrwInit("g:netrw_cursor" , 2)
336let s:netrw_usercul = &cursorline
337let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200338"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100339call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000340" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200341call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200342call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200343call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100344call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200345call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100346call s:NetrwInit("g:netrw_fastbrowse" , 1)
347call 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 +0000348if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000349 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
350 let g:netrw_ftp_list_cmd = "ls -lF"
351 let g:netrw_ftp_timelist_cmd = "ls -tlF"
352 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000353 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000354 let g:netrw_ftp_list_cmd = "dir"
355 let g:netrw_ftp_timelist_cmd = "dir"
356 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000357 endif
358endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100359call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000360" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100361call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000362if !exists("g:netrw_ignorenetrc")
363 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
364 let g:netrw_ignorenetrc= 1
365 else
366 let g:netrw_ignorenetrc= 0
367 endif
368endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100369call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000370if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000371 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200372 if has("win32") && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200373 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000374 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
375 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100376 if exists("g:netrw_list_cmd_options")
377 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
378 else
379 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
380 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000381 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200382 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100383 if exists("g:netrw_list_cmd_options")
384 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
385 else
386 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
387 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000388 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100389" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000390 let g:netrw_list_cmd= ""
391 endif
392endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100393call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000394" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200395if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200396 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200397 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
398endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100399if !exists("g:netrw_localcmdshell")
400 let g:netrw_localcmdshell= ""
401endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000402if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200403 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000404 if g:netrw_cygwin
405 let g:netrw_localcopycmd= "cp"
406 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000407 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200408 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000409 endif
410 elseif has("unix") || has("macunix")
411 let g:netrw_localcopycmd= "cp"
412 else
413 let g:netrw_localcopycmd= ""
414 endif
415endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100416if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200417 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100418 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200419 let g:netrw_localcopydircmd = "cp"
420 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100421 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000422 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200423 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100424 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200425 elseif has("unix")
426 let g:netrw_localcopydircmd = "cp"
427 let g:netrw_localcopydircmdopt= " -R"
428 elseif has("macunix")
429 let g:netrw_localcopydircmd = "cp"
430 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100431 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200432 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100433 endif
434endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200435if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100436 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200437 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
438endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200439if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200440 if g:netrw_cygwin
441 call s:NetrwInit("g:netrw_localmkdir","mkdir")
442 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000443 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200444 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200445 endif
446else
447 call s:NetrwInit("g:netrw_localmkdir","mkdir")
448endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200449call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200450if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200451 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200452 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
453endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000454if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200455 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000456 if g:netrw_cygwin
457 let g:netrw_localmovecmd= "mv"
458 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000459 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200460 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000461 endif
462 elseif has("unix") || has("macunix")
463 let g:netrw_localmovecmd= "mv"
464 else
465 let g:netrw_localmovecmd= ""
466 endif
467endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100468" following serves as an example for how to insert a version&patch specific test
469"if v:version < 704 || (v:version == 704 && !has("patch1107"))
470"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100471call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
472" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000473if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000474 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000475endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000476if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000477 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
478endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000479" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100480call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
481call s:NetrwInit("g:netrw_maxfilenamelen", 32)
482call s:NetrwInit("g:netrw_menu" , 1)
483call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200484call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100485call s:NetrwInit("g:netrw_retmap" , 0)
486if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
487 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200488elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100489 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
490else
491 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000492endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100493call s:NetrwInit("g:netrw_preview" , 0)
494call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100495call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100496call s:NetrwInit("g:netrw_sshport" , "-p")
497call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
498call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
499call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100500call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
501" Default values - q-s ---------- {{{3
502call s:NetrwInit("g:netrw_quickhelp",0)
503let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100504 \ "(create new) %:file d:directory",
505 \ "(windows split&open) o:horz v:vert p:preview",
506 \ "i:style qf:file info O:obtain r:reverse",
507 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
508 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
509 \ "(history) qb:list u:go up U:go down",
510 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100511" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
512call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100513if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
514 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
515else
516 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
517endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100518call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
519call s:NetrwInit("g:netrw_sort_options" , "")
520call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000521if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100522 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200523 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100524 else
525 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000526 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000527endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100528call s:NetrwInit("g:netrw_special_syntax" , 0)
529call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200530call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100531call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100532call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000533" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100534call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200535if !exists("g:netrw_xstrlen")
536 if exists("g:Align_xstrlen")
537 let g:netrw_xstrlen= g:Align_xstrlen
538 elseif exists("g:drawit_xstrlen")
539 let g:netrw_xstrlen= g:drawit_xstrlen
540 elseif &enc == "latin1" || !has("multi_byte")
541 let g:netrw_xstrlen= 0
542 else
543 let g:netrw_xstrlen= 1
544 endif
545endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100546call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200547call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100548call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200549if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000550" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000551" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100552call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200553if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200554 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200555else
Bram Moolenaarff034192013-04-24 18:51:19 +0200556 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200557endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200558call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100559call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
560call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100561if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100562 let s:treedepthstring= "│ "
563else
564 let s:treedepthstring= "| "
565endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200566call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000567
568" BufEnter event ignored by decho when following variable is true
569" Has a side effect that doau BufReadPost doesn't work, so
570" files read by network transfer aren't appropriately highlighted.
571"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572
Bram Moolenaaradc21822011-04-01 18:03:16 +0200573" ======================
574" Netrw Initialization: {{{1
575" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200576if 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 +0100577" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100578 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200579" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100580 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100581 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
582 au VimEnter * let s:initbeval= &beval
583"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100584" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
585" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
586" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
587" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
588" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
589" 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 +0200590endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200591au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200592
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200593if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100594 com! -nargs=* NetrwKeepj keepj <args>
595else
596 let g:netrw_keepj= ""
597 com! -nargs=* NetrwKeepj <args>
598endif
599
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000600" ==============================
601" Netrw Utility Functions: {{{1
602" ==============================
603
Bram Moolenaaradc21822011-04-01 18:03:16 +0200604" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100605" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100606if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100607" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100608 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100609 if &ft != "netrw"
610 return ""
611 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200612 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
613 " popup error window is still showing
614 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
615 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
616 " text under mouse hasn't changed; only close window when it changes
617 call popup_close(s:popuperr_id)
618 unlet s:popuperr_text
619 else
620 let s:popuperr_text= v:beval_text
621 endif
622 let mesg= ""
623 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 +0100624 let mesg= ""
625 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
626 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
627 elseif getline(v:beval_lnum) =~ '^"\s*/'
628 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
629 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100630 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100631 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
632 let mesg = "S: edit sorting sequence"
633 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
634 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
635 elseif v:beval_text == "Quick" || v:beval_text == "Help"
636 let mesg = "Help: press <F1>"
637 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
638 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
639 else
640 let mesg= ""
641 endif
642 return mesg
643 endfun
644"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100645" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
646" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
647" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
648" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
649" 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 +0200650endif
651
Bram Moolenaar071d4272004-06-13 20:20:40 +0000652" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200653" netrw#Explore: launch the local browser in the directory of the current file {{{2
654" indx: == -1: Nexplore
655" == -2: Pexplore
656" == +: this is overloaded:
657" * If Nexplore/Pexplore is in use, then this refers to the
658" indx'th item in the w:netrw_explore_list[] of items which
659" matched the */pattern **/pattern *//pattern **//pattern
660" * If Hexplore or Vexplore, then this will override
661" g:netrw_winsize to specify the qty of rows or columns the
662" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100663" 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 +0200664" dosplit==1: the window will be split before running the local browser
665" style == 0: Explore style == 1: Explore!
666" == 2: Hexplore style == 3: Hexplore!
667" == 4: Vexplore style == 5: Vexplore!
668" == 6: Texplore
669fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100670" 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 +0100671" 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 +0200672 if !exists("b:netrw_curdir")
673 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100674" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200675 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100676
677 " record current file for Rexplore's benefit
678 if &ft != "netrw"
679 let w:netrw_rexfile= expand("%:p")
680 endif
681
682 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200683 let curdir = simplify(b:netrw_curdir)
684 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200685 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200686 let curdir= substitute(curdir,'\','/','g')
687 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100688" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100689
690 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
691 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
692 " try Explore again.
693 if a:0 > 0
694" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100695 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
696 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
697 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
698 \ '~'.expand("<slnum>"))
699 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
700" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100701 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
702" call Dret("netrw#Explore : returning from retry")
703 return
704" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100705" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100706 endif
707 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200708
709 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200710 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100711" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100712 sil! let keepregstar = @*
713 sil! let keepregplus = @+
714 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200715 sil! let keepregslash= @/
716
Bram Moolenaar8d043172014-01-23 14:24:41 +0100717 " if dosplit
718 " -or- file has been modified AND file not hidden when abandoned
719 " -or- Texplore used
720 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100721" call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200722 call s:SaveWinVars()
723 let winsz= g:netrw_winsize
724 if a:indx > 0
725 let winsz= a:indx
726 endif
727
728 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100729" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200730 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200731 if winsz == 0|let winsz= ""|endif
732 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100733" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200734
735 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100736" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200737 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200738 if winsz == 0|let winsz= ""|endif
739 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100740" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200741
742 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100743" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200744 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200745 if winsz == 0|let winsz= ""|endif
746 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100747" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200748
749 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100750" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200751 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200752 if winsz == 0|let winsz= ""|endif
753 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100754" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200755
756 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100757" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200758 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200759 if winsz == 0|let winsz= ""|endif
760 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100761" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200762
763 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100764" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
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
767 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100768" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200769
770 elseif a:style == 6 " Texplore
771 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100772" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200773 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100774" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 call s:RestoreBufVars()
776 endif
777 call s:RestoreWinVars()
778" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100779" call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200780 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100781 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200782
783 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
792 if dirname !~ '/$'
793 let dirname= dirname."/"
794 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200800 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100803" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100805" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200806 let dirname= a:1
807 endif
808 else
809 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100810" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200811 call s:NetrwClearExplore()
812" call Dret("netrw#Explore : cleared list")
813 return
814 endif
815
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100816" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200817 if dirname =~ '\.\./\=$'
818 let dirname= simplify(fnamemodify(dirname,':p:h'))
819 elseif dirname =~ '\.\.' || dirname == '.'
820 let dirname= simplify(fnamemodify(dirname,':p'))
821 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100822" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200823
824 if dirname =~ '^\*//'
825 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100826" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200827 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
828 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100829" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200830 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
831
832 elseif dirname =~ '^\*\*//'
833 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100834" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200835 let pattern= substitute(dirname,'^\*\*//','','')
836 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100837" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200838
839 elseif dirname =~ '/\*\*/'
840 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100841" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200842 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200843 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200844 let b:netrw_curdir = prefixdir
845 else
846 let b:netrw_curdir= getcwd().'/'.prefixdir
847 endif
848 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
849 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100850" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
851" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200852
853 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200854 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200855 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100856" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200857
858 elseif dirname=~ '^\*\*/'
859 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
860 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100861" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200862
863 else
864 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100865" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200866 endif
867
868 if starpat == 0 && a:indx >= 0
869 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100870" 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 +0200871 if dirname == ""
872 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100873" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200874 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200875 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200876 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200877 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200878 if dirname == ""
879 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200880 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100881 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100882 " depending on whether backslashes have been converted to forward slashes by earlier code).
883 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200884 let dirname= b:netrw_curdir."/".dirname
885 endif
886 elseif dirname !~ '^/'
887 let dirname= b:netrw_curdir."/".dirname
888 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100889" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200890 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100891" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
892" 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 +0200893 endif
894 if exists("w:netrw_bannercnt")
895 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
896 " If one wants to return the same place in the netrw window, use :Rex instead.
897 exe w:netrw_bannercnt
898 endif
899
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100900" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200901 " ---------------------------------------------------------------------
902 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
903" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100904" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200905" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100906" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200907" endif
908 " ---------------------------------------------------------------------
909
910 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
911 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
912 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
913 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
914 elseif a:indx <= 0
915 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100916" 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 +0200917 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100918" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200919 let s:didstarstar= 1
920 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
921 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
922 endif
923
924 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100925" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200926 if !exists("w:netrw_explore_indx")
927 let w:netrw_explore_indx= 0
928 endif
929
930 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100931" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200932
933 if indx == -1
934 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100935" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200936 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100937 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 +0200938 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100939" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100940 if @* != keepregstar | sil! let @* = keepregstar | endif
941 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100942 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200943 sil! let @/ = keepregslash
944" call Dret("netrw#Explore")
945 return
946 endif
947 let indx= w:netrw_explore_indx
948 if indx < 0 | let indx= 0 | endif
949 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
950 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100951" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200952 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
953 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100954" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200955 endwhile
956 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100957" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200958
959 elseif indx == -2
960 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100961" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200962 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100963 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 +0200964 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100965" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100966 if @* != keepregstar | sil! let @* = keepregstar | endif
967 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100968 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200969 sil! let @/ = keepregslash
970" call Dret("netrw#Explore")
971 return
972 endif
973 let indx= w:netrw_explore_indx
974 if indx < 0 | let indx= 0 | endif
975 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
976 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100977" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200978 while indx >= 0 && curfile == w:netrw_explore_list[indx]
979 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100980" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200981 endwhile
982 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100983" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200984
985 else
986 " Explore -- initialize
987 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100988" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100989 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200990 let w:netrw_explore_indx= 0
991 if !exists("b:netrw_curdir")
992 let b:netrw_curdir= getcwd()
993 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100994" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200995
996 " switch on starpat to build the w:netrw_explore_list of files
997 if starpat == 1
998 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100999" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
1000" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001001 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001002 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001003 catch /^Vim\%((\a\+)\)\=:E480/
1004 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1005" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1006 return
1007 endtry
1008 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1009 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1010
1011 elseif starpat == 2
1012 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001013" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1014" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001015 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001016 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001017 catch /^Vim\%((\a\+)\)\=:E480/
1018 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1019 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001020 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001021" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001022 if @* != keepregstar | sil! let @* = keepregstar | endif
1023 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001024 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001025 sil! let @/ = keepregslash
1026" call Dret("netrw#Explore : no files matched pattern")
1027 return
1028 endtry
1029 let s:netrw_curdir = b:netrw_curdir
1030 let w:netrw_explore_list = getqflist()
1031 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1032 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1033
1034 elseif starpat == 3
1035 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001036" 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 +02001037 let filepat= substitute(dirname,'^\*/','','')
1038 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001039" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1040" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001041 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1042 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1043
1044 elseif starpat == 4
1045 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001046" 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 +02001047 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1048 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1049 endif " switch on starpat to build w:netrw_explore_list
1050
1051 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001052" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1053" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001054
1055 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001056 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001057 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001058" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001059 if @* != keepregstar | sil! let @* = keepregstar | endif
1060 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001061 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001062 sil! let @/ = keepregslash
1063" call Dret("netrw#Explore : no files matched")
1064 return
1065 endif
1066 endif " if indx ... endif
1067
1068 " NetrwStatusLine support - for exploring support
1069 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001070" 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 +02001071
1072 " wrap the indx around, but issue a note
1073 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001074" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1076 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001077 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001078 endif
1079
1080 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001081" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001082 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001083" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001084
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001085" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001086 call netrw#LocalBrowseCheck(newdir)
1087 if !exists("w:netrw_liststyle")
1088 let w:netrw_liststyle= g:netrw_liststyle
1089 endif
1090 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001091 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001092 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001093 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001094 endif
1095 let w:netrw_explore_mtchcnt = indx + 1
1096 let w:netrw_explore_bufnr = bufnr("%")
1097 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001098 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001099" 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 +02001100
1101 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001102" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001103 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001104 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 +02001105 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001106 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001107" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001108 if @* != keepregstar | sil! let @* = keepregstar | endif
1109 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001110 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001111 sil! let @/ = keepregslash
1112" call Dret("netrw#Explore : missing +path_extra")
1113 return
1114 endif
1115
1116 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001117" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001118 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1119 sil! unlet w:netrw_treedict
1120 sil! unlet w:netrw_treetop
1121 endif
1122 let newdir= dirname
1123 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001124 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001125 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001126 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001127 endif
1128 endif
1129
1130 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001131" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1132" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001133 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001134" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001135 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001136 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001137" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001138 let s:explore_prvdir = b:netrw_curdir
1139 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001140 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001141 if b:netrw_curdir !~ '/$'
1142 let dirlen= dirlen + 1
1143 endif
1144 let prvfname= ""
1145 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001146" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001147 if fname =~ '^'.b:netrw_curdir
1148 if s:explore_match == ""
1149 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1150 else
1151 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1152 endif
1153 elseif fname !~ '^/' && fname != prvfname
1154 if s:explore_match == ""
1155 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1156 else
1157 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1158 endif
1159 endif
1160 let prvfname= fname
1161 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001162" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001163 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1164 exe "2match netrwMarkFile /".s:explore_match."/"
1165 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001166 endif
1167 echo "<s-up>==Pexplore <s-down>==Nexplore"
1168 else
1169 2match none
1170 if exists("s:explore_match") | unlet s:explore_match | endif
1171 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001172" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001173 endif
1174
Bram Moolenaara6878372014-03-22 21:02:50 +01001175 " since Explore may be used to initialize netrw's browser,
1176 " there's no danger of a late FocusGained event on initialization.
1177 " Consequently, set s:netrw_events to 2.
1178 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001179 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001180" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001181 if @* != keepregstar | sil! let @* = keepregstar | endif
1182 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001183 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001184 sil! let @/ = keepregslash
1185" call Dret("netrw#Explore : @/<".@/.">")
1186endfun
1187
1188" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001189" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001190" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1191" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1192" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1193" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1194" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001196" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001197 let curwin= winnr()
1198
Bram Moolenaara6878372014-03-22 21:02:50 +01001199 if a:0 > 0 && a:1 != ""
1200 " if a netrw window is already on the left-side of the tab
1201 " and a directory has been specified, explore with that
1202 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001203" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001204 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001205" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001206 exe "1wincmd w"
1207 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001208" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 exe "Explore ".fnameescape(a1)
1210 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001211 let s:lexplore_win= curwin
1212 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001213 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001214" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001215 unlet t:netrw_lexposn
1216 endif
1217" call Dret("netrw#Lexplore")
1218 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001219 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001220 exe curwin."wincmd w"
1221 else
1222 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001223" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001224 endif
1225
Bram Moolenaar8d043172014-01-23 14:24:41 +01001226 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001228 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001229" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001230 else
1231 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001232" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001233 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001234" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001235
1236 if lexwinnr > 0
1237 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001238" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001239 exe lexwinnr."wincmd w"
1240 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001241 let t:netrw_lexposn = winsaveview()
1242" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001243" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001244 close
1245 if lexwinnr < curwin
1246 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001247 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001248 if lexwinnr != curwin
1249 exe curwin."wincmd w"
1250 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001251 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001252" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001253
1254 else
1255 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001256" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001257 exe "1wincmd w"
1258 let keep_altv = g:netrw_altv
1259 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001260 if a:count != 0
1261 let netrw_winsize = g:netrw_winsize
1262 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001263 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001264 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001265" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 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 +02001267" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001269" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001270 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001271 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001272 elseif curfile =~ '^\a\{3,}://'
1273" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001274 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001275 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001276" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001277 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001278 endif
1279 if a:count != 0
1280 let g:netrw_winsize = netrw_winsize
1281 endif
1282 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001283 let g:netrw_altv = keep_altv
1284 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001285 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1286 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001287 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001288 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001289" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1290" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001291 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001292" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001293" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1294 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001295 unlet t:netrw_lexposn
1296 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001297 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001298
1299 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001300 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001301 if a:rightside
1302 let g:netrw_chgwin= 1
1303 else
1304 let g:netrw_chgwin= 2
1305 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001306" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001307 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001308
Bram Moolenaar8d043172014-01-23 14:24:41 +01001309" call Dret("netrw#Lexplore")
1310endfun
1311
1312" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001313" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001314" supports :NetrwClean -- remove netrw from first directory on runtimepath
1315" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001316fun! netrw#Clean(sys)
1317" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001318
1319 if a:sys
1320 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1321 else
1322 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1323 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001324" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001325 let diddel= 0
1326 let diddir= ""
1327
1328 if choice == 1
1329 for dir in split(&rtp,',')
1330 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001331" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001332 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1333 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1334 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1335 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1336 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1337 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 +00001338 let diddir= dir
1339 let diddel= diddel + 1
1340 if !a:sys|break|endif
1341 endif
1342 endfor
1343 endif
1344
1345 echohl WarningMsg
1346 if diddel == 0
1347 echomsg "netrw is either not installed or not removable"
1348 elseif diddel == 1
1349 echomsg "removed one copy of netrw from <".diddir.">"
1350 else
1351 echomsg "removed ".diddel." copies of netrw"
1352 endif
1353 echohl None
1354
Bram Moolenaara6878372014-03-22 21:02:50 +01001355" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001356endfun
1357
Bram Moolenaar5c736222010-01-06 20:54:52 +01001358" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001359" netrw#MakeTgt: make a target out of the directory name provided {{{2
1360fun! netrw#MakeTgt(dname)
1361" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1362 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001363 let svpos = winsaveview()
1364" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001365 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1366" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001367 if s:netrwmftgt_islocal
1368 let netrwmftgt= simplify(a:dname)
1369 else
1370 let netrwmftgt= a:dname
1371 endif
1372 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1373 " re-selected target, so just clear it
1374 unlet s:netrwmftgt s:netrwmftgt_islocal
1375 else
1376 let s:netrwmftgt= netrwmftgt
1377 endif
1378 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001379 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001380 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001381" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1382 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001383" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001384endfun
1385
Bram Moolenaara6878372014-03-22 21:02:50 +01001386" ---------------------------------------------------------------------
1387" netrw#Obtain: {{{2
1388" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001389" islocal=0 obtain from remote source
1390" =1 obtain from local source
1391" fname : a filename or a list of filenames
1392" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001393fun! netrw#Obtain(islocal,fname,...)
1394" 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 +02001395 " NetrwStatusLine support - for obtaining support
1396
1397 if type(a:fname) == 1
1398 let fnamelist= [ a:fname ]
1399 elseif type(a:fname) == 3
1400 let fnamelist= a:fname
1401 else
1402 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 +01001403" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001404 return
1405 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001406" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001407 if a:0 > 0
1408 let tgtdir= a:1
1409 else
1410 let tgtdir= getcwd()
1411 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001412" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001413
1414 if exists("b:netrw_islocal") && b:netrw_islocal
1415 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001416" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001417 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1418 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001419 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001420 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001421" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001422 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001423" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001424 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001425 if v:shell_error != 0
1426 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 +01001427" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001428 return
1429 endif
1430 endfor
1431 else
1432 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001433" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1434 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1435" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001436 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001437 if v:shell_error != 0
1438 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 +01001439" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001440 return
1441 endif
1442 endif
1443 elseif !exists("b:netrw_curdir")
1444 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1445 else
1446 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1447 endif
1448
1449 else
1450 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001451" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001452 if type(a:fname) == 1
1453 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1454 endif
1455 call s:NetrwMethod(b:netrw_curdir)
1456
1457 if b:netrw_method == 4
1458 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001459" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001460 if exists("g:netrw_port") && g:netrw_port != ""
1461 let useport= " ".g:netrw_scpport." ".g:netrw_port
1462 else
1463 let useport= ""
1464 endif
1465 if b:netrw_fname =~ '/'
1466 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1467 else
1468 let path= ""
1469 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001470 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001471 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 +02001472
1473 elseif b:netrw_method == 2
1474 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001475" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001476 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001477 let tmpbufnr= bufnr("%")
1478 setl ff=unix
1479 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001480 NetrwKeepj put =g:netrw_ftpmode
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("b:netrw_fname") && b:netrw_fname != ""
1485 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
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
1489 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001490 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001491" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001492 endif
1493 for fname in fnamelist
1494 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001495" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001496 endfor
1497 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001498 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 +02001499 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001500 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001501 endif
1502 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1503 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1504 let debugkeep= &debug
1505 setl debug=msg
1506 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1507 let &debug= debugkeep
1508 endif
1509
1510 elseif b:netrw_method == 3
1511 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001512" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001513 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001514 let tmpbufnr= bufnr("%")
1515 setl ff=unix
1516
1517 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001518 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001519" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001520 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001521 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001522" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 endif
1524
1525 if exists("g:netrw_uid") && g:netrw_uid != ""
1526 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001527 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001528" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001529 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001530 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001531 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001532" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001533 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001534 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001535" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001536 endif
1537 endif
1538
1539 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001540 NetrwKeepj put =g:netrw_ftpmode
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("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001545 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
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
1554 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001555 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001556" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001557 endif
1558 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001559 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001560 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001561" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001562
1563 " perform ftp:
1564 " -i : turns off interactive prompting from ftp
1565 " -n unix : DON'T use <.netrc>, even though it exists
1566 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001567 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1568 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001569 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001570 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1571 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001572" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001573 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001574 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001575 endif
1576 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001577
1578 elseif b:netrw_method == 9
1579 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001580" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001581 if a:fname =~ '/'
1582 let localfile= substitute(a:fname,'^.*/','','')
1583 else
1584 let localfile= a:fname
1585 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001586 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 +02001587
Bram Moolenaarff034192013-04-24 18:51:19 +02001588 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001589 " probably a badly formed url; protocol not recognized
1590" call Dret("netrw#Obtain : unsupported method")
1591 return
1592
1593 else
1594 " protocol recognized but not supported for Obtain (yet?)
1595 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001596 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001597 endif
1598" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001599 return
1600 endif
1601
1602 " restore status line
1603 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001604 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001605 endif
1606
1607 endif
1608
1609 " cleanup
1610 if exists("tmpbufnr")
1611 if bufnr("%") != tmpbufnr
1612 exe tmpbufnr."bw!"
1613 else
1614 q!
1615 endif
1616 endif
1617
Bram Moolenaara6878372014-03-22 21:02:50 +01001618" call Dret("netrw#Obtain")
1619endfun
1620
1621" ---------------------------------------------------------------------
1622" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1623fun! netrw#Nread(mode,fname)
1624" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001625 let svpos= winsaveview()
1626" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001627 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001628" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1629 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001630
1631 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1632 if exists("w:netrw_bannercnt")
1633 " start with cursor just after the banner
1634 exe w:netrw_bannercnt
1635 endif
1636 endif
1637" call Dret("netrw#Nread")
1638endfun
1639
1640" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001641" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1642" Options get restored by s:NetrwOptionsRestore()
1643"
1644" Option handling:
1645" * save user's options (s:NetrwOptionsSave)
1646" * set netrw-safe options (s:NetrwOptionsSafe)
1647" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1648" * restore user's options (s:netrwOPtionsRestore)
1649" - restore a user option when != safe option (s:NetrwRestoreSetting)
1650" vt: (variable type) normally its either "w:" or "s:"
1651fun! s:NetrwOptionsSave(vt)
1652" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1653" 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 +02001654" 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>"))
1655" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001656
1657 if !exists("{a:vt}netrw_optionsave")
1658 let {a:vt}netrw_optionsave= 1
1659 else
1660" call Dret("s:NetrwOptionsSave : options already saved")
1661 return
1662 endif
1663" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1664
1665 " Save current settings and current directory
1666" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1667 let s:yykeep = @@
1668 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1669 let {a:vt}netrw_aikeep = &l:ai
1670 let {a:vt}netrw_awkeep = &l:aw
1671 let {a:vt}netrw_bhkeep = &l:bh
1672 let {a:vt}netrw_blkeep = &l:bl
1673 let {a:vt}netrw_btkeep = &l:bt
1674 let {a:vt}netrw_bombkeep = &l:bomb
1675 let {a:vt}netrw_cedit = &cedit
1676 let {a:vt}netrw_cikeep = &l:ci
1677 let {a:vt}netrw_cinkeep = &l:cin
1678 let {a:vt}netrw_cinokeep = &l:cino
1679 let {a:vt}netrw_comkeep = &l:com
1680 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001681 let {a:vt}netrw_cuckeep = &l:cuc
1682 let {a:vt}netrw_culkeep = &l:cul
1683" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001684 let {a:vt}netrw_diffkeep = &l:diff
1685 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001686 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1687 let {a:vt}netrw_ffkeep = &l:ff
1688 endif
1689 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1690 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001691 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001692 let {a:vt}netrw_hidkeep = &l:hidden
1693 let {a:vt}netrw_imkeep = &l:im
1694 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001695 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001696 let {a:vt}netrw_lskeep = &l:ls
1697 let {a:vt}netrw_makeep = &l:ma
1698 let {a:vt}netrw_magickeep = &l:magic
1699 let {a:vt}netrw_modkeep = &l:mod
1700 let {a:vt}netrw_nukeep = &l:nu
1701 let {a:vt}netrw_rnukeep = &l:rnu
1702 let {a:vt}netrw_repkeep = &l:report
1703 let {a:vt}netrw_rokeep = &l:ro
1704 let {a:vt}netrw_selkeep = &l:sel
1705 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001706 if !g:netrw_use_noswf
1707 let {a:vt}netrw_swfkeep = &l:swf
1708 endif
1709 let {a:vt}netrw_tskeep = &l:ts
1710 let {a:vt}netrw_twkeep = &l:tw " textwidth
1711 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1712 let {a:vt}netrw_wrapkeep = &l:wrap
1713 let {a:vt}netrw_writekeep = &l:write
1714
1715 " save a few selected netrw-related variables
1716" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1717 if g:netrw_keepdir
1718 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001719" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001720 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001721 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001722 sil! let {a:vt}netrw_starkeep = @*
1723 sil! let {a:vt}netrw_pluskeep = @+
1724 endif
1725 sil! let {a:vt}netrw_slashkeep= @/
1726
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001727" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001728" 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>"))
1729" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1730endfun
1731
1732" ---------------------------------------------------------------------
1733" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1734" Use s:NetrwSaveOptions() to save user settings
1735" Use s:NetrwOptionsRestore() to restore user settings
1736fun! s:NetrwOptionsSafe(islocal)
1737" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1738" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1739" 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>"))
1740 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1741 call s:NetrwSetSafeSetting("&l:ai",0)
1742 call s:NetrwSetSafeSetting("&l:aw",0)
1743 call s:NetrwSetSafeSetting("&l:bl",0)
1744 call s:NetrwSetSafeSetting("&l:bomb",0)
1745 if a:islocal
1746 call s:NetrwSetSafeSetting("&l:bt","nofile")
1747 else
1748 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1749 endif
1750 call s:NetrwSetSafeSetting("&l:ci",0)
1751 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001752 if g:netrw_fastbrowse > a:islocal
1753 call s:NetrwSetSafeSetting("&l:bh","hide")
1754 else
1755 call s:NetrwSetSafeSetting("&l:bh","delete")
1756 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001757 call s:NetrwSetSafeSetting("&l:cino","")
1758 call s:NetrwSetSafeSetting("&l:com","")
1759 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1760 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1761 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001762 if &go =~ 'a' | set go-=a | endif
1763 if &go =~ 'A' | set go-=A | endif
1764 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001765 call s:NetrwSetSafeSetting("&l:hid",0)
1766 call s:NetrwSetSafeSetting("&l:im",0)
1767 setl isk+=@ isk+=* isk+=/
1768 call s:NetrwSetSafeSetting("&l:magic",1)
1769 if g:netrw_use_noswf
1770 call s:NetrwSetSafeSetting("swf",0)
1771 endif
1772 call s:NetrwSetSafeSetting("&l:report",10000)
1773 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1774 call s:NetrwSetSafeSetting("&l:spell",0)
1775 call s:NetrwSetSafeSetting("&l:tw",0)
1776 call s:NetrwSetSafeSetting("&l:wig","")
1777 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001778
1779 " set up cuc and cul based on g:netrw_cursor and listing style
1780 " COMBAK -- cuc cul related
1781 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001782
1783 " allow the user to override safe options
1784" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1785 if &ft == "netrw"
1786" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1787 keepalt NetrwKeepj doau FileType netrw
1788 endif
1789
1790" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1791" 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>"))
1792" call Dret("s:NetrwOptionsSafe")
1793endfun
1794
1795" ---------------------------------------------------------------------
1796" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1797fun! s:NetrwOptionsRestore(vt)
1798" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001799" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001800" 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>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001801 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001802" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001803
1804 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1805 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001806" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001807 filetype detect
1808" 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>"))
1809 else
1810 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001811 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001812" 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 +02001813" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001814 return
1815 endif
1816 unlet {a:vt}netrw_optionsave
1817
1818 if exists("+acd")
1819 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001820" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001821 let curdir = getcwd()
1822 let &l:acd = {a:vt}netrw_acdkeep
1823 unlet {a:vt}netrw_acdkeep
1824 if &l:acd
1825 call s:NetrwLcd(curdir)
1826 endif
1827 endif
1828 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001829" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001830 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1831 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1832 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1833 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1834 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001835" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001836 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1837 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1838 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1839 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1840 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001841" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001842 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1843 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1844 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1845 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1846 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001847 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001848" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1849 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1850 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001851 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001852 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1853" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1854 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1855 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1856" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1857 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1858" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1859 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1860 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001861 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001862 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1863 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1864" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1865 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1866 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1867 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1868 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1869" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001870 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001871 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1872 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1873 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001874 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001875" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001876 call s:NetrwRestoreSetting("s:yykeep","@@")
1877 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1878 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1879 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1880 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1881
Bram Moolenaara6878372014-03-22 21:02:50 +01001882 if exists("{a:vt}netrw_swfkeep")
1883 if &directory == ""
1884 " user hasn't specified a swapfile directory;
1885 " netrw will temporarily set the swapfile directory
1886 " to the current directory as returned by getcwd().
1887 let &l:directory= getcwd()
1888 sil! let &l:swf = {a:vt}netrw_swfkeep
1889 setl directory=
1890 unlet {a:vt}netrw_swfkeep
1891 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001892 if !g:netrw_use_noswf
1893 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1894 sil! let &l:swf= {a:vt}netrw_swfkeep
1895 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001896 unlet {a:vt}netrw_swfkeep
1897 endif
1898 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001899 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001900 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1901 if exists("{a:vt}netrw_dirkeep")
1902 call s:NetrwLcd(dirkeep)
1903 unlet {a:vt}netrw_dirkeep
1904 endif
1905 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001906 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001907" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001908 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1909 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001910 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001911 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001912
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001913" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1914" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1915" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1916" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1917" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001918 " Moved the filetype detect here from NetrwGetFile() because remote files
1919 " were having their filetype detect-generated settings overwritten by
1920 " NetrwOptionRestore.
1921 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001922" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1923 filetype detect
1924" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001925 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001926" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001927" 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>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001928" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001929endfun
1930
1931" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001932" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1933" but only when the options' value and the safe setting differ
1934" Doing this means that netrw will not come up as having changed a
1935" setting last when it really didn't actually change it.
1936"
1937" Called from s:NetrwOptionsSafe
1938" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1939fun! s:NetrwSetSafeSetting(setting,safesetting)
1940" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001941
Bram Moolenaar85850f32019-07-19 22:05:51 +02001942 if a:setting =~ '^&'
1943" call Decho("fyi: a:setting starts with &")
1944 exe "let settingval= ".a:setting
1945" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001946
Bram Moolenaar85850f32019-07-19 22:05:51 +02001947 if settingval != a:safesetting
1948" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1949 if type(a:safesetting) == 0
1950 exe "let ".a:setting."=".a:safesetting
1951 elseif type(a:safesetting) == 1
1952 exe "let ".a:setting."= '".a:safesetting."'"
1953 else
1954 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1955 endif
1956 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001957 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001958
Bram Moolenaar85850f32019-07-19 22:05:51 +02001959" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001960endfun
1961
1962" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001963" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1964" but only if the setting value differs from the associated keepvar.
1965" Doing this means that netrw will not come up as having changed a
1966" setting last when it really didn't actually change it.
1967"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001968" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001969" keepvars are set up by s:NetrwOptionsSave
1970fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001971""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001972
Bram Moolenaar85850f32019-07-19 22:05:51 +02001973 " typically called from s:NetrwOptionsRestore
1974 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1975 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001976 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001977 if exists(a:keepvar)
1978 exe "let keepvarval= ".a:keepvar
1979 exe "let setting= ".a:setting
1980
1981"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1982"" call Decho("fyi: keepvarval=".keepvarval)
1983"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1984
1985 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001986"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001987 if type(a:setting) == 0
1988 exe "let ".a:setting."= ".keepvarval
1989 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001990 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001991 else
1992 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1993 endif
1994 endif
1995
1996 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001997 endif
1998
Bram Moolenaar85850f32019-07-19 22:05:51 +02001999"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02002000endfun
2001
2002" ---------------------------------------------------------------------
2003" NetrwStatusLine: {{{2
2004fun! NetrwStatusLine()
2005
2006" vvv NetrwStatusLine() debugging vvv
2007" let g:stlmsg=""
2008" if !exists("w:netrw_explore_bufnr")
2009" let g:stlmsg="!X<explore_bufnr>"
2010" elseif w:netrw_explore_bufnr != bufnr("%")
2011" let g:stlmsg="explore_bufnr!=".bufnr("%")
2012" endif
2013" if !exists("w:netrw_explore_line")
2014" let g:stlmsg=" !X<explore_line>"
2015" elseif w:netrw_explore_line != line(".")
2016" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2017" endif
2018" if !exists("w:netrw_explore_list")
2019" let g:stlmsg=" !X<explore_list>"
2020" endif
2021" ^^^ NetrwStatusLine() debugging ^^^
2022
2023 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")
2024 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002025 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002026 let &laststatus = s:netrw_users_ls
2027 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2028 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2029 return ""
2030 else
2031 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2032 endif
2033endfun
2034
Bram Moolenaar85850f32019-07-19 22:05:51 +02002035" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002036" Netrw Transfer Functions: {{{1
2037" ===============================
2038
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002040" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002041" mode: =0 read remote file and insert before current line
2042" =1 read remote file and insert after current line
2043" =2 replace with remote file
2044" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002045fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002046" 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 +00002047
Bram Moolenaar5c736222010-01-06 20:54:52 +01002048 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002049 call s:NetrwOptionsSave("w:")
2050 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002051 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002052 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2053 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2054 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002055" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056
Bram Moolenaar5c736222010-01-06 20:54:52 +01002057 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002058 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002059 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002060 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002061 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002062 elseif a:mode == 2 " replace with remote file
2063 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002064 elseif a:mode == 3 " skip read of file (leave as temporary)
2065 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002066 else
2067 exe a:mode
2068 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002069 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002070 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002071" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002072
Bram Moolenaar5c736222010-01-06 20:54:52 +01002073 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002074 let tmpfile= s:GetTempfile("")
2075 if tmpfile == ""
2076" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002077 return
2078 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002079
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002080 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002081
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002082 " attempt to repeat with previous host-file-etc
2083 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002084" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002085 let choice = b:netrw_lastfile
2086 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002087
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002088 else
2089 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002090" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002091
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002092 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002093 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002094 echomsg 'NetRead Usage:'
2095 echomsg ':Nread machine:path uses rcp'
2096 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2097 echomsg ':Nread "machine id password path" uses ftp'
2098 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2099 echomsg ':Nread fetch://machine/path uses fetch'
2100 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2101 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002102 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002103 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002104 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2105 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2106 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2107 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002108 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002109 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002110
Bram Moolenaar9964e462007-05-05 17:54:07 +00002111 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002112 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002113" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002114 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002115 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002116 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002117 else
2118 " case "... ... ..."
2119 let choice = strpart(choice,1,strlen(choice)-1)
2120 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002121
Bram Moolenaar9964e462007-05-05 17:54:07 +00002122 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002123 let wholechoice = wholechoice . " " . choice
2124 let ichoice = ichoice + 1
2125 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002126 if !exists("g:netrw_quiet")
2127 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2128 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002129" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002130 return
2131 endif
2132 let choice= a:{ichoice}
2133 endwhile
2134 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2135 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 endif
2137 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002139" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002140 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002141
Bram Moolenaar5c736222010-01-06 20:54:52 +01002142 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002143 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002144 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002145" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002146 return
2147 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002148 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002149
Bram Moolenaar8d043172014-01-23 14:24:41 +01002150 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002151" 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 +02002152 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002153" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002154 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002155" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002157 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002158
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002159 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002160 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002161 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002162 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2163 echo "(netrw) Processing your read request..."
2164 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002165
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002167 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002168 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002169" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002170 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002172 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002173 " ER: the tmpfile is full path: rcp sees C:\... as host C
2174 if s:netrw_has_nt_rcp == 1
2175 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2176 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2177 else
2178 " Any way needed it machine contains a '.'
2179 let uid_machine = g:netrw_machine .'.'. $USERNAME
2180 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002181 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002182 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2183 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2184 else
2185 let uid_machine = g:netrw_machine
2186 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002188 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 +00002189 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002190 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002191
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002192 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002193 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002194 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002195" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002196 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002197 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002198 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002199 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002200 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002201" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002202 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002203 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002205 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002206 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002207" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002208 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002209 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 +00002210 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002211 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002212 endif
2213 " 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 +00002214 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002215 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002216 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002217 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002218 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002219 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002220 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002221 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002222 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2223 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002224 q!
2225 endif
2226 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002227 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002229
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002231 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002232 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2233 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002234" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002235 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002236 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002237 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002238 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002239 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002242 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002243 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002244" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002245 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002246
Bram Moolenaar97d62492012-11-15 21:28:22 +01002247 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002248 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002249 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002250" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002251 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002252 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002253 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002255 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002256 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002257" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002258 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002259 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002260
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002261 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002262 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002263" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002264 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002265 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002266 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002267" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002268 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002269 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002270" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002271
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 " perform ftp:
2273 " -i : turns off interactive prompting from ftp
2274 " -n unix : DON'T use <.netrc>, even though it exists
2275 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002276 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002277 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2279 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002280" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002281 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002282 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002283 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002285 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002286 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002287 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002288
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002289 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002290 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002291 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002292" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002293 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002294 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002295 else
2296 let useport= ""
2297 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002298 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2299 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002300 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002301 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2302 else
2303 let tmpfile_get = tmpfile
2304 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002305 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 +00002306 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002307 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002308
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002309 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002310 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002311 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002312" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002313 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002314 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002315 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002316 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002317" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002318 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002319 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002320
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002321 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2322 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002323" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002324 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002325 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 +00002326 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002327 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 +00002328 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002329 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002330
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002331 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002332 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002333" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002334 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2335 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002336" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2337" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2338 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 +00002339 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002340" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002341 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002342 endif
2343 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002344" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002345 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002346
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002347 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002348 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002349 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002350" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002351
Bram Moolenaar5c736222010-01-06 20:54:52 +01002352 if !executable(g:netrw_dav_cmd)
2353 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2354" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2355 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002356 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002357 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002358 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 +01002359 else
2360 " Construct execution string (four lines) which will be passed through filter
2361 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2362 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002363 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002364 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002365 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002366 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002367 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002368 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002369 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002370 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002371 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002372 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2373 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002374
Bram Moolenaar5c736222010-01-06 20:54:52 +01002375 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002376 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002377 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002378 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002379 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002380 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002382
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002383 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002384 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002385 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002386" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002387 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 +00002388 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002390
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002392 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002394 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002395" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002396 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002397 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002398 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002399 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002400" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002401 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002402 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002403 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002404 let netrw_option= "http"
2405 else
2406 let netrw_option= "ftp"
2407 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002408" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002409
Bram Moolenaar446cb832008-06-24 21:56:24 +00002410 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002411 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 +00002412 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002413 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 +00002414 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002415
Bram Moolenaar446cb832008-06-24 21:56:24 +00002416 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002417 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002418" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002419 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002420
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002421 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002422 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002423 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002424" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2425 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 +00002426 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002427 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002428
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002429 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002430 " NetRead: (file) NetRead Method #10 {{{3
2431 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002432" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2433 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002434 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2435 let b:netrw_lastfile = choice
2436
2437 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002438 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002439 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002440 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002441 endif
2442 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002443
Bram Moolenaar5c736222010-01-06 20:54:52 +01002444 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002446" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002447 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002448 unlet b:netrw_fname
2449 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002450 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 +01002451" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002452 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002453 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002454 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002455
Bram Moolenaar9964e462007-05-05 17:54:07 +00002456" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002457endfun
2458
2459" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002460" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002461fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002462" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002463
Bram Moolenaar5c736222010-01-06 20:54:52 +01002464 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002465 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002466 call s:NetrwOptionsSave("w:")
2467 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002468
Bram Moolenaar5c736222010-01-06 20:54:52 +01002469 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002470 let tmpfile= s:GetTempfile("")
2471 if tmpfile == ""
2472" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002473 return
2474 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002475
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002476 if a:0 == 0
2477 let ichoice = 0
2478 else
2479 let ichoice = 1
2480 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002481
Bram Moolenaar9964e462007-05-05 17:54:07 +00002482 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002483" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002484 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002485 " For binary writes, always write entire file.
2486 " (line numbers don't really make sense for that).
2487 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002488" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002489 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002490 elseif g:netrw_cygwin
2491 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002492 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002493" 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 +01002494 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002495 else
2496 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002497" 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 +01002498 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002499 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002500
Bram Moolenaar9964e462007-05-05 17:54:07 +00002501 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002502 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002503 " on the temporary file's name. Deletion of the temporary file during
2504 " cleanup then causes an error message.
2505 0file!
2506 endif
2507
Bram Moolenaar5c736222010-01-06 20:54:52 +01002508 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002509 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002510
Bram Moolenaar9964e462007-05-05 17:54:07 +00002511 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002512 " attempt to repeat with previous host-file-etc
2513 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002514" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002515 let choice = b:netrw_lastfile
2516 let ichoice= ichoice + 1
2517 else
2518 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002519
Bram Moolenaar8d043172014-01-23 14:24:41 +01002520 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002521 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002522 echomsg 'NetWrite Usage:"'
2523 echomsg ':Nwrite machine:path uses rcp'
2524 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2525 echomsg ':Nwrite "machine id password path" uses ftp'
2526 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2527 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2528 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2529 echomsg ':Nwrite rcp://machine/path uses rcp'
2530 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2531 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2532 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002533 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002534 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002535
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002536 elseif match(choice,"^\"") != -1
2537 if match(choice,"\"$") != -1
2538 " case "..."
2539 let choice=strpart(choice,1,strlen(choice)-2)
2540 else
2541 " case "... ... ..."
2542 let choice = strpart(choice,1,strlen(choice)-1)
2543 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002544
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002545 while match(choice,"\"$") == -1
2546 let wholechoice= wholechoice . " " . choice
2547 let ichoice = ichoice + 1
2548 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002549 if !exists("g:netrw_quiet")
2550 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2551 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002552" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002553 return
2554 endif
2555 let choice= a:{ichoice}
2556 endwhile
2557 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2558 endif
2559 endif
2560 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002561 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002562" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002563
Bram Moolenaar9964e462007-05-05 17:54:07 +00002564 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002565 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002566 if !exists("b:netrw_method") || b:netrw_method < 0
2567" call Dfunc("netrw#NetWrite : unsupported method")
2568 return
2569 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002570
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002571 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002572 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002573 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002574 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2575 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002576" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002577 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002578
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002579 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002580 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002581 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002582" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002583 if s:netrw_has_nt_rcp == 1
2584 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2585 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2586 else
2587 let uid_machine = g:netrw_machine .'.'. $USERNAME
2588 endif
2589 else
2590 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2591 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2592 else
2593 let uid_machine = g:netrw_machine
2594 endif
2595 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002596 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 +00002597 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002598
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002599 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002600 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002601 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002602" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002603 let netrw_fname = b:netrw_fname
2604
2605 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2606 let bhkeep = &l:bh
2607 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002608 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002610
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002612 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002613 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002614" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002615 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002616 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002618 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002619 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002620" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002622 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 +00002623 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002624" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2625 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 endif
2627 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2628 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002629 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002630 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002631 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002632 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002634
2635 " remove enew buffer (quietly)
2636 let filtbuf= bufnr("%")
2637 exe curbuf."b!"
2638 let &l:bh = bhkeep
2639 exe filtbuf."bw!"
2640
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002642
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002643 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002645 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002646 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002647" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002648 let netrw_fname = b:netrw_fname
2649 let bhkeep = &l:bh
2650
2651 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2652 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002653 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002654 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002655 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002656
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002657 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002658 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002660 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002661 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002663 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002664 if exists("g:netrw_uid") && g:netrw_uid != ""
2665 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002666 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002667" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002668 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002669 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002670 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002672 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002673 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002674" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002675 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002676 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002677 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002678" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002679 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002680 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002681" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002682 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002683 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002684" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002685 " save choice/id/password for future use
2686 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002687
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002688 " perform ftp:
2689 " -i : turns off interactive prompting from ftp
2690 " -n unix : DON'T use <.netrc>, even though it exists
2691 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002692 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002693 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002694 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2695 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002696 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002697 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002698 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002699 let mod=1
2700 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002701
2702 " remove enew buffer (quietly)
2703 let filtbuf= bufnr("%")
2704 exe curbuf."b!"
2705 let &l:bh= bhkeep
2706 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002707
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002708 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002709 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002710 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002711" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002712 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002713 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002714 else
2715 let useport= ""
2716 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002717 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 +00002718 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002719
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002720 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002721 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002722 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002723" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002724 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2725 if executable(curl)
2726 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002727 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 +01002728 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002729 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002730 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002731
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002732 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002733 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002734 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002735" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002736
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002737 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002738 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2739 let bhkeep = &l:bh
2740
2741 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2742 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002743 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002744 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002745
Bram Moolenaarff034192013-04-24 18:51:19 +02002746 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002747 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002748 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002749 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002750 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002751 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002752 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002753 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002754 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002755 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002756
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002757 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002758 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002759 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002760
2761 " remove enew buffer (quietly)
2762 let filtbuf= bufnr("%")
2763 exe curbuf."b!"
2764 let &l:bh = bhkeep
2765 exe filtbuf."bw!"
2766
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002767 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: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002771 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002772" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002773 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 +00002774 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002775
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002776 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002777 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002778 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002779" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002780 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2782 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2783 else
2784 let uid_machine = g:netrw_machine
2785 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002786
2787 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2788 let bhkeep = &l:bh
2789 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002790 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002791 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002792
Bram Moolenaarff034192013-04-24 18:51:19 +02002793 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002794 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002795" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002796 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002797 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002798 let filtbuf= bufnr("%")
2799 exe curbuf."b!"
2800 let &l:bh = bhkeep
2801 exe filtbuf."bw!"
2802 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002803
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002804 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002805 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002806 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002807 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002808 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002810 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002811
Bram Moolenaar5c736222010-01-06 20:54:52 +01002812 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002813" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002814 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002815" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002816 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002817 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002818 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002819
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002820 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002821 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002822 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002823" 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 +02002824 elseif !exists("leavemod")
2825 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002826" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002827 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002828" 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 +00002829 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002830
Bram Moolenaar9964e462007-05-05 17:54:07 +00002831" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002832endfun
2833
2834" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002835" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002836" uses NetRead to get a copy of the file into a temporarily file,
2837" then sources that file,
2838" then removes that file.
2839fun! netrw#NetSource(...)
2840" call Dfunc("netrw#NetSource() a:0=".a:0)
2841 if a:0 > 0 && a:1 == '?'
2842 " give help
2843 echomsg 'NetSource Usage:'
2844 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2845 echomsg ':Nsource fetch://machine/path uses fetch'
2846 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002847 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002848 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2849 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2850 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2851 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2852 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002853 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002854 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002855 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002856 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002857" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002858 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002859" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002860 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002861" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002862 if delete(s:netrw_tmpfile)
2863 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2864 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002865 unlet s:netrw_tmpfile
2866 else
2867 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2868 endif
2869 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002870 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002871 endif
2872" call Dret("netrw#NetSource")
2873endfun
2874
Bram Moolenaar8d043172014-01-23 14:24:41 +01002875" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002876" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2877" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002878fun! netrw#SetTreetop(iscmd,...)
2879" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2880" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002881
Bram Moolenaar85850f32019-07-19 22:05:51 +02002882 " iscmd==0: netrw#SetTreetop called using gn mapping
2883 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2884" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002885 " clear out the current tree
2886 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002887" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002888 let inittreetop= w:netrw_treetop
2889 unlet w:netrw_treetop
2890 endif
2891 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002892" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002893 unlet w:netrw_treedict
2894 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002895" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002896
Bram Moolenaar85850f32019-07-19 22:05:51 +02002897 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002898 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002899" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002900 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002901 if isdirectory(s:NetrwFile(a:1))
2902" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002903 let treedir = a:1
2904 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002905 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002906 let treedir = b:netrw_curdir."/".a:1
2907 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002908" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002909 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002910 " normally the cursor is left in the message window.
2911 " However, here this results in the directory being listed in the message window, which is not wanted.
2912 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002913 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002914 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002915 let treedir = "."
2916 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002917 endif
2918 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002919" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002920
2921 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002922 let islocal= expand("%") !~ '^\a\{3,}://'
2923" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002924
2925 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002926 if islocal
2927 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2928 else
2929 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2930 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002931
Bram Moolenaara6878372014-03-22 21:02:50 +01002932" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002933endfun
2934
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002936" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002937" readcmd == %r : replace buffer with newly read file
2938" == 0r : read file at top of buffer
2939" == r : read file after current line
2940" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002941fun! s:NetrwGetFile(readcmd, tfile, method)
2942" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002943
2944 " readcmd=='t': simply do nothing
2945 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002946" 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 +01002947" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002948 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002949 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002950
Bram Moolenaar9964e462007-05-05 17:54:07 +00002951 " get name of remote filename (ie. url and all)
2952 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002953" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002954
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955 if exists("*NetReadFixup")
2956 " for the use of NetReadFixup (not otherwise used internally)
2957 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002958 endif
2959
Bram Moolenaar9964e462007-05-05 17:54:07 +00002960 if a:readcmd[0] == '%'
2961 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002962" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002963
2964 " rename the current buffer to the temp file (ie. tfile)
2965 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002966 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002967 else
2968 let tfile= a:tfile
2969 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002970 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971
2972 " edit temporary file (ie. read the temporary file in)
2973 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002974" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002975 call zip#Browse(tfile)
2976 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002978 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002979 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002981 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002982 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002983" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002984 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002985 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002986" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002987 call tar#Browse(tfile)
2988 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002989" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002990 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002991 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002992" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002993 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002994 endif
2995
2996 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002997 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002998
Bram Moolenaar71badf92023-04-22 22:40:14 +01002999 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01003000 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003001 " Note that isk must not include a "/" for scripts.vim
3002 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01003003" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
3004" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003005" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003006" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3007 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003008 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003009 filetype detect
3010" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003011 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003012" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003013 let line1 = 1
3014 let line2 = line("$")
3015
Bram Moolenaar8d043172014-01-23 14:24:41 +01003016 elseif !&ma
3017 " 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 +01003018 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003019" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003020 return
3021
Bram Moolenaar9964e462007-05-05 17:54:07 +00003022 elseif s:FileReadable(a:tfile)
3023 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003024" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003025 let curline = line(".")
3026 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003027" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003028 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003029 let line1= curline + 1
3030 let line2= line("$") - lastline + 1
3031
3032 else
3033 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003034" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3035" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003036 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003037" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003038 return
3039 endif
3040
3041 " User-provided (ie. optional) fix-it-up command
3042 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003043" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003044 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003045" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003046" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003047 endif
3048
Bram Moolenaaradc21822011-04-01 18:03:16 +02003049 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003050 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003051 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003052 endif
3053
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003054" 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 +00003055
3056 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003057" redraw!
3058
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003059" 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 +00003060" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003061endfun
3062
Bram Moolenaar9964e462007-05-05 17:54:07 +00003063" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003064" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003065" Input:
3066" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3067" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003068" b:netrw_method= 1: rcp
3069" 2: ftp + <.netrc>
3070" 3: ftp + machine, id, password, and [path]filename
3071" 4: scp
3072" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003073" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003074" 7: rsync
3075" 8: fetch
3076" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003077" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003078" g:netrw_machine= hostname
3079" b:netrw_fname = filename
3080" g:netrw_port = optional port number (for ftp)
3081" g:netrw_choice = copy of input url (choice)
3082fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003083" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003084
Bram Moolenaar251e1912011-06-19 05:09:16 +02003085 " sanity check: choice should have at least three slashes in it
3086 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3087 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3088 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003089" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003090 return
3091 endif
3092
Bram Moolenaar5c736222010-01-06 20:54:52 +01003093 " record current g:netrw_machine, if any
3094 " curmachine used if protocol == ftp and no .netrc
3095 if exists("g:netrw_machine")
3096 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003097" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003098 else
3099 let curmachine= "N O T A HOST"
3100 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003101 if exists("g:netrw_port")
3102 let netrw_port= g:netrw_port
3103 endif
3104
3105 " insure that netrw_ftp_cmd starts off every method determination
3106 " with the current g:netrw_ftp_cmd
3107 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003108
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 " initialization
3110 let b:netrw_method = 0
3111 let g:netrw_machine = ""
3112 let b:netrw_fname = ""
3113 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003114 let g:netrw_choice = a:choice
3115
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003117 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003118 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3119 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003120 " rcpurm : rcp://[user@]host/filename Use rcp
3121 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003122 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003123 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003124 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003125 " rsyncurm : rsync://host[:port]/path Use rsync
3126 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3127 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003128 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3130 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003131 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3132 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003133 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003134 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003135 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003136 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003137 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003138 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003140 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003141
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003142" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003143 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003144 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003145 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003146" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003147 let b:netrw_method = 1
3148 let userid = substitute(a:choice,rcpurm,'\1',"")
3149 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3150 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003151 if userid != ""
3152 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003154
Bram Moolenaaradc21822011-04-01 18:03:16 +02003155 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003156 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003157" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003158 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003159 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3160 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3161 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003162
Bram Moolenaar15146672011-10-20 22:22:38 +02003163 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003164 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003165" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003166 let b:netrw_method = 5
3167 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3168 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003169 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003170
Bram Moolenaaradc21822011-04-01 18:03:16 +02003171 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003172 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003173" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003174 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003175 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003176 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3177 else
3178 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3179 endif
3180 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003181
Bram Moolenaaradc21822011-04-01 18:03:16 +02003182 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003183 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003184" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003185 let b:netrw_method = 7
3186 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3187 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003188
Bram Moolenaaradc21822011-04-01 18:03:16 +02003189 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003190 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003191" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003192 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003193 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3194 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3195 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003196" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003197 if userid != ""
3198 let g:netrw_uid= userid
3199 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003200
Bram Moolenaaradc21822011-04-01 18:03:16 +02003201 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003202 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003203 call NetUserPass("ftp:".g:netrw_machine)
3204 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003205 " if there's a change in hostname, require password re-entry
3206 unlet s:netrw_passwd
3207 endif
3208 if exists("netrw_port")
3209 unlet netrw_port
3210 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003211 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003212
Bram Moolenaar446cb832008-06-24 21:56:24 +00003213 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003214 let b:netrw_method = 3
3215 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003216 let host= substitute(g:netrw_machine,'\..*$','','')
3217 if exists("s:netrw_hup[host]")
3218 call NetUserPass("ftp:".host)
3219
Nir Lichtman1e34b952024-05-08 19:19:34 +02003220 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003221" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3222" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003223 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003224 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003225" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003226 endif
3227 let b:netrw_method= 2
3228 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003229" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003230 let b:netrw_method= 2
3231 else
3232 if !exists("g:netrw_uid") || g:netrw_uid == ""
3233 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003234 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003235 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003236 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003237 endif
3238 let b:netrw_method= 3
3239 endif
3240 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003241
Bram Moolenaaradc21822011-04-01 18:03:16 +02003242 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003243 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003244" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003245 let b:netrw_method = 8
3246 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3247 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3248 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3249 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003250
Bram Moolenaaradc21822011-04-01 18:03:16 +02003251 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003252 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003253" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003255 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3256 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003257 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003258 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003259 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003260
Bram Moolenaaradc21822011-04-01 18:03:16 +02003261 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003262 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003263" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003264 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003265 let b:netrw_method = 3
3266 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3267 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003268
Bram Moolenaar9964e462007-05-05 17:54:07 +00003269 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003270 let b:netrw_method = 2
3271 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3272 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3273 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003274
Bram Moolenaaradc21822011-04-01 18:03:16 +02003275 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003276 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003277" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003278 let b:netrw_method = 9
3279 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3280 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003281
Bram Moolenaaradc21822011-04-01 18:03:16 +02003282 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003283 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003284" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003285 let b:netrw_method = 1
3286 let userid = substitute(a:choice,rcphf,'\2',"")
3287 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3288 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003289" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3290" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3291" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3292" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003293 if userid != ""
3294 let g:netrw_uid= userid
3295 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003296
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003297 " Method#10: file://user@hostname/...path-to-file {{{3
3298 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003299" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003300 let b:netrw_method = 10
3301 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003302" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003303
Bram Moolenaaradc21822011-04-01 18:03:16 +02003304 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003305 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003306 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003307 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003308 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003309 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003311 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003312
Bram Moolenaar81695252004-12-29 20:58:21 +00003313 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003314 " remove any leading [:#] from port number
3315 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3316 elseif exists("netrw_port")
3317 " retain port number as implicit for subsequent ftp operations
3318 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003319 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003320
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003321" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3322" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3323" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3324" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003325" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003326" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003327" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003328" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003329" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003330" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003331" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003332" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334
Bram Moolenaar9964e462007-05-05 17:54:07 +00003335" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003336" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003337" Usage: :call NetUserPass() -- will prompt for userid and password
3338" :call NetUserPass("uid") -- will prompt for password
3339" :call NetUserPass("uid","password") -- sets global userid and password
3340" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3341" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342fun! NetUserPass(...)
3343
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003344" call Dfunc("NetUserPass() a:0=".a:0)
3345
3346 if !exists('s:netrw_hup')
3347 let s:netrw_hup= {}
3348 endif
3349
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003351 " case: no input arguments
3352
3353 " change host and username if not previously entered; get new password
3354 if !exists("g:netrw_machine")
3355 let g:netrw_machine= input('Enter hostname: ')
3356 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003358 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359 let g:netrw_uid= input('Enter username: ')
3360 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003361 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003362 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003363
3364 " set up hup database
3365 let host = substitute(g:netrw_machine,'\..*$','','')
3366 if !exists('s:netrw_hup[host]')
3367 let s:netrw_hup[host]= {}
3368 endif
3369 let s:netrw_hup[host].uid = g:netrw_uid
3370 let s:netrw_hup[host].passwd = s:netrw_passwd
3371
3372 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003373 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003374
3375 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003376 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003377 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003378" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003379 let host = substitute(a:1,'^ftp:','','')
3380 let host = substitute(host,'\..*','','')
3381 if exists("s:netrw_hup[host]")
3382 let g:netrw_uid = s:netrw_hup[host].uid
3383 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003384" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3385" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003386 else
3387 let g:netrw_uid = input("Enter UserId: ")
3388 let s:netrw_passwd = inputsecret("Enter Password: ")
3389 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003390
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003391 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003392 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003393" 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 +02003394 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003395 if g:netrw_machine =~ '[0-9.]\+'
3396 let host= g:netrw_machine
3397 else
3398 let host= substitute(g:netrw_machine,'\..*$','','')
3399 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003400 else
3401 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003402 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003403 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003404" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003405 if exists("g:netrw_passwd")
3406 " ask for password if one not previously entered
3407 let s:netrw_passwd= g:netrw_passwd
3408 else
3409 let s:netrw_passwd = inputsecret("Enter Password: ")
3410 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003411 endif
3412
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003413" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003414 if exists("host")
3415 if !exists('s:netrw_hup[host]')
3416 let s:netrw_hup[host]= {}
3417 endif
3418 let s:netrw_hup[host].uid = g:netrw_uid
3419 let s:netrw_hup[host].passwd = s:netrw_passwd
3420 endif
3421
3422 elseif a:0 == 2
3423 let g:netrw_uid = a:1
3424 let s:netrw_passwd = a:2
3425
3426 elseif a:0 == 3
3427 " enter hostname, user-id, and password into the hup dictionary
3428 let host = substitute(a:1,'^\a\+:','','')
3429 let host = substitute(host,'\..*$','','')
3430 if !exists('s:netrw_hup[host]')
3431 let s:netrw_hup[host]= {}
3432 endif
3433 let s:netrw_hup[host].uid = a:2
3434 let s:netrw_hup[host].passwd = a:3
3435 let g:netrw_uid = s:netrw_hup[host].uid
3436 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003437" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3438" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003440
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003441" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003442endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443
Bram Moolenaar85850f32019-07-19 22:05:51 +02003444" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003445" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003446" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003448" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003449" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3450fun! s:ExplorePatHls(pattern)
3451" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3452 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003453" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003454 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003455" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003456 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3457" call Dret("s:ExplorePatHls repat<".repat.">")
3458 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003459endfun
3460
3461" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003462" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003463" 0: (user: <mb>) bookmark current directory
3464" 1: (user: <gb>) change to the bookmarked directory
3465" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003466" 3: (browsing) records current directory history
3467" 4: (user: <u>) go up (previous) directory, using history
3468" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003469" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003470fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003471" 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 +02003472 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3473" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3474 return
3475 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003476
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003477 let ykeep = @@
3478 let curbufnr = bufnr("%")
3479
Bram Moolenaar9964e462007-05-05 17:54:07 +00003480 if a:chg == 0
3481 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003482" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003483 if exists("s:netrwmarkfilelist_{curbufnr}")
3484 call s:NetrwBookmark(0)
3485 echo "bookmarked marked files"
3486 else
3487 call s:MakeBookmark(a:curdir)
3488 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003489 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003490
KSR-Yasudaf4498252023-10-06 03:34:17 +09003491 try
3492 call s:NetrwBookHistSave()
3493 catch
3494 endtry
3495
Bram Moolenaar9964e462007-05-05 17:54:07 +00003496 elseif a:chg == 1
3497 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003498" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003499 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003500" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003501 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003502 else
3503 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3504 endif
3505
3506 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003507" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003508 let didwork= 0
3509 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003510" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003511 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003512" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003513 let cnt= 1
3514 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003515" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003516 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003517 let didwork = 1
3518 let cnt = cnt + 1
3519 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003520 endif
3521
3522 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003523 " Note: history is saved only when PerformListing is done;
3524 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3525 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003526 let first = 1
3527 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003528 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003529 while ( first || cnt != g:netrw_dirhistcnt )
3530" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003531 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003532" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003533 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003534 let didwork= 1
3535 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003536 let histcnt = histcnt + 1
3537 let first = 0
3538 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003539 if cnt < 0
3540 let cnt= cnt + g:netrw_dirhistmax
3541 endif
3542 endwhile
3543 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003544 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003545 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003546 if didwork
3547 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3548 endif
3549
3550 elseif a:chg == 3
3551 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003552" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003553 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 +02003554 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003555 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3556 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003557 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003558" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003559 endif
3560
3561 elseif a:chg == 4
3562 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003563" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003564 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003565 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3566 if g:netrw_dirhistcnt < 0
3567 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003568 endif
3569 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003570 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003571 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003572 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3573" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003574 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003575 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003576" call Decho("setl ma noro",'~'.expand("<slnum>"))
3577 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003578 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003579" call Decho("setl nomod",'~'.expand("<slnum>"))
3580" 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 +00003581 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003582" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3583 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003584 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003585 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003586 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003587 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003588 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003589 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003590 echo "Sorry, no predecessor directory exists yet"
3591 endif
3592
3593 elseif a:chg == 5
3594 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003595" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003596 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003597 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3598 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3599" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003600 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003601" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003602 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003603 sil! NetrwKeepj %d _
3604" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3605" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003606 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003607" 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 +02003608 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003609" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3610 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003611 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003612 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3613 if g:netrw_dirhistcnt < 0
3614 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003615 endif
3616 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003617 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003618 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003619 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003620 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003621 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003622
3623 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003624" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003625 if exists("s:netrwmarkfilelist_{curbufnr}")
3626 call s:NetrwBookmark(1)
3627 echo "removed marked files from bookmarks"
3628 else
3629 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003630 let iremove = v:count
3631 let dremove = g:netrw_bookmarklist[iremove - 1]
3632" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003633 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003634" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3635 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3636 echo "removed ".dremove." from g:netrw_bookmarklist"
3637" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003638 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003639" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003640
3641 try
3642 call s:NetrwBookHistSave()
3643 catch
3644 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003645 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003646 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003647 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003648 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003649" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003650endfun
3651
3652" ---------------------------------------------------------------------
3653" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003654" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003655" Sister function: s:NetrwBookHistSave()
3656fun! s:NetrwBookHistRead()
3657" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003658 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003659" 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 +02003660 return
3661 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003662 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003663
3664 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003665 if !exists("s:netrw_initbookhist")
3666 let home = s:NetrwHome()
3667 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003668 if filereadable(s:NetrwFile(savefile))
3669" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003670 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003671 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003672
3673 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003674 if g:netrw_dirhistmax > 0
3675 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003676 if filereadable(s:NetrwFile(savefile))
3677" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003678 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003679 endif
3680 let s:netrw_initbookhist= 1
3681 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003682 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003683 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003684
Bram Moolenaar97d62492012-11-15 21:28:22 +01003685 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003686" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3687" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003688" call Dret("s:NetrwBookHistRead")
3689endfun
3690
3691" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003692" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003693" Sister function: s:NetrwBookHistRead()
3694" I used to do this via viminfo but that appears to
3695" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003696" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3697" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003698" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003699fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003700" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003701 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003702" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003703 return
3704 endif
3705
Bram Moolenaar5c736222010-01-06 20:54:52 +01003706 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003707" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003708 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003709
3710 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003711 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003712" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003713 if g:netrw_use_noswf
3714 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3715 else
3716 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3717 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003718 setl nocin noai noci magic nospell nohid wig= noaw
3719 setl ma noro write
3720 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003721 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003722
Bram Moolenaar85850f32019-07-19 22:05:51 +02003723 " rename enew'd file: .netrwhist -- no attempt to merge
3724 " record dirhistmax and current dirhistcnt
3725 " save history
3726" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003727 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003728 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003729 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3730 if g:netrw_dirhistmax > 0
3731 let lastline = line("$")
3732 let cnt = g:netrw_dirhistcnt
3733 let first = 1
3734 while ( first || cnt != g:netrw_dirhistcnt )
3735 let lastline= lastline + 1
3736 if exists("g:netrw_dirhist_{cnt}")
3737 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3738" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3739 endif
3740 let first = 0
3741 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3742 if cnt < 0
3743 let cnt= cnt + g:netrw_dirhistmax
3744 endif
3745 endwhile
3746 exe "sil! w! ".savefile
3747" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3748 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003749
Bram Moolenaar85850f32019-07-19 22:05:51 +02003750 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003751 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003752 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003753" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003754 " merge and write .netrwbook
3755 let savefile= s:NetrwHome()."/.netrwbook"
3756
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003757 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003758 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003759 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003760 for bdm in booklist
3761 if index(g:netrw_bookmarklist,bdm) == -1
3762 call add(g:netrw_bookmarklist,bdm)
3763 endif
3764 endfor
3765 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003766 endif
3767
3768 " construct and save .netrwbook
3769 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003770 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003771" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003772 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003773
3774 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003775 let bgone= bufnr("%")
3776 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003777 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003778
3779" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003780endfun
3781
3782" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003783" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3784" list of the contents of a local or remote directory. It is assumed that the
3785" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3786" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003787" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003788fun! s:NetrwBrowse(islocal,dirname)
3789 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003790" 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 +02003791" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3792" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3793" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003794
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003795 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3796 " This is useful when one edits a local file, then :e ., then :Rex
3797 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3798 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003799" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003800 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003801
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003802 " s:NetrwBrowse : initialize history {{{3
3803 if !exists("s:netrw_initbookhist")
3804 NetrwKeepj call s:NetrwBookHistRead()
3805 endif
3806
3807 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003808 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003809 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003810" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003811 else
3812 let dirname= a:dirname
3813 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003814
Bram Moolenaar85850f32019-07-19 22:05:51 +02003815 " repoint t:netrw_lexbufnr if appropriate
3816 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3817" call Decho("set repointlexbufnr to true!")
3818 let repointlexbufnr= 1
3819 endif
3820
3821 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003822 if exists("s:netrw_skipbrowse")
3823 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003824" 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 +01003825" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003826 return
3827 endif
3828 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003829 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003830" call Dret("s:NetrwBrowse : missing shellescape()")
3831 return
3832 endif
3833 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003834 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003835" call Dret("s:NetrwBrowse : missing fnameescape()")
3836 return
3837 endif
3838
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003839 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003840 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003841
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003842 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003843 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3844 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3845" call Decho("clearing marked files",'~'.expand("<slnum>"))
3846 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3847 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003848 endif
3849
3850 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003851 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003852" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3853" 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 +02003854 if s:NetrwLcd(dirname)
3855" call Dret("s:NetrwBrowse : lcd failure")
3856 return
3857 endif
3858 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003859" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003860
Bram Moolenaar5c736222010-01-06 20:54:52 +01003861 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003862 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003863" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003864 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003865" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003866 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003867 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003868 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003869" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003870
3871 " remove any filetype indicator from end of dirname, except for the
3872 " "this is a directory" indicator (/).
3873 " There shouldn't be one of those here, anyway.
3874 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003875" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003876 call s:RemotePathAnalysis(dirname)
3877
3878 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3879 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003880 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003881 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003882" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003883 let b:netrw_curdir = dirname
3884 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003885 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003886 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3887 sil call netrw#NetRead(2,url)
3888 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003889" call Decho("url<".url.">",'~'.expand("<slnum>"))
3890" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3891" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003892 if s:path =~ '.bz2'
3893 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3894 elseif s:path =~ '.gz'
3895 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3896 elseif s:path =~ '.gz'
3897 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3898 else
3899 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3900 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003901 endif
3902
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003903 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003904 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003905 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003906" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003907 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003908" 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 +00003909
Bram Moolenaar446cb832008-06-24 21:56:24 +00003910" call Dret("s:NetrwBrowse : file<".s:fname.">")
3911 return
3912 endif
3913
Bram Moolenaaradc21822011-04-01 18:03:16 +02003914 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003915 call s:UseBufWinVars()
3916
3917 " set up some variables {{{3
3918 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003919 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003920 let s:last_sort_by = g:netrw_sort_by
3921
3922 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003923 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003924
Bram Moolenaar97d62492012-11-15 21:28:22 +01003925 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003926" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003927 let svpos = winsaveview()
3928" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003929 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003930
Bram Moolenaar446cb832008-06-24 21:56:24 +00003931 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003932 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3933 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3934" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3935" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3936 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3937 else
3938" " call Decho("2match none",'~'.expand("<slnum>"))
3939 2match none
3940 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003941 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003942 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003943 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003945 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003946" 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 +01003947" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003948 return
3949 endif
3950
3951 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003952" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003953 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003954 if b:netrw_curdir =~ '[/\\]$'
3955 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3956 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003957 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003958 let b:netrw_curdir= b:netrw_curdir."/"
3959 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003960 if b:netrw_curdir == ''
3961 if has("amiga")
3962 " On the Amiga, the empty string connotes the current directory
3963 let b:netrw_curdir= getcwd()
3964 else
3965 " under unix, when the root directory is encountered, the result
3966 " from the preceding substitute is an empty string.
3967 let b:netrw_curdir= '/'
3968 endif
3969 endif
3970 if !a:islocal && b:netrw_curdir !~ '/$'
3971 let b:netrw_curdir= b:netrw_curdir.'/'
3972 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003973" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003974
3975 " ------------
3976 " (local only) {{{3
3977 " ------------
3978 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003979" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003980
3981 " Set up ShellCmdPost handling. Append current buffer to browselist
3982 call s:LocalFastBrowser()
3983
3984 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3985 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003986" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3987" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003988 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003989 if s:NetrwLcd(b:netrw_curdir)
3990" call Dret("s:NetrwBrowse : lcd failure")
3991 return
3992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003993 endif
3994 endif
3995
3996 " --------------------------------
3997 " remote handling: {{{3
3998 " --------------------------------
3999 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004001
Bram Moolenaar97d62492012-11-15 21:28:22 +01004002 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004003" 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 +02004004 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004005 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004006" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004007 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4008 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4009 if dirname !~ '/$'
4010 let dirname= dirname.'/'
4011 endif
4012 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004013" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004014 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004015 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004016" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004017 endif
4018
4019 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4020 if dirname !~ dirpat
4021 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004022 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004023 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004024 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004025" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004026 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004027" 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 +00004028" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4029 return
4030 endif
4031 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004032" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004033 endif " (additional remote handling)
4034
Bram Moolenaar85850f32019-07-19 22:05:51 +02004035 " -------------------------------
4036 " Perform Directory Listing: {{{3
4037 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004038 NetrwKeepj call s:NetrwMaps(a:islocal)
4039 NetrwKeepj call s:NetrwCommands(a:islocal)
4040 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004041
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004042 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004043 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004044" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4045
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004046 " If there is a rexposn: restore position with rexposn
4047 " Otherwise : set rexposn
4048 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004049" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4050 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4051 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4052 NetrwKeepj exe w:netrw_bannercnt
4053 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004054 else
4055 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4056 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004057 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004058 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004059" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004060 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004061 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004062
Bram Moolenaar85850f32019-07-19 22:05:51 +02004063 " repoint t:netrw_lexbufnr if appropriate
4064 if exists("repointlexbufnr")
4065 let t:netrw_lexbufnr= bufnr("%")
4066" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4067 endif
4068
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004069 " restore position
4070 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004071" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4072 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004073 endif
4074
Bram Moolenaara6878372014-03-22 21:02:50 +01004075 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004076 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4077 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004078" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4079" 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 +02004080" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004081 return
4082endfun
4083
4084" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004085" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4086" may not apply correctly; ie. netrw's idea of the current directory may
4087" differ from vim's. This function insures that netrw's idea of the current
4088" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004089" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004090fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004091" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4092" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4093" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4094" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4095" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004096
4097 " clean up any leading treedepthstring
4098 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4099 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004100" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004101 else
4102 let fname= a:fname
4103 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004104
4105 if g:netrw_keepdir
4106 " vim's idea of the current directory possibly may differ from netrw's
4107 if !exists("b:netrw_curdir")
4108 let b:netrw_curdir= getcwd()
4109 endif
4110
Nir Lichtman1e34b952024-05-08 19:19:34 +02004111 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004112 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004114 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004115" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004116 else
4117 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004118 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004119" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004120 endif
4121
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004122 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004123 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004124 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004125" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004126 else
4127 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004128 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004129" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004130 endif
4131 else
4132 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004133 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004134" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4135" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4136" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004137 endif
4138
Bram Moolenaar85850f32019-07-19 22:05:51 +02004139" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004140 return ret
4141endfun
4142
4143" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004144" s:NetrwFileInfo: supports qf (query for file information) {{{2
4145fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004146" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004147 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004148 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004149 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004150 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004152 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004153 let lsopt= "-lsadh --si"
4154 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004155" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004156 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004157
4158 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004159 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004160" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004161
Bram Moolenaara6878372014-03-22 21:02:50 +01004162 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004163 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004165
4166 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004167 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004168" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004169
Bram Moolenaar446cb832008-06-24 21:56:24 +00004170 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004171" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004172 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004173" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004174 endif
4175 else
4176 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004177" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4178 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004179 let fname= substitute(a:fname,".$","","")
4180 else
4181 let fname= a:fname
4182 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004183 let t = getftime(s:NetrwFile(fname))
4184 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004185 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004186 let sz= s:NetrwHumanReadable(sz)
4187 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004188 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4189" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004190 endif
4191 else
4192 echo "sorry, \"qf\" not supported yet for remote files"
4193 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004194 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004195" call Dret("s:NetrwFileInfo")
4196endfun
4197
4198" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004199" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4200fun! s:NetrwFullPath(filename)
4201" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4202 let filename= a:filename
4203 if filename !~ '^/'
4204 let filename= resolve(getcwd().'/'.filename)
4205 endif
4206 if filename != "/" && filename =~ '/$'
4207 let filename= substitute(filename,'/$','','')
4208 endif
4209" " call Dret("s:NetrwFullPath <".filename.">")
4210 return filename
4211endfun
4212
4213" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004214" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004215" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004216" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004217" 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 +00004218fun! s:NetrwGetBuffer(islocal,dirname)
4219" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004220" 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 +02004221" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4222" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004223 let dirname= a:dirname
4224
4225 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004226" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004227 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004228" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004229 let s:netrwbuf= {}
4230 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004231" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4232" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4233
4234 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4235 let bufnum = -1
4236
4237 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4238 if has_key(s:netrwbuf,"NetrwTreeListing")
4239 let bufnum= s:netrwbuf["NetrwTreeListing"]
4240 else
4241 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4242 endif
4243" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4244 if !bufexists(bufnum)
4245 call remove(s:netrwbuf,"NetrwTreeListing"])
4246 let bufnum= -1
4247 endif
4248 elseif bufnr("NetrwTreeListing") != -1
4249 let bufnum= bufnr("NetrwTreeListing")
4250" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4251 else
4252" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4253 let bufnum= -1
4254 endif
4255
4256 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004257 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004258" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004259 if !bufexists(bufnum)
4260 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4261 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004262 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004263
Bram Moolenaar446cb832008-06-24 21:56:24 +00004264 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004265" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004266 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004267 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004268" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4269
Bram Moolenaar71badf92023-04-22 22:40:14 +01004270 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004271 " IF the buffer already has the desired name
4272 " AND it is empty
4273 let curbuf = bufname("%")
4274 if curbuf == '.'
4275 let curbuf = getcwd()
4276 endif
4277" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004278" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004279" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4280" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4281" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4282" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4283 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004284" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4285 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004286 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004287" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004288 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004289 " 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 +00004290
4291 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004292 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004293" 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 +00004294 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004295" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004296 " name the buffer
4297 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4298 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004299" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004300 let w:netrw_treebufnr = bufnr("%")
4301 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004302 if g:netrw_use_noswf
4303 setl nobl bt=nofile noswf
4304 else
4305 setl nobl bt=nofile
4306 endif
4307 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4308 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4309 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4310 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004311" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004312 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004313 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004314 " enter the new buffer into the s:netrwbuf dictionary
4315 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4316" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4317" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004318 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004319" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004320
4321 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004322" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004323 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004324 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004325 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004326
4327 if &ft == "netrw"
4328" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4329 exe "sil! NetrwKeepj noswapfile b ".bufnum
4330" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004331 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004332" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4333 call s:NetrwEditBuf(bufnum)
4334" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004335 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004336" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004337 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004338 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004339 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004340
4341 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004342 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004343
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004344 if line("$") <= 1 && getline(1) == ""
4345 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004346 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004347" 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>"))
4348" 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 +01004349" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4350 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004351
Bram Moolenaar97d62492012-11-15 21:28:22 +01004352 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004353" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004354 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004355 sil NetrwKeepj %d _
4356" 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>"))
4357" 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 +01004358" 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 +00004359 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004360
Bram Moolenaar446cb832008-06-24 21:56:24 +00004361 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004362" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4363" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004364 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004365 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004366 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004367" 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>"))
4368" 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 +01004369" 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 +00004370 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004371
Bram Moolenaar446cb832008-06-24 21:56:24 +00004372 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004373" 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>"))
4374" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4375" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004376 return 1
4377 endif
4378 endif
4379
4380 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4381 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4382 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4383 " med 1 D H
4384 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004385" 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 +00004386 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004387 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004388 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004389
4390 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004391" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4392" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4393 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004394
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004395" 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>"))
4396" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4397" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004398 return 0
4399endfun
4400
4401" ---------------------------------------------------------------------
4402" s:NetrwGetcwd: get the current directory. {{{2
4403" Change backslashes to forward slashes, if any.
4404" If doesc is true, escape certain troublesome characters
4405fun! s:NetrwGetcwd(doesc)
4406" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4407 let curdir= substitute(getcwd(),'\\','/','ge')
4408 if curdir !~ '[\/]$'
4409 let curdir= curdir.'/'
4410 endif
4411 if a:doesc
4412 let curdir= fnameescape(curdir)
4413 endif
4414" call Dret("NetrwGetcwd <".curdir.">")
4415 return curdir
4416endfun
4417
4418" ---------------------------------------------------------------------
4419" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4420fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004421" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4422" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4423 let keepsol= &l:sol
4424 setl nosol
4425
Bram Moolenaar446cb832008-06-24 21:56:24 +00004426 call s:UseBufWinVars()
4427
4428 " insure that w:netrw_liststyle is set up
4429 if !exists("w:netrw_liststyle")
4430 if exists("g:netrw_liststyle")
4431 let w:netrw_liststyle= g:netrw_liststyle
4432 else
4433 let w:netrw_liststyle= s:THINLIST
4434 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004435" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004436 endif
4437
4438 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4439 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004440" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004441 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004442 let dirname= "./"
4443 let curline= getline('.')
4444
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004445 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004446 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004447 let s:netrw_skipbrowse= 1
4448 echo 'Pressing "s" also works'
4449
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004450 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004451 let s:netrw_skipbrowse= 1
4452 echo 'Press "S" to edit sorting sequence'
4453
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004454 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004455 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004456 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004457
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004458 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004459 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004460 let s:netrw_skipbrowse= 1
4461 echo 'Pressing "a" also works'
4462
4463 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004464 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004465 endif
4466
4467 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004468" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004469 NetrwKeepj norm! 0
4470 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004471
4472 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004473" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004474 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004475 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4476
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004477 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004478" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004479 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004480 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004481
4482 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004483" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004484 let dirname= getline('.')
4485
4486 if !exists("b:netrw_cpf")
4487 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004488 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 +01004489 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004490" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004491 endif
4492
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004493" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004494 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004495" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4496" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004497 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004498 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004499 else
4500 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004501 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004502 endif
4503 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004504 let eofname= filestart + b:netrw_cpf + 1
4505 if eofname <= col("$")
4506 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004507 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004508 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004509 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004510 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004511 let dirname = @a
4512 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004513" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004514 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004515" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004516 endif
4517
4518 " symlinks are indicated by a trailing "@". Remove it before further processing.
4519 let dirname= substitute(dirname,"@$","","")
4520
4521 " executables are indicated by a trailing "*". Remove it before further processing.
4522 let dirname= substitute(dirname,"\*$","","")
4523
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004524 let &l:sol= keepsol
4525
Bram Moolenaar446cb832008-06-24 21:56:24 +00004526" call Dret("s:NetrwGetWord <".dirname.">")
4527 return dirname
4528endfun
4529
4530" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004531" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4532" g:netrw_bufsettings will be used after the listing is produced.
4533" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004534fun! s:NetrwListSettings(islocal)
4535" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004536" 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 +00004537 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004538" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4539 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4540 setl bt=nofile nobl ma nonu nowrap noro nornu
4541 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004542 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004543 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004545" call Dredir("ls!","s:NetrwListSettings")
4546" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004547 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004548 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004549 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004550 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004551 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004552 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004553 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004554" 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 +00004555" call Dret("s:NetrwListSettings")
4556endfun
4557
4558" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004559" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004560" islocal=0: remote browsing
4561" =1: local browsing
4562fun! s:NetrwListStyle(islocal)
4563" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004564
Bram Moolenaar97d62492012-11-15 21:28:22 +01004565 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004566 let fname = s:NetrwGetWord()
4567 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004568 let svpos = winsaveview()
4569" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004570 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004571" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4572" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4573" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004574
Bram Moolenaar85850f32019-07-19 22:05:51 +02004575 " repoint t:netrw_lexbufnr if appropriate
4576 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4577" call Decho("set repointlexbufnr to true!")
4578 let repointlexbufnr= 1
4579 endif
4580
Bram Moolenaar446cb832008-06-24 21:56:24 +00004581 if w:netrw_liststyle == s:THINLIST
4582 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004583" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004584 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4585
4586 elseif w:netrw_liststyle == s:LONGLIST
4587 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004588" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004589 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4590
4591 elseif w:netrw_liststyle == s:WIDELIST
4592 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004593" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004594 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4595
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004596 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004597" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004598 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4599
4600 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004601 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004602 let g:netrw_liststyle = s:THINLIST
4603 let w:netrw_liststyle = g:netrw_liststyle
4604 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4605 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004606 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004607" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004608
4609 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004610" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4611 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004612 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004613" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004614 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004615" 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 +00004616
4617 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004618" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004619 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004620 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004621
Bram Moolenaar85850f32019-07-19 22:05:51 +02004622 " repoint t:netrw_lexbufnr if appropriate
4623 if exists("repointlexbufnr")
4624 let t:netrw_lexbufnr= bufnr("%")
4625" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4626 endif
4627
Bram Moolenaar13600302014-05-22 18:26:40 +02004628 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004629" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4630 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004631 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004632
4633" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4634endfun
4635
4636" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004637" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4638fun! s:NetrwBannerCtrl(islocal)
4639" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4640
Bram Moolenaar97d62492012-11-15 21:28:22 +01004641 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004642 " toggle the banner (enable/suppress)
4643 let g:netrw_banner= !g:netrw_banner
4644
4645 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004646 let svpos= winsaveview()
4647" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004648 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4649
4650 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004651 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4652 let fname= s:NetrwGetWord()
4653 sil NetrwKeepj $
4654 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4655" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4656 if result <= 0 && exists("w:netrw_bannercnt")
4657 exe "NetrwKeepj ".w:netrw_bannercnt
4658 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004659 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004660 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004661" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4662endfun
4663
4664" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004665" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4666"
4667" No bang: enters files/directories into Netrw's bookmark system
4668" No argument and in netrw buffer:
4669" if there are marked files: bookmark marked files
4670" otherwise : bookmark file/directory under cursor
4671" No argument and not in netrw buffer: bookmarks current open file
4672" Has arguments: globs them individually and bookmarks them
4673"
4674" With bang: deletes files/directories from Netrw's bookmark system
4675fun! s:NetrwBookmark(del,...)
4676" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4677 if a:0 == 0
4678 if &ft == "netrw"
4679 let curbufnr = bufnr("%")
4680
4681 if exists("s:netrwmarkfilelist_{curbufnr}")
4682 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004683" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004684 let svpos = winsaveview()
4685" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004686 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004687 for fname in s:netrwmarkfilelist_{curbufnr}
4688 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4689 endfor
4690 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4691 call s:NetrwUnmarkList(curbufnr,curdir)
4692 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004693" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4694 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004695 else
4696 let fname= s:NetrwGetWord()
4697 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4698 endif
4699
4700 else
4701 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004702" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004703 let fname= expand("%")
4704 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4705 endif
4706
4707 else
4708 " bookmark specified files
4709 " attempts to infer if working remote or local
4710 " by deciding if the current file begins with an url
4711 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004712 let islocal= expand("%") !~ '^\a\{3,}://'
4713" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004714 let i = 1
4715 while i <= a:0
4716 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004717 if v:version > 704 || (v:version == 704 && has("patch656"))
4718 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004719 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004720 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004721 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004722 else
4723 let mbfiles= [a:{i}]
4724 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004725" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004726 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004727" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004728 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4729 endfor
4730 let i= i + 1
4731 endwhile
4732 endif
4733
4734 " update the menu
4735 call s:NetrwBookmarkMenu()
4736
4737" call Dret("s:NetrwBookmark")
4738endfun
4739
4740" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004741" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4742" .2.[cnt] for bookmarks, and
4743" .3.[cnt] for history
4744" (see s:NetrwMenu())
4745fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004746 if !exists("s:netrw_menucnt")
4747 return
4748 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004749" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004750
4751 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004752 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004753 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004754" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004755 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4756 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004757 endif
4758 if !exists("s:netrw_initbookhist")
4759 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004760 endif
4761
4762 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004763 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004764 let cnt= 1
4765 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004766" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004767 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004768
4769 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004770 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004771
4772 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004773 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 +01004774 let cnt= cnt + 1
4775 endfor
4776
4777 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004778
4779 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004780 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004781 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004782 let first = 1
4783 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004784 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004785 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004786 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004787 if exists("g:netrw_dirhist_{cnt}")
4788 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004789" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004790 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4791 endif
4792 let first = 0
4793 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4794 if cnt < 0
4795 let cnt= cnt + g:netrw_dirhistmax
4796 endif
4797 endwhile
4798 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004799
Bram Moolenaar9964e462007-05-05 17:54:07 +00004800 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004801" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004802endfun
4803
4804" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004805" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4806" directory and a new directory name. Also, if the
4807" "new directory name" is actually a file,
4808" NetrwBrowseChgDir() edits the file.
4809fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004810" 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 +01004811" 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 +00004812
Bram Moolenaar97d62492012-11-15 21:28:22 +01004813 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004814 if !exists("b:netrw_curdir")
4815 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4816 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004817 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004818" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4819" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004820" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004821" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004822 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004823 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004824" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004825
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004826 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004827" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004828 call s:SavePosn(s:netrw_posn)
4829 NetrwKeepj call s:NetrwOptionsSave("s:")
4830 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004831 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004832 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004833 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004834 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004835 endif
4836 let newdir = a:newdir
4837 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004838 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004839" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004840" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004841" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004842
4843 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004844" 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 +01004845 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004846" 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 +01004847 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004848 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004849" 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 +01004850 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004851" 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 +02004852 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004853 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004854 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004855 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004856" 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 +01004857 endif
4858 endif
4859" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004860" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004861 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004862
Bram Moolenaar446cb832008-06-24 21:56:24 +00004863 " set up o/s-dependent directory recognition pattern
4864 if has("amiga")
4865 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004866 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004867 let dirpat= '[\/]$'
4868 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004869" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870
4871 if dirname !~ dirpat
4872 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004873 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004874 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004875" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004876 endif
4877
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004878" 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 +01004879 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004880 " ------------------------------
4881 " NetrwBrowseChgDir: edit a file {{{3
4882 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004883" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004884
Bram Moolenaar97d62492012-11-15 21:28:22 +01004885 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004886 let s:rexposn_{bufnr("%")}= winsaveview()
4887" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004888" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4889" 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 +01004890
Bram Moolenaar446cb832008-06-24 21:56:24 +00004891 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004892" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4893" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004894" let newdir = s:NetrwTreePath(s:netrw_treetop)
4895" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004896 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004897 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4898" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4899 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004900 if dirname =~ '/$'
4901 let dirname= dirname.newdir
4902 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004903 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004904 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004905" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4906" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004907 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004908" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004909 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004910 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004911 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004912 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004913" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004914 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004915 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004916" 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 +02004917 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004918 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004919 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004920" " 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 +01004921 if type(g:netrw_browse_split) == 3
4922 " open file in server
4923 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004924" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004925 call s:NetrwServerEdit(a:islocal,dirname)
4926" call Dret("s:NetrwBrowseChgDir")
4927 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004928
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004929 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004930 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004931" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004932 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4933 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004934 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004935 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004936 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004937 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004938
Bram Moolenaar446cb832008-06-24 21:56:24 +00004939 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004940 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004941" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004942 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4943 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004944 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004945 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004946 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004947 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004948
Bram Moolenaar446cb832008-06-24 21:56:24 +00004949 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004950 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004951" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004952 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004953 if !exists("b:netrw_curdir")
4954 let b:netrw_curdir= getcwd()
4955 endif
4956 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004957
Bram Moolenaar446cb832008-06-24 21:56:24 +00004958 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004959 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004960" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004961 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004962 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004963" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004964 return
4965 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004966 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004967
Bram Moolenaar9964e462007-05-05 17:54:07 +00004968 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004969 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004970" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004971 call s:NetrwMenu(0)
4972 " optional change to window
4973 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004974" 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 +02004975 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004976 " if g:netrw_chgwin is set to one more than the last window, then
4977 " vertically split the last window to make that window available.
4978 let curwin= winnr()
4979 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4980 vs
4981 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004982 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004983 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004984 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004985 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004986 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004987
Bram Moolenaar9964e462007-05-05 17:54:07 +00004988 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004989
Bram Moolenaar446cb832008-06-24 21:56:24 +00004990 " the point where netrw actually edits the (local) file
4991 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004992 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004993 if !&mod
4994 " if e the new file would fail due to &mod, then don't change any of the flags
4995 let dolockout= 1
4996 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004997 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004998" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004999 " some like c-^ to return to the last edited file
5000 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005001 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5002 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005003 call s:NetrwEditFile("e","",dirname)
5004" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005005 " COMBAK -- cuc cul related
5006 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005007 if &hidden || &bufhidden == "hide"
5008 " file came from vim's hidden storage. Don't "restore" options with it.
5009 let dorestore= 0
5010 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005011 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005012" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005013 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005014
5015 " handle g:Netrw_funcref -- call external-to-netrw functions
5016 " This code will handle g:Netrw_funcref as an individual function reference
5017 " or as a list of function references. It will ignore anything that's not
5018 " a function reference. See :help Funcref for information about function references.
5019 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005020" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005021 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005022" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005023 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005024 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005025" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005026 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005027 if type(Fncref) == 2
5028 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005029 endif
5030 endfor
5031 endif
5032 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005033 endif
5034
5035 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005036 " ----------------------------------------------------
5037 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5038 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005039" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005040 let dirname = newdir
5041 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005042 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005043 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005044
5045 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005046 " ---------------------------------------------
5047 " NetrwBrowseChgDir: refresh the directory list {{{3
5048 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005049" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005050 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005051 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005052
5053 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005054 " --------------------------------------
5055 " NetrwBrowseChgDir: go up one directory {{{3
5056 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005057" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005058
5059 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5060 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005061" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5062" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005063 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005064 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005065 endif
5066
5067 if has("amiga")
5068 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005069" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005070 if a:islocal
5071 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5072 let dirname= substitute(dirname,'/$','','')
5073 else
5074 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5075 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005076" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005077
Nir Lichtman1e34b952024-05-08 19:19:34 +02005078 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005079 " windows
5080 if a:islocal
5081 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5082 if dirname == ""
5083 let dirname= '/'
5084 endif
5085 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005086 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005087 endif
5088 if dirname =~ '^\a:$'
5089 let dirname= dirname.'/'
5090 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005091" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005092
Bram Moolenaar446cb832008-06-24 21:56:24 +00005093 else
5094 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005095" 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 +00005096 if a:islocal
5097 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5098 if dirname == ""
5099 let dirname= '/'
5100 endif
5101 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005102 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005103 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005104" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005105 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005106 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005107 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005108
5109 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005110 " --------------------------------------
5111 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5112 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005113" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005114 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5115" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005116 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005117 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005118" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5119 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005120 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005121 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005122" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005123 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005124 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005125" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005126
5127 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005128" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005129 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005130" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005131 let haskey= 1
5132 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005133" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005134 endif
5135
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005136 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005137" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005138 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005139 if has_key(w:netrw_treedict,treedir."/")
5140 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005141" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005142 let haskey = 1
5143 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005144" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005145 endif
5146 endif
5147
5148 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005149" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005150 if !haskey && treedir =~ '/$'
5151 let treedir= substitute(treedir,'/$','','')
5152 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005153" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005154 let haskey = 1
5155 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005156" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005157 endif
5158 endif
5159
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005160" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005161 if haskey
5162 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005163" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005165" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5166" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005167 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005168 else
5169 " go down one directory
5170 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005171" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5172" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005173 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005174 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005175" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005176 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005177
5178 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005179 " ----------------------------------------
5180 " NetrwBrowseChgDir: Go down one directory {{{3
5181 " ----------------------------------------
5182 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005183" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005184 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005185 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005186 endif
5187
Bram Moolenaar97d62492012-11-15 21:28:22 +01005188 " --------------------------------------
5189 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5190 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005191 if dorestore
5192 " dorestore is zero'd when a local file was hidden or bufhidden;
5193 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005194" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005195 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005196" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005197" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005198 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005199 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005200" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005201 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005202" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5203" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005204 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005205" 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 +02005206 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005207" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5208" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005209 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005210" 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 +02005211 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005212 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005213 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005214 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005215
Bram Moolenaar446cb832008-06-24 21:56:24 +00005216" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5217 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005218endfun
5219
5220" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005221" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5222" for thin, long, and wide: cursor placed just after banner
5223" for tree, keeps cursor on current filename
5224fun! s:NetrwBrowseUpDir(islocal)
5225" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005226 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5227 " this test needed because occasionally this function seems to be incorrectly called
5228 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005229 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005230 " directories.
5231" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5232 return
5233 endif
5234
Bram Moolenaara6878372014-03-22 21:02:50 +01005235 norm! 0
5236 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005237" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005238 let curline= getline(".")
5239 let swwline= winline() - 1
5240 if exists("w:netrw_treetop")
5241 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005242 elseif exists("b:netrw_curdir")
5243 let w:netrw_treetop= b:netrw_curdir
5244 else
5245 let w:netrw_treetop= getcwd()
5246 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005247 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005248 let curfile = getline(".")
5249 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005250 if a:islocal
5251 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5252 else
5253 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5254 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005255" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5256" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5257 if w:netrw_treetop == '/'
5258 keepj call search('^\M'.curfile,"w")
5259 elseif curfile == '../'
5260 keepj call search('^\M'.curfile,"wb")
5261 else
5262" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5263 while 1
5264 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5265 let treepath= s:NetrwTreePath(w:netrw_treetop)
5266" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5267 if treepath == curpath
5268 break
5269 endif
5270 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005271 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005272
Bram Moolenaara6878372014-03-22 21:02:50 +01005273 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005274" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005275 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005276 if exists("b:netrw_curdir")
5277 let curdir= b:netrw_curdir
5278 else
5279 let curdir= expand(getcwd())
5280 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005281 if a:islocal
5282 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5283 else
5284 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5285 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005286 call s:RestorePosn(s:netrw_posn)
5287 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005288 let curdir= '\<'. escape(curdir, '~'). '/'
5289 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005290 endif
5291" call Dret("s:NetrwBrowseUpDir")
5292endfun
5293
5294" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005295" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005296" given filename; typically this means given their extension.
5297" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005298fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005299 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005300" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005301
Bram Moolenaar91359012019-11-30 17:57:03 +01005302 if a:remote == 0 && isdirectory(a:fname)
5303 " if its really just a local directory, then do a "gf" instead
5304" call Decho("remote≡0 and a:fname<".a:fname."> ".(isdirectory(a:fname)? "is a directory" : "is not a directory"),'~'.expand("<slnum>"))
Bram Moolenaar29634562020-01-09 21:46:04 +01005305" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5306 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005307" call Dret("netrw#BrowseX")
5308 return
5309 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5310 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5311" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5312" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5313" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5314" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5315 norm! gf
5316" call Dret("netrw#BrowseX")
5317 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005318 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005319" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005320
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005321 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5322 let remote = a:remote
5323 else
5324 let remote = 0
5325 endif
5326
Bram Moolenaar97d62492012-11-15 21:28:22 +01005327 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005328 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005329" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005330
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005331 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5332 let awkeep = &aw
5333 set noaw
5334
Bram Moolenaar5c736222010-01-06 20:54:52 +01005335 " special core dump handler
5336 if a:fname =~ '/core\(\.\d\+\)\=$'
5337 if exists("g:Netrw_corehandler")
5338 if type(g:Netrw_corehandler) == 2
5339 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005340" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005341 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005342 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005343 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005344" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005345 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005346 if type(Fncref) == 2
5347 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005348 endif
5349 endfor
5350 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005351" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005352 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005353 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005354 let &aw= awkeep
5355" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005356 return
5357 endif
5358 endif
5359
Bram Moolenaar446cb832008-06-24 21:56:24 +00005360 " set up the filename
5361 " (lower case the extension, make a local copy of a remote file)
5362 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005363 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005364 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005365 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005366 if exten =~ "[\\/]"
5367 let exten= ""
5368 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005369" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005370
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005371 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005372 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005373" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005374 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005375 call netrw#NetRead(3,a:fname)
5376 " attempt to rename tempfile
5377 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005378 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005379" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5380" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005381 if s:netrw_tmpfile != newname && newname != ""
5382 if rename(s:netrw_tmpfile,newname) == 0
5383 " renaming succeeded
5384" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5385 let fname= newname
5386 else
5387 " renaming failed
5388" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5389 let fname= s:netrw_tmpfile
5390 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005391 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005392 let fname= s:netrw_tmpfile
5393 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005394 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005395" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005396 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005397 " special ~ handler for local
5398 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005399" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5400 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005401 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005402 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005403" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5404" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005405
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005406 " set up redirection (avoids browser messages)
5407 " by default, g:netrw_suppress_gx_mesg is true
5408 if g:netrw_suppress_gx_mesg
5409 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005410 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005411 let redir= substitute(&srr,"%s","nul","")
5412 else
5413 let redir= substitute(&srr,"%s","/dev/null","")
5414 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005415 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005416 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005417 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005418 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005419 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005420 else
5421 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005422 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005423" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005424
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005425 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005426 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005427" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005428 if g:netrw_browsex_viewer =~ '\s'
5429 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5430 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5431 let oviewer = ''
5432 let cnt = 1
5433 while !executable(viewer) && viewer != oviewer
5434 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5435 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5436 let cnt = cnt + 1
5437 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005438" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005439 endwhile
5440 else
5441 let viewer = g:netrw_browsex_viewer
5442 let viewopt = ""
5443 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005444" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005445 endif
5446
5447 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005448" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005449 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005450" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005451 let ret= netrwFileHandlers#Invoke(exten,fname)
5452
5453 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005454" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005455 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005456 let ret= v:shell_error
5457
Nir Lichtman1e34b952024-05-08 19:19:34 +02005458 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005459" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005460 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005461 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005462 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005463 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005464 else
5465 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5466 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005467 let ret= v:shell_error
5468
Bram Moolenaar97d62492012-11-15 21:28:22 +01005469 elseif has("win32unix")
5470 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005471" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005472 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005473" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005474 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005475 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005476" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005477 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005478 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005479" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005480 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005481 else
5482 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5483 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005484 let ret= v:shell_error
5485
Bram Moolenaar85850f32019-07-19 22:05:51 +02005486 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005487" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5488 if a:fname =~ '^https\=://'
5489 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5490 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005491" call Decho("fname<".fname.">")
5492" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005493 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5494
5495 else
5496 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5497 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005498 let ret= v:shell_error
5499
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005500 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5501" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5502 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5503 let ret= v:shell_error
5504
5505 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5506" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5507 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5508 let ret= v:shell_error
5509
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005510 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005511" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005512 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005513 let ret= v:shell_error
5514
5515 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005516" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005517 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005518 let ret= v:shell_error
5519
5520 else
5521 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005522" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005523 let ret= netrwFileHandlers#Invoke(exten,fname)
5524 endif
5525
5526 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5527 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005528" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005529 let ret= netrwFileHandlers#Invoke(exten,fname)
5530 endif
5531
Bram Moolenaarc236c162008-07-13 17:41:49 +00005532 " restoring redraw! after external file handlers
5533 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005534
5535 " cleanup: remove temporary file,
5536 " delete current buffer if success with handler,
5537 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005538 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005539 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005540" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005541"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005542" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005543" endif
5544
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005545 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005546 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005547 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005548 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005549 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005550 if use_ctrlo
5551 exe "sil! NetrwKeepj norm! \<c-o>"
5552 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005553 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005554" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005555 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005556 let @@ = ykeep
5557 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005558
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005559" call Dret("netrw#BrowseX")
5560endfun
5561
5562" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005563" netrw#GX: gets word under cursor for gx support {{{2
5564" See also: netrw#BrowseXVis
5565" netrw#BrowseX
5566fun! netrw#GX()
5567" call Dfunc("netrw#GX()")
5568 if &ft == "netrw"
5569 let fname= s:NetrwGetWord()
5570 else
5571 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5572 endif
5573" call Dret("netrw#GX <".fname.">")
5574 return fname
5575endfun
5576
5577" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005578" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5579fun! netrw#BrowseXVis()
5580" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005581 let akeep = @a
5582 norm! gv"ay
5583 let gxfile= @a
5584 let @a = akeep
5585 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005586" call Dret("netrw#BrowseXVis")
5587endfun
5588
5589" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005590" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5591" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5592" to become an unlisted buffer, so in that case don't bwipe it.
5593fun! s:NetrwBufRename(newname)
5594" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5595" call Dredir("ls!","s:NetrwBufRename (before rename)")
5596 let oldbufname= bufname(bufnr("%"))
5597" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5598
5599 if oldbufname != a:newname
5600" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5601 let b:junk= 1
5602" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5603 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005604" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005605 let oldbufnr= bufnr(oldbufname)
5606" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5607" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5608 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5609" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5610 exe "bwipe! ".oldbufnr
5611" else " Decho
5612" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005613" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5614" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5615" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005616 endif
5617" call Dredir("ls!","s:NetrwBufRename (after rename)")
5618" else " Decho
5619" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5620 endif
5621
5622" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5623endfun
5624
5625" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005626" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005627fun! netrw#CheckIfRemote(...)
5628" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5629 if a:0 > 0
5630 let curfile= a:1
5631 else
5632 let curfile= expand("%")
5633 endif
5634" call Decho("curfile<".curfile.">")
5635 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005636" call Dret("netrw#CheckIfRemote 1")
5637 return 1
5638 else
5639" call Dret("netrw#CheckIfRemote 0")
5640 return 0
5641 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005642endfun
5643
5644" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005645" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5646fun! s:NetrwChgPerm(islocal,curdir)
5647" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005648 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005649 call inputsave()
5650 let newperm= input("Enter new permission: ")
5651 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005652 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5653 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5654" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005655 call system(chgperm)
5656 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005657 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005658 endif
5659 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005660 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005661 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005662 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005663" call Dret("s:NetrwChgPerm")
5664endfun
5665
5666" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005667" s:CheckIfKde: checks if kdeinit is running {{{2
5668" Returns 0: kdeinit not running
5669" 1: kdeinit is running
5670fun! s:CheckIfKde()
5671" call Dfunc("s:CheckIfKde()")
5672 " seems kde systems often have gnome-open due to dependencies, even though
5673 " gnome-open's subsidiary display tools are largely absent. Kde systems
5674 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5675 if !exists("s:haskdeinit")
5676 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005677 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005678 if v:shell_error
5679 let s:haskdeinit = 0
5680 endif
5681 else
5682 let s:haskdeinit= 0
5683 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005684" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005685 endif
5686
5687" call Dret("s:CheckIfKde ".s:haskdeinit)
5688 return s:haskdeinit
5689endfun
5690
5691" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005692" s:NetrwClearExplore: clear explore variables (if any) {{{2
5693fun! s:NetrwClearExplore()
5694" call Dfunc("s:NetrwClearExplore()")
5695 2match none
5696 if exists("s:explore_match") |unlet s:explore_match |endif
5697 if exists("s:explore_indx") |unlet s:explore_indx |endif
5698 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5699 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5700 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5701 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5702 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5703 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5704 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5705" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005706" call Dret("s:NetrwClearExplore")
5707endfun
5708
5709" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005710" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5711fun! s:NetrwEditBuf(bufnum)
5712" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5713 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5714" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5715 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5716 else
5717" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005718 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005719 endif
5720" call Dret("s:NetrwEditBuf")
5721endfun
5722
5723" ---------------------------------------------------------------------
5724" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5725" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5726fun! s:NetrwEditFile(cmd,opt,fname)
5727" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5728 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5729" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5730 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5731 else
5732" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5733 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5734 endif
5735" call Dret("s:NetrwEditFile")
5736endfun
5737
5738" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005739" s:NetrwExploreListUniq: {{{2
5740fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005741" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005742
5743 " this assumes that the list is already sorted
5744 let newexplist= []
5745 for member in a:explist
5746 if !exists("uniqmember") || member != uniqmember
5747 let uniqmember = member
5748 let newexplist = newexplist + [ member ]
5749 endif
5750 endfor
5751
Bram Moolenaar15146672011-10-20 22:22:38 +02005752" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005753 return newexplist
5754endfun
5755
5756" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005757" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5758fun! s:NetrwForceChgDir(islocal,newdir)
5759" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005760 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005761 if a:newdir !~ '/$'
5762 " ok, looks like force is needed to get directory-style treatment
5763 if a:newdir =~ '@$'
5764 let newdir= substitute(a:newdir,'@$','/','')
5765 elseif a:newdir =~ '[*=|\\]$'
5766 let newdir= substitute(a:newdir,'.$','/','')
5767 else
5768 let newdir= a:newdir.'/'
5769 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005770" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005771 else
5772 " should already be getting treatment as a directory
5773 let newdir= a:newdir
5774 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005775 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005776 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005777 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005778" call Dret("s:NetrwForceChgDir")
5779endfun
5780
5781" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005782" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005783" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5784" expr : this is the expression to follow the directory. Will use s:ComposePath()
5785" pare =1: remove the current directory from the resulting glob() filelist
5786" =0: leave the current directory in the resulting glob() filelist
5787fun! s:NetrwGlob(direntry,expr,pare)
5788" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005789 if netrw#CheckIfRemote()
5790 keepalt 1sp
5791 keepalt enew
5792 let keep_liststyle = w:netrw_liststyle
5793 let w:netrw_liststyle = s:THINLIST
5794 if s:NetrwRemoteListing() == 0
5795 keepj keepalt %s@/@@
5796 let filelist= getline(1,$)
5797 q!
5798 else
5799 " remote listing error -- leave treedict unchanged
5800 let filelist= w:netrw_treedict[a:direntry]
5801 endif
5802 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005803 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5804 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5805 if a:pare
5806 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5807 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005808 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005809 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5810 if a:pare
5811 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5812 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005813 endif
5814" call Dret("s:NetrwGlob ".string(filelist))
5815 return filelist
5816endfun
5817
5818" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005819" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5820fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005821" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005822 if a:newfile =~ '[/@*=|\\]$'
5823 let newfile= substitute(a:newfile,'.$','','')
5824 else
5825 let newfile= a:newfile
5826 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005827 if a:islocal
5828 call s:NetrwBrowseChgDir(a:islocal,newfile)
5829 else
5830 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5831 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005832" call Dret("s:NetrwForceFile")
5833endfun
5834
5835" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005836" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5837" and switches the hiding mode. The actual hiding is done by
5838" s:NetrwListHide().
5839" g:netrw_hide= 0: show all
5840" 1: show not-hidden files
5841" 2: show hidden files only
5842fun! s:NetrwHide(islocal)
5843" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005844 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005845 let svpos= winsaveview()
5846" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005847
5848 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005849" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5850" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005851
5852 " hide the files in the markfile list
5853 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005854" 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 +00005855 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5856 " remove fname from hiding list
5857 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5858 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5859 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005860" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005861 else
5862 " append fname to hiding list
5863 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5864 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5865 else
5866 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5867 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005868" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005869 endif
5870 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005871 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005872 let g:netrw_hide= 1
5873
5874 else
5875
5876 " switch between show-all/show-not-hidden/show-hidden
5877 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005878 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005879 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005880 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005881 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005882" call Dret("NetrwHide")
5883 return
5884 endif
5885 endif
5886
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005887 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005888" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5889 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005890 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005891" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005892endfun
5893
5894" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005895" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5896fun! s:NetrwHideEdit(islocal)
5897" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5898
5899 let ykeep= @@
5900 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005901 let svpos= winsaveview()
5902" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005903
5904 " get new hiding list from user
5905 call inputsave()
5906 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5907 call inputrestore()
5908 let g:netrw_list_hide= newhide
5909" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5910
5911 " refresh the listing
5912 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5913
5914 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005915" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5916 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005917 let @@= ykeep
5918
5919" call Dret("NetrwHideEdit")
5920endfun
5921
5922" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005923" s:NetrwHidden: invoked by "gh" {{{2
5924fun! s:NetrwHidden(islocal)
5925" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005926 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005927 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005928 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005929" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005930
5931 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005932 " remove .file pattern from hiding list
5933" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005934 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005935 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005936" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005937 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5938 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005939" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005940 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5941 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005942 if g:netrw_list_hide =~ '^,'
5943 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5944 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005945
5946 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005947 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005948" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5949 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005950 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005951" call Dret("s:NetrwHidden")
5952endfun
5953
5954" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005955" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5956fun! s:NetrwHome()
5957 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005958 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005959 else
5960 " go to vim plugin home
5961 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005962 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005963 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005964 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005965 let home= basehome."/.vim"
5966 break
5967 endif
5968 endfor
5969 if home == ""
5970 " just pick the first directory
5971 let home= substitute(&rtp,',.*$','','')
5972 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005973 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005974 let home= substitute(home,'/','\\','g')
5975 endif
5976 endif
5977 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005978 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005979" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005980 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005981" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005982 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005983 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005984" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005985 call mkdir(home)
5986 endif
5987 endif
5988 let g:netrw_home= home
5989 return home
5990endfun
5991
5992" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005993" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5994fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005995 if exists("s:netrwdrag")
5996 return
5997 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005998 if &ft != "netrw"
5999 return
6000 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006001" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006002
Bram Moolenaar97d62492012-11-15 21:28:22 +01006003 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006004 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006005 while getchar(0) != 0
6006 "clear the input stream
6007 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006008 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006009 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006010 let mouse_lnum = v:mouse_lnum
6011 let wlastline = line('w$')
6012 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006013" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6014" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006015 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6016 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006017 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006018" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6019 return
6020 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006021 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006022 " 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 +01006023 " without this test when its disabled.
6024 " 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 +01006025" 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 +01006026 if v:mouse_col > virtcol('.')
6027 let @@= ykeep
6028" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6029 return
6030 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006031
Bram Moolenaar446cb832008-06-24 21:56:24 +00006032 if a:islocal
6033 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006034 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006035 endif
6036 else
6037 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006038 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006039 endif
6040 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006041 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006042" call Dret("s:NetrwLeftmouse")
6043endfun
6044
6045" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006046" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6047fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006048 if &ft != "netrw"
6049 return
6050 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006051" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6052 call s:NetrwMarkFileTgt(a:islocal)
6053" call Dret("s:NetrwCLeftmouse")
6054endfun
6055
6056" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006057" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6058" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006059" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006060" a:islocal=2 : <c-r> used, remote
6061" a:islocal=3 : <c-r> used, local
6062fun! s:NetrwServerEdit(islocal,fname)
6063" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6064 let islocal = a:islocal%2 " =0: remote =1: local
6065 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006066" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006067
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006068 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006069 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006070 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006071" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006072 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006073 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006074 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6075 unlet s:netrw_browse_split_{winnr()}
6076 endif
6077 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6078" call Dret("s:NetrwServerEdit")
6079 return
6080 endif
6081
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006082" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006083 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006084" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006085
6086 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006087" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006088 let srvrname = g:netrw_browse_split[0]
6089 let tabnum = g:netrw_browse_split[1]
6090 let winnum = g:netrw_browse_split[2]
6091
6092 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006093" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006094
6095 if !ctrlr
6096 " user must have closed the server window and the user did not use <c-r>, but
6097 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006098" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006099 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006100 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006101 endif
6102 let g:netrw_browse_split= 0
6103 if exists("s:netrw_browse_split_".winnr())
6104 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6105 endif
6106 call s:NetrwBrowseChgDir(islocal,a:fname)
6107" call Dret("s:NetrwServerEdit")
6108 return
6109
6110 elseif has("win32") && executable("start")
6111 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006112" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006113 call system("start gvim --servername ".srvrname)
6114
6115 else
6116 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006117" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006118 call system("gvim --servername ".srvrname)
6119 endif
6120 endif
6121
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006122" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006123 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6124 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006125 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006126
6127 else
6128
6129 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6130
6131 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006132" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006133 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006134 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006135 endif
6136 let g:netrw_browse_split= 0
6137 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6138" call Dret("s:NetrwServerEdit")
6139 return
6140
6141 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006142" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006143 if has("win32") && executable("start")
6144 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006145" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006146 call system("start gvim --servername ".g:netrw_servername)
6147 else
6148 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006149" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006150 call system("gvim --servername ".g:netrw_servername)
6151 endif
6152 endif
6153 endif
6154
6155 while 1
6156 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006157" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6158 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006159 break
6160 catch /^Vim\%((\a\+)\)\=:E241/
6161 sleep 200m
6162 endtry
6163 endwhile
6164
6165 if exists("g:netrw_browse_split")
6166 if type(g:netrw_browse_split) != 3
6167 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6168 endif
6169 unlet g:netrw_browse_split
6170 endif
6171 let g:netrw_browse_split= [g:netrw_servername,1,1]
6172 endif
6173
6174 else
6175 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6176 endif
6177
6178" call Dret("s:NetrwServerEdit")
6179endfun
6180
6181" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006182" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6183fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006184 if &ft != "netrw"
6185 return
6186 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006187" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006188
Bram Moolenaar8d043172014-01-23 14:24:41 +01006189 let s:ngw= s:NetrwGetWord()
6190 call s:NetrwMarkFile(a:islocal,s:ngw)
6191
6192" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006193endfun
6194
6195" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006196" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6197" Used to mark multiple files.
6198fun! s:NetrwSLeftdrag(islocal)
6199" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6200 if !exists("s:netrwdrag")
6201 let s:netrwdrag = winnr()
6202 if a:islocal
6203 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006204 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006205 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006206 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006207 endif
6208 let ngw = s:NetrwGetWord()
6209 if !exists("s:ngw") || s:ngw != ngw
6210 call s:NetrwMarkFile(a:islocal,ngw)
6211 endif
6212 let s:ngw= ngw
6213" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6214endfun
6215
6216" ---------------------------------------------------------------------
6217" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6218fun! s:NetrwSLeftrelease(islocal)
6219" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6220 if exists("s:netrwdrag")
6221 nunmap <s-leftrelease>
6222 let ngw = s:NetrwGetWord()
6223 if !exists("s:ngw") || s:ngw != ngw
6224 call s:NetrwMarkFile(a:islocal,ngw)
6225 endif
6226 if exists("s:ngw")
6227 unlet s:ngw
6228 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006229 unlet s:netrwdrag
6230 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006231" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006232endfun
6233
6234" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006235" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6236" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006237fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006238" 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 +02006239" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006240 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006241
6242 " 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 +02006243 " How-it-works: take the hiding command, convert it into a range.
6244 " Duplicate characters don't matter.
6245 " Remove all such characters from the '/~@#...890' string.
6246 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006247" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006248 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006249 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006250" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006251
6252 while listhide != ""
6253 if listhide =~ ','
6254 let hide = substitute(listhide,',.*$','','e')
6255 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6256 else
6257 let hide = listhide
6258 let listhide = ""
6259 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006260" 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 +01006261 if g:netrw_sort_by =~ '^[ts]'
6262 if hide =~ '^\^'
6263" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6264 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6265 elseif hide =~ '^\\(\^'
6266 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6267 endif
6268" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6269 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006270
6271 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006272" 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 +00006273 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006274" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006275 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006276 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006277" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006278 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006279 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006280" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006281 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006282
Bram Moolenaar446cb832008-06-24 21:56:24 +00006283 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006284 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006285" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006286 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006287" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006288 endif
6289
Bram Moolenaaradc21822011-04-01 18:03:16 +02006290 " remove any blank lines that have somehow remained.
6291 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006292 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006293
Bram Moolenaar97d62492012-11-15 21:28:22 +01006294 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006295" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006296endfun
6297
6298" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006299" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006300" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006301fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006302" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006303
Bram Moolenaar97d62492012-11-15 21:28:22 +01006304 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006305 " get name of new directory from user. A bare <CR> will skip.
6306 " if its currently a directory, also request will be skipped, but with
6307 " a message.
6308 call inputsave()
6309 let newdirname= input("Please give directory name: ")
6310 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006311" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006312
6313 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006314 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006315" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006316 return
6317 endif
6318
6319 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006320" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006321
6322 " Local mkdir:
6323 " sanity checks
6324 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006325" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6326 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006327 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006328 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006329 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006330 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006331" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006332 return
6333 endif
6334 if s:FileReadable(fullnewdir)
6335 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006336 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006337 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006338 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006339" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006340 return
6341 endif
6342
6343 " requested new local directory is neither a pre-existing file or
6344 " directory, so make it!
6345 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006346 if has("unix")
6347 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6348 else
6349 call mkdir(fullnewdir,"p")
6350 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006351 else
6352 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006353 if s:NetrwLcd(b:netrw_curdir)
6354" call Dret("s:NetrwMakeDir : lcd failure")
6355 return
6356 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006357" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006358 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006359 if v:shell_error != 0
6360 let @@= ykeep
6361 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 +01006362" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006363 return
6364 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006365 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006366" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006367 if s:NetrwLcd(netrw_origdir)
6368" call Dret("s:NetrwBrowse : lcd failure")
6369 return
6370 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006371 endif
6372 endif
6373
6374 if v:shell_error == 0
6375 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006376" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006377 let svpos= winsaveview()
6378" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006379 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006380" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6381 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006382 elseif !exists("g:netrw_quiet")
6383 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6384 endif
6385" redraw!
6386
6387 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006388 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006389" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006390 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6391 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006392 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006393 if v:shell_error == 0
6394 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006395 let svpos= winsaveview()
6396" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006397 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006398" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6399 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006400 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006401 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006402 endif
6403" redraw!
6404
6405 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006406 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006407 let svpos= winsaveview()
6408" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006409" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006410 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006411" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006412 let remotepath= b:netrw_fname
6413 else
6414 let remotepath= ""
6415 endif
6416 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006417 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006418" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6419 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006420
Bram Moolenaar446cb832008-06-24 21:56:24 +00006421 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006422 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006423 let svpos= winsaveview()
6424" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006426 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006427" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006428 let remotepath= b:netrw_fname
6429 else
6430 let remotepath= ""
6431 endif
6432 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006433 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006434" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6435 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006436 endif
6437
Bram Moolenaar97d62492012-11-15 21:28:22 +01006438 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006439" call Dret("s:NetrwMakeDir")
6440endfun
6441
6442" ---------------------------------------------------------------------
6443" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6444fun! s:TreeSqueezeDir(islocal)
6445" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6446 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6447 " its a tree-listing style
6448 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006449 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006450 let depth = strchars(substitute(curdepth,' ','','g'))
6451 let srch = -1
6452" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6453" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006454" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006455" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6456 if depth >= 2
6457 NetrwKeepj norm! 0
6458 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6459 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6460" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6461" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6462 elseif depth == 1
6463 NetrwKeepj norm! 0
6464 let treedepthchr= substitute(s:treedepthstring,' ','','')
6465 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6466" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6467 endif
6468 if srch > 0
6469" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6470 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6471 exe srch
6472 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006473 endif
6474" call Dret("s:TreeSqueezeDir")
6475endfun
6476
6477" ---------------------------------------------------------------------
6478" s:NetrwMaps: {{{2
6479fun! s:NetrwMaps(islocal)
6480" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6481
Bram Moolenaar85850f32019-07-19 22:05:51 +02006482 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006483 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006484" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006485 if !hasmapto("<Plug>NetrwReturn")
6486 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006487" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006488 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6489 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006490" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006491 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6492 endif
6493 endif
6494 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006495" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006496 endif
6497
Bram Moolenaar85850f32019-07-19 22:05:51 +02006498 " generate default <Plug> maps {{{3
6499 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006500 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006501 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6502 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6503 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6504 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6505 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6506 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6507 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6508 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6509 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6510 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6511" ---------------------------------------------------------------------
6512" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6513" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6514" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6515" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6516" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6517" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6518" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6519" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6520" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6521" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6522" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6523" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6524" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6525" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6526" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6527" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6528" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6529" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6530" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6531" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6532" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6533" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6534" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6535" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6536" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6537" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6538" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6539" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6540" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6541" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6542" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6543" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6544" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6545" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6546" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6547" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6548" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6549" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6550" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6551" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6552" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6553" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6554" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6555" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6556" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6557" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6558" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6559
Bram Moolenaara6878372014-03-22 21:02:50 +01006560 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006561" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006562 " local normal-mode maps {{{3
6563 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6564 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6565 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6566 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6567 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6568 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6569 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6570 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6571 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6572 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6573 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6574" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006575 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6576 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6577 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006578 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006579 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006580 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6581 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6582 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6583 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006584 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6585 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6586 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6587 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6588 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6589 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6590 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6591 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6592 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6593 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6594 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6595 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6596 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006597 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006598 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006599 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6600 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6601 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6602 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6603 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006604 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006605 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006606 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6607 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006608 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6609 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6610 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006611 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006612 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006613 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6614 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006615 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006616 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006617 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6618 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6619 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006620 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6621 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006622
6623 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 +01006624 if !hasmapto('<Plug>NetrwHideEdit')
6625 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006626 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006627 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006628 if !hasmapto('<Plug>NetrwRefresh')
6629 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006630 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006631 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 +01006632 if s:didstarstar || !mapcheck("<s-down>","n")
6633 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006634 endif
6635 if s:didstarstar || !mapcheck("<s-up>","n")
6636 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006637 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006638 if !hasmapto('<Plug>NetrwTreeSqueeze')
6639 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006640 endif
6641 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006642 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6643 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006644 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6645 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6646 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6647 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6648 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6649 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6650 imap <buffer> <leftmouse> <Plug>ILeftmouse
6651 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006652 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6653 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6654 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6655 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6656 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006657 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006658 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6659 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006660 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006661 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6662 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6663 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6664 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6665 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6666 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6667 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006668 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6669
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006670 " support user-specified maps
6671 call netrw#UserMaps(1)
6672
Bram Moolenaar85850f32019-07-19 22:05:51 +02006673 else
6674 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006675" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006676 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006677 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6678 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6679 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6680 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6681 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6682 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6683 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6684 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6685 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6686 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6687 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6688" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006689 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6690 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6691 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6692 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6693 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6694 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6695 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6696 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006697 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006698 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006699 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6700 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6701 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6702 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6703 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6704 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6705 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6706 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6707 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6708 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6709 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006710 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006711 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006712 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6713 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6714 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6715 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6716 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006717 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6718 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6719 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6720 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006721 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006722 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6723 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006724 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006725 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 +01006726 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6727 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6728 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6729 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6730 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6731 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6732 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6733 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6734 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006735 if !hasmapto('<Plug>NetrwHideEdit')
6736 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006737 endif
6738 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6739 if !hasmapto('<Plug>NetrwRefresh')
6740 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006741 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006742 if !hasmapto('<Plug>NetrwTreeSqueeze')
6743 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006744 endif
6745 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006746
6747 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006748 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006749
6750 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6751 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006752 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006753 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006754 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006755 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006756 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006757 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006758 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006759 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006760 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006761 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006762 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6763 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6764 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006765 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006766 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006767 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6768 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006769 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006770 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6771 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6772 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6773 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6774 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6775 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6776 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006777 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006778
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006779 " support user-specified maps
6780 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006781 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006782
6783" call Dret("s:NetrwMaps")
6784endfun
6785
6786" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006787" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006788" If -buffer, the command is only available from within netrw buffers
6789" Otherwise, the command is available from any window, so long as netrw
6790" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006791fun! s:NetrwCommands(islocal)
6792" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6793
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006794 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6795 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006796 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 +01006797 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006798 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006799 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006800 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006801 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006802 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006803
6804" call Dret("s:NetrwCommands")
6805endfun
6806
6807" ---------------------------------------------------------------------
6808" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6809" glob()ing only works with local files
6810fun! s:NetrwMarkFiles(islocal,...)
6811" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006812 let curdir = s:NetrwGetCurdir(a:islocal)
6813 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006814 while i <= a:0
6815 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006816 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006817 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006818 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006819 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006820 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006821 else
6822 let mffiles= [a:{i}]
6823 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006824" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006825 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006826" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006827 call s:NetrwMarkFile(a:islocal,mffile)
6828 endfor
6829 let i= i + 1
6830 endwhile
6831" call Dret("s:NetrwMarkFiles")
6832endfun
6833
6834" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006835" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006836fun! s:NetrwMarkTarget(...)
6837" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6838 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006839 let curdir = s:NetrwGetCurdir(1)
6840 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006841 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006842 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6843 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006844 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006846 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006847 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6848 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006849 let svpos = winsaveview()
6850" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006851 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006852" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6853 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006854" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006855endfun
6856
6857" ---------------------------------------------------------------------
6858" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6859" mark and unmark files. If a markfile list exists,
6860" then the rename and delete functions will use it instead
6861" of whatever may happen to be under the cursor at that
6862" moment. When the mouse and gui are available,
6863" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006864"
6865" Creates two lists
6866" s:netrwmarkfilelist -- holds complete paths to all marked files
6867" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6868"
6869" Creates a marked file match string
6870" s:netrwmarfilemtch_# -- used with 2match to display marked files
6871"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006872" Creates a buffer version of islocal
6873" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006874fun! s:NetrwMarkFile(islocal,fname)
6875" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006876" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006877
6878 " sanity check
6879 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006880" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006881 return
6882 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006883 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006884
Bram Moolenaar97d62492012-11-15 21:28:22 +01006885 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006886 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006887 if a:fname =~ '^\a'
6888 let leader= '\<'
6889 else
6890 let leader= ''
6891 endif
6892 if a:fname =~ '\a$'
6893 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6894 else
6895 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6896 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006897
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006898 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006899 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006900" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6901" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6902" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006903 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006904
6905 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006906 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006907" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006908 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006909 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006910
6911 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006912 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006913" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006914 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6915 if s:netrwmarkfilelist_{curbufnr} == []
6916 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006917" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006918 call s:NetrwUnmarkList(curbufnr,curdir)
6919 else
6920 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006921" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006922 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006923 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006924 for fname in s:netrwmarkfilelist_{curbufnr}
6925 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006926 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006928 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006929 endif
6930 let first= 0
6931 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006932" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006933 endif
6934 endif
6935
6936 else
6937 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006938" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006939
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006940" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006941 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006942 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6943" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006944
6945 " build initial markfile matching pattern
6946 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006947 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006948 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006949 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006950 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006951" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952 endif
6953
6954 " handle global markfilelist
6955 if exists("s:netrwmarkfilelist")
6956 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6957 if index(s:netrwmarkfilelist,dname) == -1
6958 " append new filename to global markfilelist
6959 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006960" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006961 else
6962 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006963" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6964" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006966" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006967 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006968" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969 unlet s:netrwmarkfilelist
6970 endif
6971 endif
6972 else
6973 " initialize new global-directory markfilelist
6974 let s:netrwmarkfilelist= []
6975 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006976" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006977 endif
6978
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006979 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006980 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6981 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6982" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6983 if exists("g:did_drchip_netrwlist_syntax")
6984 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6985 endif
6986 else
6987" " call Decho("2match none",'~'.expand("<slnum>"))
6988 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006989 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006990 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006991 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006992" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6993" 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 +00006994endfun
6995
6996" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006997" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6998" mA: move the argument list to marked file list (tomflist=1)
6999" Uses the global marked file list
7000fun! s:NetrwMarkFileArgList(islocal,tomflist)
7001" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7002
7003 let svpos = winsaveview()
7004" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7005 let curdir = s:NetrwGetCurdir(a:islocal)
7006 let curbufnr = bufnr("%")
7007
7008 if a:tomflist
7009 " mA: move argument list to marked file list
7010 while argc()
7011 let fname= argv(0)
7012" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7013 exe "argdel ".fnameescape(fname)
7014 call s:NetrwMarkFile(a:islocal,fname)
7015 endwhile
7016
7017 else
7018 " ma: move marked file list to argument list
7019 if exists("s:netrwmarkfilelist")
7020
7021 " for every filename in the marked list
7022 for fname in s:netrwmarkfilelist
7023" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7024 exe "argadd ".fnameescape(fname)
7025 endfor " for every file in the marked list
7026
7027 " unmark list and refresh
7028 call s:NetrwUnmarkList(curbufnr,curdir)
7029 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7030" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7031 NetrwKeepj call winrestview(svpos)
7032 endif
7033 endif
7034
7035" call Dret("s:NetrwMarkFileArgList")
7036endfun
7037
7038" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007039" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7040" compress/decompress files using the programs
7041" in g:netrw_compress and g:netrw_uncompress,
7042" using g:netrw_compress_suffix to know which to
7043" do. By default:
7044" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007045" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007046fun! s:NetrwMarkFileCompress(islocal)
7047" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007048 let svpos = winsaveview()
7049" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007050 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007051 let curbufnr = bufnr("%")
7052
Bram Moolenaarff034192013-04-24 18:51:19 +02007053 " sanity check
7054 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007055 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007056" call Dret("s:NetrwMarkFileCompress")
7057 return
7058 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007059" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007060
Bram Moolenaar446cb832008-06-24 21:56:24 +00007061 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007062
7063 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007064 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007065 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007066" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007067 if exists("g:netrw_decompress['".sfx."']")
7068 " fname has a suffix indicating that its compressed; apply associated decompression routine
7069 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007070" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007071 let exe= netrw#WinPath(exe)
7072 if a:islocal
7073 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007074 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007075 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007076 call system(exe." ".fname)
7077 if v:shell_error
7078 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007079 endif
7080 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007081 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7082 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007083 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007084
Bram Moolenaarff034192013-04-24 18:51:19 +02007085 endif
7086 unlet sfx
7087
Bram Moolenaar446cb832008-06-24 21:56:24 +00007088 if exists("exe")
7089 unlet exe
7090 elseif a:islocal
7091 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007092 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007093 if v:shell_error
7094 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7095 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007096 else
7097 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007098 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007099 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007100 endfor " for every file in the marked list
7101
Bram Moolenaar446cb832008-06-24 21:56:24 +00007102 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007103 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007104" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7105 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007106 endif
7107" call Dret("s:NetrwMarkFileCompress")
7108endfun
7109
7110" ---------------------------------------------------------------------
7111" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7112" If no marked files, then set up directory as the
7113" target. Currently does not support copying entire
7114" directories. Uses the local-buffer marked file list.
7115" Returns 1=success (used by NetrwMarkFileMove())
7116" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007117fun! s:NetrwMarkFileCopy(islocal,...)
7118" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7119
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007120 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007121 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007122 if b:netrw_curdir !~ '/$'
7123 if !exists("b:netrw_curdir")
7124 let b:netrw_curdir= curdir
7125 endif
7126 let b:netrw_curdir= b:netrw_curdir."/"
7127 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007128
Bram Moolenaarff034192013-04-24 18:51:19 +02007129 " sanity check
7130 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007131 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007132" call Dret("s:NetrwMarkFileCopy")
7133 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007134 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007135" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007136
Bram Moolenaar446cb832008-06-24 21:56:24 +00007137 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007138 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007139" call Dret("s:NetrwMarkFileCopy 0")
7140 return 0
7141 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007142" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007143
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007144 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007145 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007146" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007147 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007148 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7149" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7150 return
7151 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007152
7153 " copy marked files while within the same directory (ie. allow renaming)
7154 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7155 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7156 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007157" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007158 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007159 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7160 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007161" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007162 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007163 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007164 let oldname = a:1
7165 else
7166 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007167" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007168 let s:recursive= 1
7169 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7170 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7171 if ret == 0
7172 break
7173 endif
7174 endfor
7175 unlet s:recursive
7176 call s:NetrwUnmarkList(curbufnr,curdir)
7177" call Dret("s:NetrwMarkFileCopy ".ret)
7178 return ret
7179 endif
7180
7181 call inputsave()
7182 let newname= input("Copy ".oldname." to : ",oldname,"file")
7183 call inputrestore()
7184 if newname == ""
7185" call Dret("s:NetrwMarkFileCopy 0")
7186 return 0
7187 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007188 let args= s:ShellEscape(oldname)
7189 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007190 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007191 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7192 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007193 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007194 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007195 let args= substitute(args,'/','\\','g')
7196 let tgt = substitute(tgt, '/','\\','g')
7197 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007198 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7199 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7200 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7201 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7202" call Decho("args <".args.">",'~'.expand("<slnum>"))
7203" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007204 if isdirectory(s:NetrwFile(args))
7205" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007206 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007207" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007208 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007209 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7210 " contents to a target. One must append the source directory name to the target to get xcopy to
7211 " do the right thing.
7212 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007213" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007214 endif
7215 else
7216 let copycmd= g:netrw_localcopycmd
7217 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007218 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007219 let copycmd = substitute(copycmd,'\s.*$','','')
7220 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007221 let copycmd = netrw#WinPath(copycmd).copycmdargs
7222 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007223 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007224 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007225" call Decho("args <".args.">",'~'.expand("<slnum>"))
7226" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7227" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7228" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007229 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007230 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007231 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007232 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 +01007233 else
7234 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7235 endif
7236" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007237 return 0
7238 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007239
7240 elseif a:islocal && !s:netrwmftgt_islocal
7241 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007242" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007243 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007244
7245 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007246 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007247" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007248 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007249
7250 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007251 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007252" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007253 let curdir = getcwd()
7254 let tmpdir = s:GetTempfile("")
7255 if tmpdir !~ '/'
7256 let tmpdir= curdir."/".tmpdir
7257 endif
7258 if exists("*mkdir")
7259 call mkdir(tmpdir)
7260 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007261 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007262 if v:shell_error != 0
7263 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 +01007264" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007265 return
7266 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007267 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007268 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007269 if s:NetrwLcd(tmpdir)
7270" call Dret("s:NetrwMarkFileCopy : lcd failure")
7271 return
7272 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007273 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007274 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007275 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007276 if getcwd() == tmpdir
7277 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007278 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007280 if s:NetrwLcd(curdir)
7281" call Dret("s:NetrwMarkFileCopy : lcd failure")
7282 return
7283 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007284 if delete(tmpdir,"d")
7285 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007286 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007287 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007288 if s:NetrwLcd(curdir)
7289" call Dret("s:NetrwMarkFileCopy : lcd failure")
7290 return
7291 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007292 endif
7293 endif
7294 endif
7295
7296 " -------
7297 " cleanup
7298 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007299" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007300 " remove markings from local buffer
7301 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007302" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7303" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7304" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7305" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7306" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7307" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7308 if exists("s:recursive")
7309" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7310 else
7311" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007312 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007313 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007314 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007315 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007316 else
7317 " refresh local and targets for fast browsing
7318 if !exists("s:recursive")
7319 " remove markings from local buffer
7320" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7321 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7322 endif
7323
7324 " refresh buffers
7325 if s:netrwmftgt_islocal
7326" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7327 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7328 endif
7329 if a:islocal && s:netrwmftgt != curdir
7330" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7331 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7332 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007333 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007334
Bram Moolenaar446cb832008-06-24 21:56:24 +00007335" call Dret("s:NetrwMarkFileCopy 1")
7336 return 1
7337endfun
7338
7339" ---------------------------------------------------------------------
7340" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7341" invoke vim's diff mode on the marked files.
7342" Either two or three files can be so handled.
7343" Uses the global marked file list.
7344fun! s:NetrwMarkFileDiff(islocal)
7345" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7346 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007347
Bram Moolenaarff034192013-04-24 18:51:19 +02007348 " sanity check
7349 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007350 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007351" call Dret("s:NetrwMarkFileDiff")
7352 return
7353 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007354 let curdir= s:NetrwGetCurdir(a:islocal)
7355" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007356
Bram Moolenaara6878372014-03-22 21:02:50 +01007357 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007358 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007359 for fname in s:netrwmarkfilelist
7360 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007362" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007363 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007364 diffthis
7365 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007366 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007367" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007368 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007369 diffthis
7370 else
7371 break
7372 endif
7373 endfor
7374 call s:NetrwUnmarkList(curbufnr,curdir)
7375 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007376
Bram Moolenaar446cb832008-06-24 21:56:24 +00007377" call Dret("s:NetrwMarkFileDiff")
7378endfun
7379
7380" ---------------------------------------------------------------------
7381" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7382" Uses global markfilelist
7383fun! s:NetrwMarkFileEdit(islocal)
7384" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7385
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007386 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007387 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007388
7389 " sanity check
7390 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007391 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007392" call Dret("s:NetrwMarkFileEdit")
7393 return
7394 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007395" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007396
Bram Moolenaar446cb832008-06-24 21:56:24 +00007397 if exists("s:netrwmarkfilelist_{curbufnr}")
7398 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007399 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400 " unmark markedfile list
7401" call s:NetrwUnmarkList(curbufnr,curdir)
7402 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007403" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007404 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007405 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007406 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007407
Bram Moolenaar446cb832008-06-24 21:56:24 +00007408" call Dret("s:NetrwMarkFileEdit")
7409endfun
7410
7411" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007412" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007413fun! s:NetrwMarkFileQFEL(islocal,qfel)
7414" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7415 call s:NetrwUnmarkAll()
7416 let curbufnr= bufnr("%")
7417
7418 if !empty(a:qfel)
7419 for entry in a:qfel
7420 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007421" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007422 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007423" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007424 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7425 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7426 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7427 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007428" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007429 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7430 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007431" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007432 endif
7433 endfor
7434 echo "(use me to edit marked files)"
7435 else
7436 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7437 endif
7438
7439" call Dret("s:NetrwMarkFileQFEL")
7440endfun
7441
7442" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007443" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7444" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7445" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7446fun! s:NetrwMarkFileExe(islocal,enbloc)
7447" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007448 let svpos = winsaveview()
7449" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007450 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007451 let curbufnr = bufnr("%")
7452
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007453 if a:enbloc == 0
7454 " individually apply command to files, one at a time
7455 " sanity check
7456 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7457 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7458" call Dret("s:NetrwMarkFileExe")
7459 return
7460 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007461" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007462
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007463 if exists("s:netrwmarkfilelist_{curbufnr}")
7464 " get the command
7465 call inputsave()
7466 let cmd= input("Enter command: ","","file")
7467 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007468" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007469 if cmd == ""
7470" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7471 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007472 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007473
7474 " apply command to marked files, individually. Substitute: filename -> %
7475 " If no %, then append a space and the filename to the command
7476 for fname in s:netrwmarkfilelist_{curbufnr}
7477 if a:islocal
7478 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007479 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007480 endif
7481 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007482 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 endif
7484 if cmd =~ '%'
7485 let xcmd= substitute(cmd,'%',fname,'g')
7486 else
7487 let xcmd= cmd.' '.fname
7488 endif
7489 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007490" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007491 let ret= system(xcmd)
7492 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007493" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007494 let ret= s:RemoteSystem(xcmd)
7495 endif
7496 if v:shell_error < 0
7497 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7498 break
7499 else
7500 echo ret
7501 endif
7502 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007503
7504 " unmark marked file list
7505 call s:NetrwUnmarkList(curbufnr,curdir)
7506
7507 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007508 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007509" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7510 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007511 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007512 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007513 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007514
7515 else " apply command to global list of files, en bloc
7516
7517 call inputsave()
7518 let cmd= input("Enter command: ","","file")
7519 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007520" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007521 if cmd == ""
7522" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7523 return
7524 endif
7525 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007526 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007527 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007528 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007529 endif
7530 if a:islocal
7531 call system(cmd)
7532 if v:shell_error < 0
7533 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7534 endif
7535 else
7536 let ret= s:RemoteSystem(cmd)
7537 endif
7538 call s:NetrwUnmarkAll()
7539
7540 " refresh the listing
7541 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007542" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7543 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007544
7545 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007546
Bram Moolenaar446cb832008-06-24 21:56:24 +00007547" call Dret("s:NetrwMarkFileExe")
7548endfun
7549
7550" ---------------------------------------------------------------------
7551" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7552" as the marked file(s) (toggles suffix presence)
7553" Uses the local marked file list.
7554fun! s:NetrwMarkHideSfx(islocal)
7555" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007556 let svpos = winsaveview()
7557" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007558 let curbufnr = bufnr("%")
7559
7560 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7561 if exists("s:netrwmarkfilelist_{curbufnr}")
7562
7563 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007564" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007565 " construct suffix pattern
7566 if fname =~ '\.'
7567 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7568 else
7569 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7570 endif
7571 " determine if its in the hiding list or not
7572 let inhidelist= 0
7573 if g:netrw_list_hide != ""
7574 let itemnum = 0
7575 let hidelist= split(g:netrw_list_hide,',')
7576 for hidepat in hidelist
7577 if sfxpat == hidepat
7578 let inhidelist= 1
7579 break
7580 endif
7581 let itemnum= itemnum + 1
7582 endfor
7583 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007584" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007585 if inhidelist
7586 " remove sfxpat from list
7587 call remove(hidelist,itemnum)
7588 let g:netrw_list_hide= join(hidelist,",")
7589 elseif g:netrw_list_hide != ""
7590 " append sfxpat to non-empty list
7591 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7592 else
7593 " set hiding list to sfxpat
7594 let g:netrw_list_hide= sfxpat
7595 endif
7596 endfor
7597
7598 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007599 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007600" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7601 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007602 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007603 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007604 endif
7605
7606" call Dret("s:NetrwMarkHideSfx")
7607endfun
7608
7609" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007610" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007611" Uses the local marked-file list.
7612fun! s:NetrwMarkFileVimCmd(islocal)
7613" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007614 let svpos = winsaveview()
7615" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007616 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007617 let curbufnr = bufnr("%")
7618
Bram Moolenaarff034192013-04-24 18:51:19 +02007619 " sanity check
7620 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007621 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007622" call Dret("s:NetrwMarkFileVimCmd")
7623 return
7624 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007625" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007626
Bram Moolenaar15146672011-10-20 22:22:38 +02007627 if exists("s:netrwmarkfilelist_{curbufnr}")
7628 " get the command
7629 call inputsave()
7630 let cmd= input("Enter vim command: ","","file")
7631 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007632" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007633 if cmd == ""
7634" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7635 return
7636 endif
7637
7638 " apply command to marked files. Substitute: filename -> %
7639 " If no %, then append a space and the filename to the command
7640 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007641" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007642 if a:islocal
7643 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007644 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007645" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007646 exe cmd
7647 exe "sil! keepalt wq!"
7648 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007649" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007650 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007651 endif
7652 endfor
7653
7654 " unmark marked file list
7655 call s:NetrwUnmarkList(curbufnr,curdir)
7656
7657 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007658 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007659" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7660 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007661 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007662 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007663 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007664
Bram Moolenaar15146672011-10-20 22:22:38 +02007665" call Dret("s:NetrwMarkFileVimCmd")
7666endfun
7667
7668" ---------------------------------------------------------------------
7669" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7670" as the marked file(s) (toggles suffix presence)
7671" Uses the local marked file list.
7672fun! s:NetrwMarkHideSfx(islocal)
7673" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007674 let svpos = winsaveview()
7675" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007676 let curbufnr = bufnr("%")
7677
7678 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7679 if exists("s:netrwmarkfilelist_{curbufnr}")
7680
7681 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007682" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007683 " construct suffix pattern
7684 if fname =~ '\.'
7685 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7686 else
7687 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7688 endif
7689 " determine if its in the hiding list or not
7690 let inhidelist= 0
7691 if g:netrw_list_hide != ""
7692 let itemnum = 0
7693 let hidelist= split(g:netrw_list_hide,',')
7694 for hidepat in hidelist
7695 if sfxpat == hidepat
7696 let inhidelist= 1
7697 break
7698 endif
7699 let itemnum= itemnum + 1
7700 endfor
7701 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007702" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007703 if inhidelist
7704 " remove sfxpat from list
7705 call remove(hidelist,itemnum)
7706 let g:netrw_list_hide= join(hidelist,",")
7707 elseif g:netrw_list_hide != ""
7708 " append sfxpat to non-empty list
7709 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7710 else
7711 " set hiding list to sfxpat
7712 let g:netrw_list_hide= sfxpat
7713 endif
7714 endfor
7715
7716 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007717 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007718" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7719 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007720 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007721 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007722 endif
7723
7724" call Dret("s:NetrwMarkHideSfx")
7725endfun
7726
7727" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007728" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7729" Uses the global markfilelist
7730fun! s:NetrwMarkFileGrep(islocal)
7731" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007732 let svpos = winsaveview()
7733" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007734 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007735 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007736
7737 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007738" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007739 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007740" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007741 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007742 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007743" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007744 let netrwmarkfilelist= "*"
7745 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007746
Bram Moolenaarff034192013-04-24 18:51:19 +02007747 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007748" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007749 call inputsave()
7750 let pat= input("Enter pattern: ","")
7751 call inputrestore()
7752 let patbang = ""
7753 if pat =~ '^!'
7754 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007755 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007756 endif
7757 if pat =~ '^\i'
7758 let pat = escape(pat,'/')
7759 let pat = '/'.pat.'/'
7760 else
7761 let nonisi = pat[0]
7762 endif
7763
7764 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007765" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007766 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007767 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007768 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007769 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007770" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7771 return
7772 endtry
7773 echo "(use :cn, :cp to navigate, :Rex to return)"
7774
7775 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007776" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7777 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007778
7779 if exists("nonisi")
7780 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007781" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007782 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007783 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007784 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007785 endif
7786
7787" call Dret("s:NetrwMarkFileGrep")
7788endfun
7789
7790" ---------------------------------------------------------------------
7791" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7792" uses the global marked file list
7793" s:netrwmfloc= 0: target directory is remote
7794" = 1: target directory is local
7795fun! s:NetrwMarkFileMove(islocal)
7796" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007797 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007798 let curbufnr = bufnr("%")
7799
7800 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007801 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007802 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007803" call Dret("s:NetrwMarkFileMove")
7804 return
7805 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007806" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007807
Bram Moolenaar446cb832008-06-24 21:56:24 +00007808 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007809 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007810" call Dret("s:NetrwMarkFileCopy 0")
7811 return 0
7812 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007813" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007814
7815 if a:islocal && s:netrwmftgt_islocal
7816 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007817" call Decho("move from local to local",'~'.expand("<slnum>"))
7818" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007819 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007820 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7821" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7822 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007823 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007824 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007825" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007826 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007827 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007828" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007829 if g:netrw_localmovecmd =~ '\s'
7830 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7831 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7832 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007833" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007834 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007835 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007836" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007837 endif
7838 else
7839 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007840" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007841 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007842 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007843 if g:netrw_keepdir
7844 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7845 let fname= b:netrw_curdir."/".fname
7846 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007847 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007848 let fname= substitute(fname,'/','\\','g')
7849 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007850" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007851 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007852 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007854 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 +01007855 else
7856 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7857 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007858 break
7859 endif
7860 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007861
7862 elseif a:islocal && !s:netrwmftgt_islocal
7863 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007864" call Decho("move from local to remote",'~'.expand("<slnum>"))
7865" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007866 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007867 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007868" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007869 for fname in mflist
7870 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7871 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7872 endfor
7873 unlet mflist
7874
7875 elseif !a:islocal && s:netrwmftgt_islocal
7876 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007877" call Decho("move from remote to local",'~'.expand("<slnum>"))
7878" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007879 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007880 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007881" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007882 for fname in mflist
7883 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7884 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7885 endfor
7886 unlet mflist
7887
7888 elseif !a:islocal && !s:netrwmftgt_islocal
7889 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007890" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7891" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007892 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007893 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007894" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895 for fname in mflist
7896 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7897 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7898 endfor
7899 unlet mflist
7900 endif
7901
7902 " -------
7903 " cleanup
7904 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007905" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007906
7907 " remove markings from local buffer
7908 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7909
7910 " refresh buffers
7911 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007912" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007913 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007914 endif
7915 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007916" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007917 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007918 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007919 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007920" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007921 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007922 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007923
Bram Moolenaar446cb832008-06-24 21:56:24 +00007924" call Dret("s:NetrwMarkFileMove")
7925endfun
7926
7927" ---------------------------------------------------------------------
7928" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7929" using the hardcopy command. Local marked-file list only.
7930fun! s:NetrwMarkFilePrint(islocal)
7931" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7932 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007933
7934 " sanity check
7935 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007936 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007937" call Dret("s:NetrwMarkFilePrint")
7938 return
7939 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007940" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7941 let curdir= s:NetrwGetCurdir(a:islocal)
7942
Bram Moolenaar446cb832008-06-24 21:56:24 +00007943 if exists("s:netrwmarkfilelist_{curbufnr}")
7944 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007945 call s:NetrwUnmarkList(curbufnr,curdir)
7946 for fname in netrwmarkfilelist
7947 if a:islocal
7948 if g:netrw_keepdir
7949 let fname= s:ComposePath(curdir,fname)
7950 endif
7951 else
7952 let fname= curdir.fname
7953 endif
7954 1split
7955 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007956" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007957 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007958" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007959 hardcopy
7960 q
7961 endfor
7962 2match none
7963 endif
7964" call Dret("s:NetrwMarkFilePrint")
7965endfun
7966
7967" ---------------------------------------------------------------------
7968" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7969" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007970" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007971fun! s:NetrwMarkFileRegexp(islocal)
7972" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7973
7974 " get the regular expression
7975 call inputsave()
7976 let regexp= input("Enter regexp: ","","file")
7977 call inputrestore()
7978
7979 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007980 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007981" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007982 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007983" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007984 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007985 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007986 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007987 else
7988 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007989 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007990 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007991" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007992
7993 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007994 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007995 if fname =~ '^'.fnameescape(curdir)
7996" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7997 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7998 else
7999" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8000 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8001 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008002 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008003
8004 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008005" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006
8007 " convert displayed listing into a filelist
8008 let eikeep = &ei
8009 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008010 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008011 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008012" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008013 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008014 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008015 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008016 sil NetrwKeepj norm! "ap
8017 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008019 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008020 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008022 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008023 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008025 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008026 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008028 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8029 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008030 call histdel("/",-1)
8031 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008032 endif
8033 " convert regexp into the more usual glob-style format
8034 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008035" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008036 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008037 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008038 let filelist= getline(1,line("$"))
8039 q!
8040 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008041 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008042 endfor
8043 unlet filelist
8044 let @a = areg
8045 let &ei = eikeep
8046 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008047 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048
8049" call Dret("s:NetrwMarkFileRegexp")
8050endfun
8051
8052" ---------------------------------------------------------------------
8053" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8054" Uses the local marked file list.
8055fun! s:NetrwMarkFileSource(islocal)
8056" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8057 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008058
8059 " sanity check
8060 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008061 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008062" call Dret("s:NetrwMarkFileSource")
8063 return
8064 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008065" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8066 let curdir= s:NetrwGetCurdir(a:islocal)
8067
Bram Moolenaar446cb832008-06-24 21:56:24 +00008068 if exists("s:netrwmarkfilelist_{curbufnr}")
8069 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008070 call s:NetrwUnmarkList(curbufnr,curdir)
8071 for fname in netrwmarkfilelist
8072 if a:islocal
8073 if g:netrw_keepdir
8074 let fname= s:ComposePath(curdir,fname)
8075 endif
8076 else
8077 let fname= curdir.fname
8078 endif
8079 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008080" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008081 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008082 endfor
8083 2match none
8084 endif
8085" call Dret("s:NetrwMarkFileSource")
8086endfun
8087
8088" ---------------------------------------------------------------------
8089" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8090" Uses the global markfilelist
8091fun! s:NetrwMarkFileTag(islocal)
8092" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008093 let svpos = winsaveview()
8094" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008095 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008096 let curbufnr = bufnr("%")
8097
Bram Moolenaarff034192013-04-24 18:51:19 +02008098 " sanity check
8099 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008100 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008101" call Dret("s:NetrwMarkFileTag")
8102 return
8103 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008104" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008105
Bram Moolenaar446cb832008-06-24 21:56:24 +00008106 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008107" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8108 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008109 call s:NetrwUnmarkAll()
8110
8111 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008112
8113" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8114 call system(g:netrw_ctags." ".netrwmarkfilelist)
8115 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008116 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8117 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008118
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008120 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008121 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008122 let curdir= b:netrw_curdir
8123 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008124 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008125 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008126" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008127 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008128 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008129 wq!
8130 endif
8131 2match none
8132 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008133" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8134 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135 endif
8136
8137" call Dret("s:NetrwMarkFileTag")
8138endfun
8139
8140" ---------------------------------------------------------------------
8141" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008142" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008143" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008144" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008145" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008146fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008147" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8148 let svpos = winsaveview()
8149" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008150 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008151 let hadtgt = exists("s:netrwmftgt")
8152 if !exists("w:netrw_bannercnt")
8153 let w:netrw_bannercnt= b:netrw_bannercnt
8154 endif
8155
8156 " set up target
8157 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008158" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008159 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8160 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008161" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008162 unlet s:netrwmftgt s:netrwmftgt_islocal
8163 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008164 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008165 endif
8166 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008167" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8168 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008169" call Dret("s:NetrwMarkFileTgt : removed target")
8170 return
8171 else
8172 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008173" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008174 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008175
8176 else
8177 " get word under cursor.
8178 " * If directory, use it for the target.
8179 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008180" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008181 let curword= s:NetrwGetWord()
8182 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008185" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008186 elseif !a:islocal && tgtdir =~ '/$'
8187 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008189 else
8190 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008192 endif
8193 endif
8194 if a:islocal
8195 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8196 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008197" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008198 endif
8199 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008200 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008201 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8202 endif
8203 let s:netrwmftgt_islocal= a:islocal
8204
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008205 " need to do refresh so that the banner will be updated
8206 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008207 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008208" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008209 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008210 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008211" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008212 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008213 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8214 else
8215 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8216 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008217" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8218 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008219 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008220 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008221 endif
8222
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008223" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8224" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008225" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8226endfun
8227
8228" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008229" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8230fun! s:NetrwGetCurdir(islocal)
8231" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8232
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008233 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008234 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8235" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8236 elseif !exists("b:netrw_curdir")
8237 let b:netrw_curdir= getcwd()
8238" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8239 endif
8240
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008241" 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 +01008242 if b:netrw_curdir !~ '\<\a\{3,}://'
8243 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008244" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008245 if g:netrw_keepdir == 0
8246 call s:NetrwLcd(curdir)
8247 endif
8248 endif
8249
8250" call Dret("s:NetrwGetCurdir <".curdir.">")
8251 return b:netrw_curdir
8252endfun
8253
8254" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008255" s:NetrwOpenFile: query user for a filename and open it {{{2
8256fun! s:NetrwOpenFile(islocal)
8257" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008258 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008259 call inputsave()
8260 let fname= input("Enter filename: ")
8261 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008262" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8263
8264 " determine if Lexplore is in use
8265 if exists("t:netrw_lexbufnr")
8266 " check if t:netrw_lexbufnr refers to a netrw window
8267" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8268 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8269 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8270" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8271 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8272 exe "NetrwKeepj e ".fnameescape(fname)
8273 let @@= ykeep
8274" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8275 endif
8276 endif
8277
8278 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008279 if fname !~ '[/\\]'
8280 if exists("b:netrw_curdir")
8281 if exists("g:netrw_quiet")
8282 let netrw_quiet_keep = g:netrw_quiet
8283 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008284 let g:netrw_quiet = 1
8285 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008286 let s:rexposn_{bufnr("%")}= winsaveview()
8287" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008288 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008289 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008290 else
8291 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8292 endif
8293 if exists("netrw_quiet_keep")
8294 let g:netrw_quiet= netrw_quiet_keep
8295 else
8296 unlet g:netrw_quiet
8297 endif
8298 endif
8299 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008300 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008301 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008302 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008303" call Dret("s:NetrwOpenFile")
8304endfun
8305
8306" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008307" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8308" For the mapping to this function be made via
8309" netrwPlugin, you'll need to have had
8310" g:netrw_usetab set to non-zero.
8311fun! netrw#Shrink()
8312" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8313 let curwin = winnr()
8314 let wiwkeep = &wiw
8315 set wiw=1
8316
8317 if &ft == "netrw"
8318 if winwidth(0) > g:netrw_wiw
8319 let t:netrw_winwidth= winwidth(0)
8320 exe "vert resize ".g:netrw_wiw
8321 wincmd l
8322 if winnr() == curwin
8323 wincmd h
8324 endif
8325" call Decho("vert resize 0",'~'.expand("<slnum>"))
8326 else
8327 exe "vert resize ".t:netrw_winwidth
8328" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8329 endif
8330
8331 elseif exists("t:netrw_lexbufnr")
8332 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8333 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8334 let t:netrw_winwidth= winwidth(0)
8335 exe "vert resize ".g:netrw_wiw
8336 wincmd l
8337 if winnr() == curwin
8338 wincmd h
8339 endif
8340" call Decho("vert resize 0",'~'.expand("<slnum>"))
8341 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8342 exe "vert resize ".t:netrw_winwidth
8343" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8344 else
8345 call netrw#Lexplore(0,0)
8346 endif
8347
8348 else
8349 call netrw#Lexplore(0,0)
8350 endif
8351 let wiw= wiwkeep
8352
8353" call Dret("netrw#Shrink")
8354endfun
8355
8356" ---------------------------------------------------------------------
8357" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8358fun! s:NetSortSequence(islocal)
8359" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8360
8361 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008362 let svpos= winsaveview()
8363" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008364 call inputsave()
8365 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8366 call inputrestore()
8367
8368 " refresh the listing
8369 let g:netrw_sort_sequence= newsortseq
8370 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008371" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8372 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008373 let @@= ykeep
8374
8375" call Dret("NetSortSequence")
8376endfun
8377
8378" ---------------------------------------------------------------------
8379" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8380" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008381" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008382fun! s:NetrwUnmarkList(curbufnr,curdir)
8383" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8384
8385 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008386 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008387 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8388 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8389 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8390 call remove(s:netrwmarkfilelist,idx) " remove from global list
8391 endfor
8392 if s:netrwmarkfilelist == []
8393 unlet s:netrwmarkfilelist
8394 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008395
Bram Moolenaar446cb832008-06-24 21:56:24 +00008396 " getting rid of the local marked-file lists is easy
8397 unlet s:netrwmarkfilelist_{a:curbufnr}
8398 endif
8399 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8400 unlet s:netrwmarkfilemtch_{a:curbufnr}
8401 endif
8402 2match none
8403" call Dret("s:NetrwUnmarkList")
8404endfun
8405
8406" ---------------------------------------------------------------------
8407" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8408fun! s:NetrwUnmarkAll()
8409" call Dfunc("s:NetrwUnmarkAll()")
8410 if exists("s:netrwmarkfilelist")
8411 unlet s:netrwmarkfilelist
8412 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008413 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008414 2match none
8415" call Dret("s:NetrwUnmarkAll")
8416endfun
8417
8418" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008419" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008420fun! s:NetrwUnmarkAll2()
8421" call Dfunc("s:NetrwUnmarkAll2()")
8422 redir => netrwmarkfilelist_let
8423 let
8424 redir END
8425 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008426 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008427 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8428 for flist in netrwmarkfilelist_list
8429 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8430 unlet s:netrwmarkfilelist_{curbufnr}
8431 unlet s:netrwmarkfilemtch_{curbufnr}
8432 endfor
8433" call Dret("s:NetrwUnmarkAll2")
8434endfun
8435
8436" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008437" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8438"
8439" Marked files are in two types of lists:
8440" s:netrwmarkfilelist -- holds complete paths to all marked files
8441" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8442"
8443" Marked files suitable for use with 2match are in:
8444" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008445fun! s:NetrwUnMarkFile(islocal)
8446" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008447 let svpos = winsaveview()
8448" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008449 let curbufnr = bufnr("%")
8450
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008451 " unmark marked file list
8452 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8453 if exists("s:netrwmarkfilelist")
8454" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008455 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008456 endif
8457
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008458 let ibuf= 1
8459 while ibuf < bufnr("$")
8460 if exists("s:netrwmarkfilelist_".ibuf)
8461 unlet s:netrwmarkfilelist_{ibuf}
8462 unlet s:netrwmarkfilemtch_{ibuf}
8463 endif
8464 let ibuf = ibuf + 1
8465 endwhile
8466 2match none
8467
Bram Moolenaar446cb832008-06-24 21:56:24 +00008468" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008469"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8470call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008471" call Dret("s:NetrwUnMarkFile")
8472endfun
8473
8474" ---------------------------------------------------------------------
8475" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8476fun! s:NetrwMenu(domenu)
8477
8478 if !exists("g:NetrwMenuPriority")
8479 let g:NetrwMenuPriority= 80
8480 endif
8481
Bram Moolenaaradc21822011-04-01 18:03:16 +02008482 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008483" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8484
8485 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008486" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008487 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008488 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8489 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8490 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8491 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8492 if g:netrw_dirhistmax > 0
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8495 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8497 else
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8499 endif
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8514 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 +01008515 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 +02008516 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8545 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>'
8546 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>'
8547 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>'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8549 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>'
8550 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>'
8551 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 +01008552 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 +02008553 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008555 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008556 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8557 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008558
8559 elseif !a:domenu
8560 let s:netrwcnt = 0
8561 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008562 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008563 exe curwin."wincmd w"
8564
8565 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008566" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008567 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008568" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008569 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008570 endif
8571 endif
8572" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008573 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008574 endif
8575
8576endfun
8577
8578" ---------------------------------------------------------------------
8579" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8580" Used by the O maps (as <SID>NetrwObtain())
8581fun! s:NetrwObtain(islocal)
8582" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8583
Bram Moolenaar97d62492012-11-15 21:28:22 +01008584 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008585 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008586 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008587 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008588 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8589 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008590 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008591 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008592 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008593
8594" call Dret("NetrwObtain")
8595endfun
8596
8597" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008598" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8599" If there's only one window, then the window will first be split.
8600" Returns:
8601" choice = 0 : didn't have to choose
8602" choice = 1 : saved modified file in window first
8603" choice = 2 : didn't save modified file, opened window
8604" choice = 3 : cancel open
8605fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008606" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607
Bram Moolenaar97d62492012-11-15 21:28:22 +01008608 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008609 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008610 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008611" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612
8613 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008614 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008616" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8617" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8618 let curword = s:NetrwGetWord()
8619 let choice = 0
8620 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8621" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008622 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008623" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008624 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008625" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008626" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008627" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008628
Bram Moolenaar8d043172014-01-23 14:24:41 +01008629 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008630 if lastwinnr == 1
8631 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008632" 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 +02008633 " g:netrw_preview=0: preview window shown in a horizontally split window
8634 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008635 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008636 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008637 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008638" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008639 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008641 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008642 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008643" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008644 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008646 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008647" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648
8649 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008650" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008651 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008652" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008653 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008654" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008655 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008656" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008657 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008658" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008659" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008660" call Decho("COMBAK#12: mod=".&mod)
8661
8662 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8663 " whoops -- user trying to open file in the Lexplore window.
8664 " Use Lexplore's opening-file window instead.
8665" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8666" exe g:netrw_chgwin."wincmd w"
8667 wincmd p
8668 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8669 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008670
8671 " prevwinnr: the window number of the "prev" window
8672 " prevbufnr: the buffer number of the buffer in the "prev" window
8673 " bnrcnt : the qty of windows open on the "prev" buffer
8674 let prevwinnr = winnr()
8675 let prevbufnr = bufnr("%")
8676 let prevbufname = bufname("%")
8677 let prevmod = &mod
8678 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008679" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008680 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008681" 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 +01008682" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008683
8684 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008685 " and it doesn't appear in any other extant window, then ask the
8686 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008687 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008688" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008689 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008690" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008691 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008692" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008693
8694 if bnrcnt == 1 && &hidden == 0
8695 " only one copy of the modified buffer in a window, and
8696 " hidden not set, so overwriting will lose the modified file. Ask first...
8697 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008698" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008699 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008700" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008701
8702 if choice == 1
8703 " Yes -- write file & then browse
8704 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008705 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008706 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008707 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008708 exe origwin."wincmd w"
8709 let &ei = eikeep
8710 let @@ = ykeep
8711" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008712 return choice
8713 endif
8714
8715 elseif choice == 2
8716 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008717" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008718 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008719
8720 else
8721 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008722" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008723 exe origwin."wincmd w"
8724 let &ei= eikeep
8725 let @@ = ykeep
8726" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008727 return choice
8728 endif
8729 endif
8730 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008731 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008732 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008733" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008734
8735 " restore b:netrw_curdir (window split/enew may have lost it)
8736 let b:netrw_curdir= curdir
8737 if a:islocal < 2
8738 if a:islocal
8739 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8740 else
8741 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8742 endif
8743 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008744 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008745" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008746 return choice
8747endfun
8748
8749" ---------------------------------------------------------------------
8750" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8751" Always assumed to be local -> remote
8752" call s:NetrwUpload(filename, target)
8753" call s:NetrwUpload(filename, target, fromdirectory)
8754fun! s:NetrwUpload(fname,tgt,...)
8755" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8756
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008757 if a:tgt =~ '^\a\{3,}://'
8758 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008759 else
8760 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8761 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008762" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008763
8764 if a:0 > 0
8765 let fromdir= a:1
8766 else
8767 let fromdir= getcwd()
8768 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008769" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770
8771 if type(a:fname) == 1
8772 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008773" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008774 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008775" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8776 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8777" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778 if a:tgt =~ '/$'
8779 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008780" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008781 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008782 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008784 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008785" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008786 endif
8787 q!
8788
8789 elseif type(a:fname) == 3
8790 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008791" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792 let curdir= getcwd()
8793 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008794 if s:NetrwLcd(fromdir)
8795" call Dret("s:NetrwUpload : lcd failure")
8796 return
8797 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008798 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008799 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008800 if exists("g:netrw_port") && g:netrw_port != ""
8801 let useport= " ".g:netrw_scpport." ".g:netrw_port
8802 else
8803 let useport= ""
8804 endif
8805 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8806 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008807 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 +02008808 if s:NetrwLcd(curdir)
8809" call Dret("s:NetrwUpload : lcd failure")
8810 return
8811 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008812
8813 elseif a:tgt =~ '^ftp:'
8814 call s:NetrwMethod(a:tgt)
8815
8816 if b:netrw_method == 2
8817 " handle uploading a list of files via ftp+.netrc
8818 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008819 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008820" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008821
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008822 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824
8825 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008826 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008827" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008828 endif
8829
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008830 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008831" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832
Bram Moolenaaradc21822011-04-01 18:03:16 +02008833 if tgtdir == ""
8834 let tgtdir= '/'
8835 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008836 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008837" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008838
8839 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008840 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8841" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842 endfor
8843
8844 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008845 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 +00008846 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008847" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8848 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008849 endif
8850 " 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 +01008851 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008852 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008853 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8854 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8855 else
8856 bw!|q
8857 endif
8858
8859 elseif b:netrw_method == 3
8860 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8861 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008862 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008863 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008864 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008865
8866 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008867 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008868" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008869 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008870 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008871" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008872 endif
8873
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008874 if exists("g:netrw_uid") && g:netrw_uid != ""
8875 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008876 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008877" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008878 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008879 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008880 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008881" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008882 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008883 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008884" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008885 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008886 endif
8887
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008888 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008889" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008890
8891 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008892 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008893" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008894 endif
8895
8896 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008897 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008898" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008899 endif
8900
8901 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008902 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008903" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008904 endfor
8905
8906 " perform ftp:
8907 " -i : turns off interactive prompting from ftp
8908 " -n unix : DON'T use <.netrc>, even though it exists
8909 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008910 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008911 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008912 " 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 +01008913 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008914 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008915 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8916 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008917 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008918 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8919 let &debug = debugkeep
8920 let mod = 1
8921 else
8922 bw!|q
8923 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008924 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008925" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008926 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008927 endif
8928 else
8929 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8930 endif
8931 endif
8932
8933" call Dret("s:NetrwUpload")
8934endfun
8935
8936" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008937" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008938fun! s:NetrwPreview(path) range
8939" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008940" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8941" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008942 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008943 NetrwKeepj call s:NetrwOptionsSave("s:")
8944 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8945 NetrwKeepj call s:NetrwOptionsSafe(1)
8946 else
8947 NetrwKeepj call s:NetrwOptionsSafe(0)
8948 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008949 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008950" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008951 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008952" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8953 if g:netrw_preview
8954 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008955 let pvhkeep = &pvh
8956 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8957 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008958" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8959 else
8960 " horizontal split
8961 let pvhkeep = &pvh
8962 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8963 let &pvh = winheight(0) - winsz
8964" 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 +02008965 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008966 " g:netrw_preview g:netrw_alto
8967 " 1 : vert 1: top -- preview window is vertically split off and on the left
8968 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8969 " 0 : 1: top -- preview window is horizontally split off and on the top
8970 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8971 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008972 " 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 +02008973 " the BufEnter event set up in netrwPlugin.vim
8974" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8975 let eikeep = &ei
8976 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008977 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008978 let &ei= eikeep
8979" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008980 if exists("pvhkeep")
8981 let &pvh= pvhkeep
8982 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008983 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008984 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008985 endif
8986 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008987 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 +00008988 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008989 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008990 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008991" call Dret("NetrwPreview")
8992endfun
8993
8994" ---------------------------------------------------------------------
8995" s:NetrwRefresh: {{{2
8996fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008997" 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 +00008998 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008999 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009000" call Decho("setl ma noro",'~'.expand("<slnum>"))
9001" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009002 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009003 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9004 if !exists("w:netrw_treetop")
9005 if exists("b:netrw_curdir")
9006 let w:netrw_treetop= b:netrw_curdir
9007 else
9008 let w:netrw_treetop= getcwd()
9009 endif
9010 endif
9011 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9012 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009013
9014 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009015 let screenposn = winsaveview()
9016" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009017
9018" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9019" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9020 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009021 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009022 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009023 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009024 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009025 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009026
9027 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009028" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9029 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009030
9031 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009032 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9033 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9034" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9035 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9036 else
9037" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9038 2match none
9039 endif
9040 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009041
Bram Moolenaar97d62492012-11-15 21:28:22 +01009042" restore
9043 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009044" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009045endfun
9046
9047" ---------------------------------------------------------------------
9048" s:NetrwRefreshDir: refreshes a directory by name {{{2
9049" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009050" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009051fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009052" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009053 if g:netrw_fastbrowse == 0
9054 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009055" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009056 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009057" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009058
9059 if tgtwin > 0
9060 " tgtwin is being displayed, so refresh it
9061 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009062" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009063 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009064 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009065 exe curwin."wincmd w"
9066
9067 elseif bufnr(a:dirname) > 0
9068 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009069" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9070 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071 endif
9072
9073 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009074" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009075 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076 endif
9077" call Dret("s:NetrwRefreshDir")
9078endfun
9079
9080" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009081" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9082" window number to do its editing in.
9083" Supports [count]C where the count, if present, is used to specify
9084" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009085fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009086" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009087 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009088" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009089 if a:1 == "" " :NetrwC win#
9090 let g:netrw_chgwin= winnr()
9091 else " :NetrwC
9092 let g:netrw_chgwin= a:1
9093 endif
9094 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009095 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009096 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009097 let g:netrw_chgwin= winnr()
9098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009099 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009100" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009101endfun
9102
9103" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009104" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9105" What this function does is to compute a priority for the patterns
9106" in the g:netrw_sort_sequence. It applies a substitute to any
9107" "files" that satisfy each pattern, putting the priority / in
9108" front. An "*" pattern handles the default priority.
9109fun! s:NetrwSetSort()
9110" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009111 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009112 if w:netrw_liststyle == s:LONGLIST
9113 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9114 else
9115 let seqlist = g:netrw_sort_sequence
9116 endif
9117 " sanity check -- insure that * appears somewhere
9118 if seqlist == ""
9119 let seqlist= '*'
9120 elseif seqlist !~ '\*'
9121 let seqlist= seqlist.',*'
9122 endif
9123 let priority = 1
9124 while seqlist != ""
9125 if seqlist =~ ','
9126 let seq = substitute(seqlist,',.*$','','e')
9127 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9128 else
9129 let seq = seqlist
9130 let seqlist = ""
9131 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009132 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009133 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009134 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009135 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009136 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009137 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009138 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009139" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009140
9141 " sanity check
9142 if w:netrw_bannercnt > line("$")
9143 " apparently no files were left after a Hiding pattern was used
9144" call Dret("SetSort : no files left after hiding")
9145 return
9146 endif
9147 if seq == '*'
9148 let starpriority= spriority
9149 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009150 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009151 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009152 " sometimes multiple sorting patterns will match the same file or directory.
9153 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009154 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9155 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009156 endif
9157 let priority = priority + 1
9158 endwhile
9159 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009160 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9161 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009162 endif
9163
9164 " Following line associated with priority -- items that satisfy a priority
9165 " pattern get prefixed by ###/ which permits easy sorting by priority.
9166 " Sometimes files can satisfy multiple priority patterns -- only the latest
9167 " priority pattern needs to be retained. So, at this point, these excess
9168 " priority prefixes need to be removed, but not directories that happen to
9169 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009170 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9171 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009172 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009173
9174" call Dret("SetSort")
9175endfun
9176
Bram Moolenaarff034192013-04-24 18:51:19 +02009177" ---------------------------------------------------------------------
9178" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9179" Implements [count]Tb (bookhist<b>)
9180" [count]Th (bookhist<h>)
9181" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009182fun! s:NetrwSetTgt(islocal,bookhist,choice)
9183" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009184
9185 if a:bookhist == 'b'
9186 " supports choosing a bookmark as a target using a qb-generated list
9187 let choice= a:choice - 1
9188 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009189 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009190 else
9191 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9192 endif
9193
9194 elseif a:bookhist == 'h'
9195 " supports choosing a history stack entry as a target using a qb-generated list
9196 let choice= (a:choice % g:netrw_dirhistmax) + 1
9197 if exists("g:netrw_dirhist_".choice)
9198 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009199 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009200 else
9201 echomsg "Sorry, history#".a:choice." not available!"
9202 endif
9203 endif
9204
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009205 " refresh the display
9206 if !exists("b:netrw_curdir")
9207 let b:netrw_curdir= getcwd()
9208 endif
9209 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9210
Bram Moolenaarff034192013-04-24 18:51:19 +02009211" call Dret("s:NetrwSetTgt")
9212endfun
9213
Bram Moolenaar446cb832008-06-24 21:56:24 +00009214" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009215" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009216fun! s:NetrwSortStyle(islocal)
9217" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009218 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009219 let svpos= winsaveview()
9220" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009221
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009222 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 +01009223 NetrwKeepj norm! 0
9224 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009225" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9226 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009227
9228" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9229endfun
9230
9231" ---------------------------------------------------------------------
9232" s:NetrwSplit: mode {{{2
9233" =0 : net and o
9234" =1 : net and t
9235" =2 : net and v
9236" =3 : local and o
9237" =4 : local and t
9238" =5 : local and v
9239fun! s:NetrwSplit(mode)
9240" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9241
Bram Moolenaar97d62492012-11-15 21:28:22 +01009242 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009243 call s:SaveWinVars()
9244
9245 if a:mode == 0
9246 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009247 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009248 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009249" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009250 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009251 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009252 NetrwKeepj call s:RestoreWinVars()
9253 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009254 unlet s:didsplit
9255
9256 elseif a:mode == 1
9257 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009258 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009259" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009260 tabnew
9261 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009262 NetrwKeepj call s:RestoreWinVars()
9263 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009264 unlet s:didsplit
9265
9266 elseif a:mode == 2
9267 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009268 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009269 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009270" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009271 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009272 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009273 NetrwKeepj call s:RestoreWinVars()
9274 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009275 unlet s:didsplit
9276
9277 elseif a:mode == 3
9278 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009279 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009280 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009281" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009282 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009283 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009284 NetrwKeepj call s:RestoreWinVars()
9285 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286 unlet s:didsplit
9287
9288 elseif a:mode == 4
9289 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009290 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009291 let eikeep = &ei
9292 let netrw_winnr = winnr()
9293 let netrw_line = line(".")
9294 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009295 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009296 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009297 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009298 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9299 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009300 let &ei = eikeep
9301 let netrw_curdir = s:NetrwTreeDir(0)
9302" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009303 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009304 let b:netrw_curdir = netrw_curdir
9305 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009306 NetrwKeepj call s:RestoreWinVars()
9307 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009308 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009309 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009310 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9311 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009312 let &ei= eikeep
9313 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009314 unlet s:didsplit
9315
9316 elseif a:mode == 5
9317 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009318 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009319 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009320" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009321 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009322 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009323 NetrwKeepj call s:RestoreWinVars()
9324 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009325 unlet s:didsplit
9326
9327 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009328 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009329 endif
9330
Bram Moolenaar97d62492012-11-15 21:28:22 +01009331 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332" call Dret("s:NetrwSplit")
9333endfun
9334
9335" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009336" s:NetrwTgtMenu: {{{2
9337fun! s:NetrwTgtMenu()
9338 if !exists("s:netrw_menucnt")
9339 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009340 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009341" call Dfunc("s:NetrwTgtMenu()")
9342
9343 " the following test assures that gvim is running, has menus available, and has menus enabled.
9344 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9345 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009346" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009347 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9348 endif
9349 if !exists("s:netrw_initbookhist")
9350 call s:NetrwBookHistRead()
9351 endif
9352
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009353 " try to cull duplicate entries
9354 let tgtdict={}
9355
Bram Moolenaarff034192013-04-24 18:51:19 +02009356 " target bookmarked places
9357 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009358" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009359 let cnt= 1
9360 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009361 if has_key(tgtdict,bmd)
9362 let cnt= cnt + 1
9363 continue
9364 endif
9365 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009366 let ebmd= escape(bmd,g:netrw_menu_escape)
9367 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009368" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009369 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 +02009370 let cnt= cnt + 1
9371 endfor
9372 endif
9373
9374 " target directory browsing history
9375 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009376" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009377 let histcnt = 1
9378 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009379 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009380 if exists("g:netrw_dirhist_{histcnt}")
9381 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009382 if has_key(tgtdict,histentry)
9383 let histcnt = histcnt + 1
9384 continue
9385 endif
9386 let tgtdict[histentry] = histcnt
9387 let ehistentry = escape(histentry,g:netrw_menu_escape)
9388" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009389 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 +02009390 endif
9391 let histcnt = histcnt + 1
9392 endwhile
9393 endif
9394 endif
9395" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009396endfun
9397
9398" ---------------------------------------------------------------------
9399" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9400" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009401fun! s:NetrwTreeDir(islocal)
9402" 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 +02009403" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009404" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9405" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9406" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009407" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009408
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009409 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009410 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009411" 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 +01009412 let treedir= s:treedir
9413 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009414 unlet s:prevwinopen
9415" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009416 return treedir
9417 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009418 if exists("s:prevwinopen")
9419 unlet s:prevwinopen
9420 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009421" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009422
Bram Moolenaar8d043172014-01-23 14:24:41 +01009423 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9424 let b:netrw_curdir= getcwd()
9425 endif
9426 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009427" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009428" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009429
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009430 let s:treecurpos= winsaveview()
9431" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009432" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009433
9434 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009435" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9436" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009437" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009438
9439 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009440 let curline= substitute(getline('.'),"\t -->.*$",'','')
9441 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009442" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009443 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009444" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9445 elseif curline =~ '@$'
9446" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009447 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009448" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009449 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009450" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009451 let treedir= ""
9452 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009453" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009454
9455 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009456" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9457" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009458" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009459 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009460" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009461 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009462" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9463 sil! NetrwKeepj %d _
9464" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009465 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009466" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009467" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009468 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009469" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009470
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009471" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009472" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009473" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009474
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009475 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9476" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9477" let newdir = w:netrw_treetop.'/'.potentialdir
9478" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9479" let treedir = s:NetrwTreePath(newdir)
9480" let w:netrw_treetop = newdir
9481" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9482" else
9483" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009484 if a:islocal && curline =~ '@$'
9485 if isdirectory(s:NetrwFile(potentialdir))
9486 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9487 let w:netrw_treetop = treedir
9488 endif
9489 else
9490 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9491 let treedir = s:NetrwTreePath(w:netrw_treetop)
9492 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009493 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009494" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009495
9496 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009497 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009498" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009499" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009501" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009502 return treedir
9503endfun
9504
9505" ---------------------------------------------------------------------
9506" s:NetrwTreeDisplay: recursive tree display {{{2
9507fun! s:NetrwTreeDisplay(dir,depth)
9508" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9509
9510 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009511 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009512
9513 " install ../ and shortdir
9514 if a:depth == ""
9515 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009516" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009517 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009518 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009519 if a:dir == w:netrw_treetop
9520 let shortdir= a:dir
9521 else
9522 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9523 endif
9524 call setline(line("$")+1,a:depth.shortdir)
9525 else
9526 let shortdir= substitute(a:dir,'^.*/','','e')
9527 call setline(line("$")+1,a:depth.shortdir.'/')
9528 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009529" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009530 " append a / to dir if its missing one
9531 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009532
9533 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009534 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009535" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009536
Bram Moolenaar85850f32019-07-19 22:05:51 +02009537 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9538 if g:netrw_hide == 1
9539 " hide given patterns
9540 let listhide= split(g:netrw_list_hide,',')
9541" call Decho("listhide=".string(listhide))
9542 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009543 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009544 endfor
9545
9546 elseif g:netrw_hide == 2
9547 " show given patterns (only)
9548 let listhide= split(g:netrw_list_hide,',')
9549" call Decho("listhide=".string(listhide))
9550 let entries=[]
9551 for entry in w:netrw_treedict[dir]
9552 for pat in listhide
9553 if entry =~ pat
9554 call add(entries,entry)
9555 break
9556 endif
9557 endfor
9558 endfor
9559 let w:netrw_treedict[dir]= entries
9560 endif
9561 if depth != ""
9562 " always remove "." and ".." entries when there's depth
9563 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9564 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9565 endif
9566
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009567" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009568 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009569 if dir =~ '/$'
9570 let direntry= substitute(dir.entry,'[@/]$','','e')
9571 else
9572 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9573 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009574" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009575 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009576" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009577 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009579" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9580 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9581 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9582" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009583 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009584 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009585" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009586 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009587 endif
9588 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009589" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009590
Bram Moolenaar446cb832008-06-24 21:56:24 +00009591" call Dret("NetrwTreeDisplay")
9592endfun
9593
9594" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009595" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9596fun! s:NetrwRefreshTreeDict(dir)
9597" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009598 if !exists("w:netrw_treedict")
9599" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9600 return
9601 endif
9602
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009603 for entry in w:netrw_treedict[a:dir]
9604 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9605" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9606
9607 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9608" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9609 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009610 let liststar = s:NetrwGlob(direntry,'*',1)
9611 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009612 let w:netrw_treedict[direntry] = liststar + listdotstar
9613" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9614
9615 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9616" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9617 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009618 let liststar = s:NetrwGlob(direntry.'/','*',1)
9619 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009620 let w:netrw_treedict[direntry]= liststar + listdotstar
9621" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9622
9623 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9624" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9625 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009626 let liststar = s:NetrwGlob(direntry.'/','*',1)
9627 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009628" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9629
9630 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009631" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009632 endif
9633 endfor
9634" call Dret("s:NetrwRefreshTreeDict")
9635endfun
9636
9637" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009638" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009639" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009640fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009641 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009642" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009643" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9644" 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>"))
9645" 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 +00009646
9647 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009648 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009649" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009650 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009651 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009652" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653 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 +02009654" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009655 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009656 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009657" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009659 if exists("w:netrw_treetop")
9660 let s:netrw_treetop= w:netrw_treetop
9661 else
9662 let w:netrw_treetop= getcwd()
9663 let s:netrw_treetop= w:netrw_treetop
9664 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009665
Bram Moolenaar446cb832008-06-24 21:56:24 +00009666 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009667 " insure that we have a treedict, albeit empty
9668" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669 let w:netrw_treedict= {}
9670 endif
9671
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009672 " update the dictionary for the current directory
9673" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009674" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009675 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009676 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009677" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009678 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679
9680 " if past banner, record word
9681 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9682 let fname= expand("<cword>")
9683 else
9684 let fname= ""
9685 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009686" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9687" 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 +00009688
9689 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009690" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009691 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009692" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009693
9694 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9695 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009696" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009697 1d
9698 endwhile
9699
Bram Moolenaar13600302014-05-22 18:26:40 +02009700 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009701
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009702" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009703 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009704 endif
9705endfun
9706
9707" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009708" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009709" Normally, treetop is w:netrw_treetop, but a
9710" user of the function ( netrw#SetTreetop() )
9711" wipes that out prior to calling this function
9712fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009713" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9714 if line(".") < w:netrw_bannercnt + 2
9715 let treedir= a:treetop
9716 if treedir !~ '/$'
9717 let treedir= treedir.'/'
9718 endif
9719" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9720 return treedir
9721 endif
9722
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009723 let svpos = winsaveview()
9724" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009725 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009726" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009727 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009728" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9729 let curline= getline('.')
9730" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9731 if curline =~ '/$'
9732" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9733 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9734" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9735 elseif curline =~ '@\s\+-->'
9736" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9737 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9738 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9739" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009740 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009741" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009742 let treedir= ""
9743 endif
9744 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009745" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9746" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009747 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9748 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9749 let treedir= dirname.treedir
9750 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009751" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009752 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009753" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009754 if a:treetop =~ '/$'
9755 let treedir= a:treetop.treedir
9756 else
9757 let treedir= a:treetop.'/'.treedir
9758 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009759" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009760 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009761" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009762" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9763 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009764" call Dret("s:NetrwTreePath <".treedir.">")
9765 return treedir
9766endfun
9767
9768" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009769" s:NetrwWideListing: {{{2
9770fun! s:NetrwWideListing()
9771
9772 if w:netrw_liststyle == s:WIDELIST
9773" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9774 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009775 " cpf: characters per filename
9776 " fpl: filenames per line
9777 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009778 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009779 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009780" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009781 let b:netrw_cpf= 0
9782 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009783 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009784 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9785 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009786 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009787 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009788" call Dret("NetrwWideListing")
9789 return
9790 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009791 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009792 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009793" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009794
9795 " determine qty files per line (fpl)
9796 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9797 if w:netrw_fpl <= 0
9798 let w:netrw_fpl= 1
9799 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009800" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009801
9802 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009803 " fpc: files per column of wide listing
9804 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009805 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009806 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9807 let newcolstart = w:netrw_bannercnt + fpc
9808 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009809" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009810 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009811" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009812 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009813 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009814 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009815 while line("$") >= newcolstart
9816 if newcolend > line("$") | let newcolend= line("$") | endif
9817 let newcolqty= newcolend - newcolstart
9818 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009819 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009820 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009821 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009822 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009823 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009824 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009825 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009826 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009827 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009828 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009829" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009830 if @* != keepregstar | sil! let @* = keepregstar | endif
9831 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009832 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009833 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9834 NetrwKeepj call histdel("/",-1)
9835 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9836 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009837" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009838 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009839 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009840" 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 +00009841" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009842 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009843 else
9844 if hasmapto("w","n")
9845 sil! nunmap <buffer> w
9846 endif
9847 if hasmapto("b","n")
9848 sil! nunmap <buffer> b
9849 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009850 endif
9851
9852endfun
9853
9854" ---------------------------------------------------------------------
9855" s:PerformListing: {{{2
9856fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009857" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9858" 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 +02009859" 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>"))
9860 sil! NetrwKeepj %d _
9861" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009862
Bram Moolenaar15146672011-10-20 22:22:38 +02009863 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009864" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009865 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009866
Bram Moolenaar85850f32019-07-19 22:05:51 +02009867 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009868 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009869" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009870
9871" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009872" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009873" endif " Decho
9874
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009875" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009876 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9877 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009878" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9879 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009880 endif
9881
9882 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009883 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009884
9885 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009886 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009887" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009888 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009889 if exists("g:netrw_pchk")
9890 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9891 " failure detections.
9892 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009893 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009894 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9895 endif
9896 if exists("g:netrw_pchk")
9897 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9898 else
9899 let curdir= b:netrw_curdir
9900 endif
9901 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9902 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9903 else
9904 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009905 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009906 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009907 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009908 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009909" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009910 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009911 let w:netrw_bannercnt= 1
9912 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009913" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9914" 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 +00009915
Bram Moolenaar85850f32019-07-19 22:05:51 +02009916 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009917 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009918 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009919 let sortby= sortby." reversed"
9920 endif
9921
9922 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009923 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009924" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009925 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009926" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009927 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009928 NetrwKeepj put ='\" Sorted by '.sortby
9929 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009930 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9931 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009932" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009933 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009934 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009935 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9936 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009937 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009938" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009939" 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 +00009940 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009941
Bram Moolenaar85850f32019-07-19 22:05:51 +02009942 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009943 if g:netrw_banner
9944 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009945" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009946 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009947 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009948 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009949 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009950 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009951 endif
9952 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009953 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009954" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009955 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009956 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009957 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009958
9959 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009960 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009961" 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 +01009962 if g:netrw_list_hide != "" && g:netrw_hide
9963 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009964 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009965 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009966 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009967 endif
9968 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009969 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009970 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009971
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009972" 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 +01009973 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009974" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009975 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009976" 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 +01009977 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009978 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009979" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009980" 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 +00009981 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009982
9983 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009984 if g:netrw_banner
9985 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009986 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009987" 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 +01009988" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009989" 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 +01009990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009991
Bram Moolenaar446cb832008-06-24 21:56:24 +00009992 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009993" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009994 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009995 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009996 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009997 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009998 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009999" 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 +010010000" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10001 return
10002 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010003 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010004
10005 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010006 if !exists("w:netrw_bannercnt")
10007 let w:netrw_bannercnt= 0
10008 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010009" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10010" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10011" 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 +010010012
Bram Moolenaar5c736222010-01-06 20:54:52 +010010013 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010014" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010015" 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 +000010016 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010017 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010019 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010020" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010021
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010022 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010023 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010024" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010025 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010026
Bram Moolenaar5c736222010-01-06 20:54:52 +010010027 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010028" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010029 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010030 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010031 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 else
10033 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010034 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010035 endif
10036 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010037
Bram Moolenaar446cb832008-06-24 21:56:24 +000010038 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010039" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010040 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10041 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010042
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010043 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010044 " exten: sort by extension
10045 " The histdel(...,-1) calls remove the last search from the search history
10046" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010047 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10048 NetrwKeepj call histdel("/",-1)
10049 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10050 NetrwKeepj call histdel("/",-1)
10051 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10052 NetrwKeepj call histdel("/",-1)
10053 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10054" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010055 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010056 " normal direction sorting
10057 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10058 else
10059 " reverse direction sorting
10060 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10061 endif
10062 endif
10063 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10064 NetrwKeepj call histdel("/",-1)
10065
Bram Moolenaar446cb832008-06-24 21:56:24 +000010066 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010067 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010068" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010069 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010070" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010071 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010072 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010073" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010074 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010075 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010076" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010077 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10078 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010079 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010080 endif
10081
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010082 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010083" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010084 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010085 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010086 call histdel("/",-1)
10087 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010088 endif
10089 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010090" 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 +000010091
10092 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010093" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10094" 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 +010010095 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010096" 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 +010010097 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010098" 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 +000010099
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010100 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010101 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010102" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010103 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010104 endif
10105
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010106 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010107 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010108" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10109 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010110 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010111" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10112 else
10113" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10114" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10115" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10116" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010117 endif
10118
10119 " record previous current directory
10120 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010121" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010122
10123 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010124" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10125" 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 +010010126 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010127" 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 +020010128 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010129" 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 +000010130
10131 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010132" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010133 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010134" 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 +010010135 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010136" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010137 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10138 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010139" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010140" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010141
Bram Moolenaar8d043172014-01-23 14:24:41 +010010142 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010143" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10144" 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 +010010145" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10146 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010147 unlet s:treecurpos
10148 endif
10149
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010150" 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>"))
10151" 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 +000010152" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10153endfun
10154
10155" ---------------------------------------------------------------------
10156" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010157fun! s:SetupNetrwStatusLine(statline)
10158" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10159
10160 if !exists("s:netrw_setup_statline")
10161 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010162" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010163
10164 if !exists("s:netrw_users_stl")
10165 let s:netrw_users_stl= &stl
10166 endif
10167 if !exists("s:netrw_users_ls")
10168 let s:netrw_users_ls= &laststatus
10169 endif
10170
10171 " set up User9 highlighting as needed
10172 let keepa= @a
10173 redir @a
10174 try
10175 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010176 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010177 if &bg == "dark"
10178 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10179 else
10180 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10181 endif
10182 endtry
10183 redir END
10184 let @a= keepa
10185 endif
10186
10187 " set up status line (may use User9 highlighting)
10188 " insure that windows have a statusline
10189 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010190 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010191 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010192" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010193 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010194
10195" call Dret("SetupNetrwStatusLine : stl=".&stl)
10196endfun
10197
Bram Moolenaar85850f32019-07-19 22:05:51 +020010198" =========================================
10199" Remote Directory Browsing Support: {{{1
10200" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010201
10202" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010203" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10204" This function assumes that a long listing will be received. Size, time,
10205" and reverse sorts will be requested of the server but not otherwise
10206" enforced here.
10207fun! s:NetrwRemoteFtpCmd(path,listcmd)
10208" 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 +010010209" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010210 " sanity check: {{{3
10211 if !exists("w:netrw_method")
10212 if exists("b:netrw_method")
10213 let w:netrw_method= b:netrw_method
10214 else
10215 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10216" call Dret("NetrwRemoteFtpCmd")
10217 return
10218 endif
10219 endif
10220
10221 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10222 let ffkeep= &ff
10223 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010224" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010225
10226 " clear off any older non-banner lines " {{{3
10227 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010228" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10229 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010230
10231 ".........................................
10232 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10233 " ftp + <.netrc>: Method #2
10234 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010235 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010236 endif
10237 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010238 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010239" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010240 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010241 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010242" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010243 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010244" 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>"))
10245 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 +010010246 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010247" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10248 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 +010010249 endif
10250
10251 ".........................................
10252 elseif w:netrw_method == 3 " {{{3
10253 " ftp + machine,id,passwd,filename: Method #3
10254 setl ff=unix
10255 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010256 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010257 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010258 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010259 endif
10260
10261 " handle userid and password
10262 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010263" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010264 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10265 call NetUserPass("ftp:".host)
10266 endif
10267 if exists("g:netrw_uid") && g:netrw_uid != ""
10268 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010269 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010270 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010271 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010272 endif
10273 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010274 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010275 endif
10276 endif
10277
10278 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010279 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010280 endif
10281 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010282 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010283" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010284 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010285 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010286
10287 " perform ftp:
10288 " -i : turns off interactive prompting from ftp
10289 " -n unix : DON'T use <.netrc>, even though it exists
10290 " -n win32: quit being obnoxious about password
10291 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010292" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010293 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010294" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010295" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10296" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010297 endif
10298
10299 ".........................................
10300 elseif w:netrw_method == 9 " {{{3
10301 " sftp username@machine: Method #9
10302 " s:netrw_sftp_cmd
10303 setl ff=unix
10304
10305 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010306 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010307" call Dret("NetrwRemoteFtpCmd")
10308 return
10309
10310 ".........................................
10311 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010312 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010313 endif
10314
10315 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010316 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010317 sil! NetrwKeepj %s/\r$//e
10318 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010319 endif
10320 if a:listcmd == "dir"
10321 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010322 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10323 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10324 NetrwKeepj call histdel("/",-1)
10325 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010326 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 +010010327 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10328 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010329 endif
10330 endif
10331
10332 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10333 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010334 exe 'NetrwKeepj '.w:netrw_bannercnt
10335 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010336 endif
10337 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010338 exe 'NetrwKeepj '.w:netrw_bannercnt
10339 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010340 endif
10341
10342 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010343 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010344" call Dret("NetrwRemoteFtpCmd")
10345endfun
10346
10347" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010348" s:NetrwRemoteListing: {{{2
10349fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010350" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010351
Bram Moolenaara6878372014-03-22 21:02:50 +010010352 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10353 let w:netrw_bannercnt= s:bannercnt
10354 endif
10355 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010356 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010357 endif
10358
Bram Moolenaar446cb832008-06-24 21:56:24 +000010359 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010360
Bram Moolenaar446cb832008-06-24 21:56:24 +000010361 " sanity check:
10362 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010363" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010364 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010365" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010366 if !exists("g:netrw_quiet")
10367 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10368 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010369 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010370" call Dret("s:NetrwRemoteListing -1")
10371 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010372 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010373
Bram Moolenaar8d043172014-01-23 14:24:41 +010010374 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010375" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010376 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010377 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010378 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 +000010379 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010380 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 +000010381 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010382 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010383
Bram Moolenaar85850f32019-07-19 22:05:51 +020010384 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010385" call Dret("s:NetrwRemoteListing -1")
10386 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010387 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010388" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010389
Bram Moolenaar446cb832008-06-24 21:56:24 +000010390 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010391" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010392 let w:netrw_method= b:netrw_method
10393 endif
10394
Bram Moolenaar13600302014-05-22 18:26:40 +020010395 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010396 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010397" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010398 let s:method = "ftp"
10399 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010400 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010401 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010402 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010403 let listcmd= g:netrw_ftp_sizelist_cmd
10404 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010405" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010406 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010407" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010408
Bram Moolenaara6878372014-03-22 21:02:50 +010010409 " report on missing file or directory messages
10410 if search('[Nn]o such file or directory\|Failed to change directory')
10411 let mesg= getline(".")
10412 if exists("w:netrw_bannercnt")
10413 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010414 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010415 setl noma
10416 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010417 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010418 call netrw#ErrorMsg(s:WARNING,mesg,96)
10419" call Dret("s:NetrwRemoteListing : -1")
10420 return -1
10421 endif
10422
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010423 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 +000010424 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010425" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010426 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010427
10428 " cleanup
10429 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010430 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10431 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010432 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010433 sil! NetrwKeepj %s/\r$//e
10434 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010435
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010436 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010437 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010438 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010439 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010440" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010441 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010442" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010443 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010444 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010445 exe "sil! NetrwKeepj ".line1
10446 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010448" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010449 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010450" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010451 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10452 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010453 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010454" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010455 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10456 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10457 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10458 NetrwKeepj call histdel("/",-1)
10459 NetrwKeepj call histdel("/",-1)
10460 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461 endif
10462 endif
10463
Bram Moolenaar13600302014-05-22 18:26:40 +020010464 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010465 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010466" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010467 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010468" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010469 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010470" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10471 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010472 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010473 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10474 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10475 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10476 NetrwKeepj call histdel("/",-1)
10477 NetrwKeepj call histdel("/",-1)
10478 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010480 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10481 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010482 endif
10483 else
10484 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010485" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010486 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010487 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010488" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10489 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10490" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010491 endif
10492 endif
10493
10494 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010495 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010496" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010497 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10498 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010499 endif
10500 endif
10501
10502 if w:netrw_liststyle == s:LONGLIST
10503 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010504" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010505
10506 if s:method == "ftp"
10507 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010508 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010509 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010510 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010511 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010512 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010513 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010514 sil! NetrwKeepj 1
10515 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010516 let line2= line(".")
10517 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010518 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010519 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010520 endif
10521 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010522 exe "sil! NetrwKeepj ".line1
10523 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010524 endif
10525
10526 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010527" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010528 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 +000010529 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010530" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010531 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010532 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010533 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10534 NetrwKeepj call histdel("/",-1)
10535 NetrwKeepj call histdel("/",-1)
10536 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010537 endif
10538 endif
10539
10540" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010541" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010542" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010543
10544" call Dret("s:NetrwRemoteListing 0")
10545 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010546endfun
10547
Bram Moolenaar446cb832008-06-24 21:56:24 +000010548" ---------------------------------------------------------------------
10549" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10550fun! s:NetrwRemoteRm(usrhost,path) range
10551" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010552" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010553 let svpos= winsaveview()
10554" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010555
10556 let all= 0
10557 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10558 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010559" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010560 for fname in s:netrwmarkfilelist_{bufnr("%")}
10561 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010562 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010563 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010564 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010565 let all= 1
10566 endif
10567 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010568 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010569
10570 else
10571 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010572" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573
10574 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010575 let keepsol = &l:sol
10576 setl nosol
10577 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578
10579 " remove multiple files and directories
10580 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010581 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010582 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010583 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010584 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010585 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010586 let all= 1
10587 endif
10588 let ctr= ctr + 1
10589 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010590 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010591 endif
10592
10593 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010594" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010595 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010596" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10597 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010598
10599" call Dret("s:NetrwRemoteRm")
10600endfun
10601
10602" ---------------------------------------------------------------------
10603" s:NetrwRemoteRmFile: {{{2
10604fun! s:NetrwRemoteRmFile(path,rmfile,all)
10605" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10606
10607 let all= a:all
10608 let ok = ""
10609
10610 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10611 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010612" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010613 if !all
10614 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010615" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010616 call inputsave()
10617 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10618 call inputrestore()
10619 echohl NONE
10620 if ok == ""
10621 let ok="no"
10622 endif
10623 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010624 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010625 let all= 1
10626 endif
10627 endif
10628
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010629 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010630" 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 +000010631 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010632" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010633 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010634 if path =~ '^\a\{3,}://'
10635 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010636 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010637 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010638 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10639 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010640" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010641 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010642" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010643 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010644 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010645 let ok="q"
10646 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010647 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010648" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10649" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10650" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010651 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010652 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010654 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010655 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010656" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010657 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010658 if v:shell_error != 0
10659 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010660 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 +010010661 else
10662 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10663 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010664 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010665 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010666 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010667" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010668 endif
10669 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010670 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010671" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010672 endif
10673
10674 else
10675 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010676" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010677 if !all
10678 call inputsave()
10679 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10680 call inputrestore()
10681 if ok == ""
10682 let ok="no"
10683 endif
10684 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010685 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010686 let all= 1
10687 endif
10688 endif
10689
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010690 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010691 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010692 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010693 else
10694 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010695 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10696" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010697 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010698" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010699
10700 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010701" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10702 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10703" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010704 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010705" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010706
10707 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010708 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010709 endif
10710 endif
10711 endif
10712
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010713 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010714" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010715 endif
10716 endif
10717
10718" call Dret("s:NetrwRemoteRmFile ".ok)
10719 return ok
10720endfun
10721
10722" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010723" s:NetrwRemoteRename: rename a remote file or directory {{{2
10724fun! s:NetrwRemoteRename(usrhost,path) range
10725" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10726
10727 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010728 let svpos = winsaveview()
10729" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010730 let ctr = a:firstline
10731 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10732
10733 " rename files given by the markfilelist
10734 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10735 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010736" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010737 if exists("subfrom")
10738 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010739" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010740 else
10741 call inputsave()
10742 let newname= input("Moving ".oldname." to : ",oldname)
10743 call inputrestore()
10744 if newname =~ '^s/'
10745 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10746 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10747 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010748" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010749 endif
10750 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010751
Bram Moolenaar446cb832008-06-24 21:56:24 +000010752 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010753 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010754 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010755 let oldname= s:ShellEscape(a:path.oldname)
10756 let newname= s:ShellEscape(a:path.newname)
10757" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010758 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010759 endif
10760
10761 endfor
10762 call s:NetrwUnMarkFile(1)
10763
10764 else
10765
10766 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010767 let keepsol= &l:sol
10768 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010769 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010770 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010771
10772 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010773" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010774
10775 call inputsave()
10776 let newname= input("Moving ".oldname." to : ",oldname)
10777 call inputrestore()
10778
10779 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10780 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10781 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010782 let oldname= s:ShellEscape(a:path.oldname)
10783 let newname= s:ShellEscape(a:path.newname)
10784" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010785 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010786 endif
10787
10788 let ctr= ctr + 1
10789 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010790 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010791 endif
10792
10793 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010794 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010795" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10796 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010797
10798" call Dret("NetrwRemoteRename")
10799endfun
10800
Bram Moolenaar85850f32019-07-19 22:05:51 +020010801" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010802" Local Directory Browsing Support: {{{1
10803" ==========================================
10804
10805" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010806" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010807" Should accept: file://localhost/etc/fstab
10808" file:///etc/fstab
10809" file:///c:/WINDOWS/clock.avi
10810" file:///c|/WINDOWS/clock.avi
10811" file://localhost/c:/WINDOWS/clock.avi
10812" file://localhost/c|/WINDOWS/clock.avi
10813" file://c:/foo.txt
10814" file:///c:/foo.txt
10815" 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 +020010816fun! netrw#FileUrlEdit(fname)
10817" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010818 let fname = a:fname
10819 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010820" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010821 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010822" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010823 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010824 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010825 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010826" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010827 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010828" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010829 endif
10830 endif
10831 let fname2396 = netrw#RFC2396(fname)
10832 let fname2396e= fnameescape(fname2396)
10833 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010834 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010835" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010836 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010837" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010838 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10839 endif
10840 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010841
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010842" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10843" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010844 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010845 exe 'NetrwKeepj keepalt edit '.plainfname
10846 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10847
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010848" 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 +020010849" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010850 exe "sil doau BufReadPost ".fname2396e
10851endfun
10852
10853" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010854" netrw#LocalBrowseCheck: {{{2
10855fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010856 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010857 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10858 "
10859 " unfortunate interaction -- split window debugging can't be used here, must use
10860 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10861 " another call to LocalBrowseCheck() when attempts to write
10862 " to the DBG buffer are made.
10863 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010864 " The &ft == "netrw" test was installed because the BufEnter event
10865 " would hit when re-entering netrw windows, creating unexpected
10866 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010867" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010868" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010869" 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 +010010870 " getting E930: Cannot use :redir inside execute
10871"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010872" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10873" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010874
Bram Moolenaar97d62492012-11-15 21:28:22 +010010875 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010876 if isdirectory(s:NetrwFile(a:dirname))
10877" 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 +010010878
Bram Moolenaar97d62492012-11-15 21:28:22 +010010879 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010880" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10881" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010882 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010883
Bram Moolenaar446cb832008-06-24 21:56:24 +000010884 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010885" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010886 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010887
Bram Moolenaar5c736222010-01-06 20:54:52 +010010888 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010889" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010890 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010891 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010892 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010893" 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 +010010894" call Dret("netrw#LocalBrowseCheck")
10895 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010896 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010897
Bram Moolenaar85850f32019-07-19 22:05:51 +020010898 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010899 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10900 " AND IF the listing style is not a tree listing
10901 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010902" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010903 let ibuf = 1
10904 let buflast = bufnr("$")
10905 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010906 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10907 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010908 endif
10909 let ibuf= ibuf + 1
10910 endwhile
10911 endif
10912 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010913" 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>"))
10914" 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 +000010915 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010916" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010917endfun
10918
10919" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010920" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010921" performed any shell command. The idea is to cause all local-browsing
10922" buffers to be refreshed after a user has executed some shell command,
10923" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010924fun! s:LocalBrowseRefresh()
10925" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010926" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10927" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010928
Bram Moolenaar446cb832008-06-24 21:56:24 +000010929 " determine which buffers currently reside in a tab
10930 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010931" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010932 return
10933 endif
10934 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010935" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010936 return
10937 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010938 if !empty(getcmdwintype())
10939 " cannot move away from cmdline window, see :h E11
10940 return
10941 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010942 if exists("s:netrw_events") && s:netrw_events == 1
10943 " s:LocalFastBrowser gets called (indirectly) from a
10944 let s:netrw_events= 2
10945" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10946 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010947 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010948 let itab = 1
10949 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010950 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010951 while itab <= tabpagenr("$")
10952 let buftablist = buftablist + tabpagebuflist()
10953 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010954 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010955 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010956" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10957" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010958 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10959 " | refresh any netrw window
10960 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010961 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010962 let ibl = 0
10963 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010964" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10966 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010967 " (ibuf not shown in a current window AND
10968 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010969" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10970 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010971 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010972" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010973 continue
10974 elseif index(tabpagebuflist(),ibuf) != -1
10975 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010976" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010977 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010978 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010979 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10980 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10981 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10982 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010983" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010984 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10985 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10986 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010987 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010988 endif
10989 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010990" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010991 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010992" call Decho("restore window: win_gotoid(".curwinid.")")
10993 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010994 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010995
Bram Moolenaara6878372014-03-22 21:02:50 +010010996" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010997endfun
10998
10999" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011000" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11001"
11002" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011003" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011004" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11005" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011006" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011007"
11008" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11009" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011010" (re-using a buffer may not be as accurate)
11011"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011012" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011013" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11014" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11015" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11016" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011017fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011018" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11019" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11020" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11021" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011022
11023 " initialize browselist, a list of buffer numbers that the local browser has used
11024 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011025" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011026 let s:netrw_browselist= []
11027 endif
11028
11029 " append current buffer to fastbrowse list
11030 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011031" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011032 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011033" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011034 endif
11035
11036 " enable autocmd events to handle refreshing/removing local browser buffers
11037 " If local browse buffer is currently showing: refresh it
11038 " If local browse buffer is currently hidden : wipe it
11039 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11040 " =1 : medium speed, re-use directory listing for remote only
11041 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011042 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11043 let s:netrw_events= 1
11044 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011045 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011046 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011047" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011048 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011049 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011050" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011051 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011052 endif
11053 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011054
11055 " user must have changed fastbrowse to its fast setting, so remove
11056 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011057 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011058" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011059 unlet s:netrw_events
11060 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011061 au!
11062 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011063 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011064 endif
11065
Bram Moolenaar85850f32019-07-19 22:05:51 +020011066" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011067endfun
11068
11069" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011070" s:LocalListing: does the job of "ls" for local directories {{{2
11071fun! s:LocalListing()
11072" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011073" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11074" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11075" 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 +010011076
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011077" 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
11078" 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
11079" 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 +010011080
11081 " get the list of files contained in the current directory
11082 let dirname = b:netrw_curdir
11083 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011084 let filelist = s:NetrwGlob(dirname,"*",0)
11085 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011086" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011087
Nir Lichtman1e34b952024-05-08 19:19:34 +020011088 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011089" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011090 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11091 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011092" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011093 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011094" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011095 endif
11096
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011097" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011098" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011099" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011100
11101 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11102 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11103 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011104" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11105" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011106 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011107" 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 +010011108
11109 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011110" call Decho(" ",'~'.expand("<slnum>"))
11111" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011112
11113 if getftype(filename) == "link"
11114 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011115" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011116 let pfile= filename."@"
11117
11118 elseif getftype(filename) == "socket"
11119 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011120" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011121 let pfile= filename."="
11122
11123 elseif getftype(filename) == "fifo"
11124 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011125" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011126 let pfile= filename."|"
11127
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011128 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011129 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011130" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011131 let pfile= filename."/"
11132
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011133 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011134 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011135 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11136 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011137" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011138 let pfile= filename."*"
11139 else
11140 " normal file
11141 let pfile= filename
11142 endif
11143 elseif executable(filename)
11144 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011145" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011146 let pfile= filename."*"
11147 else
11148 " normal file
11149 let pfile= filename
11150 endif
11151
11152 else
11153 " normal file
11154 let pfile= filename
11155 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011156" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011157
11158 if pfile =~ '//$'
11159 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011160" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011161 endif
11162 let pfile= strpart(pfile,dirnamelen)
11163 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011164" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11165" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011166
11167 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011168 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11169 let sz = getfsize(filename)
11170 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11171 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011172
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011173 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011174 let sz= s:NetrwHumanReadable(sz)
11175 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011176 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011177 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011178" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011179 endif
11180
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011181 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011182 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011183 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011184" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011185" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011186 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011187 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011188" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011189 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011190 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011191
11192 elseif g:netrw_sort_by =~ "^s"
11193 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011194" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011195" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011196 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011197 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011198" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011199 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011200 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011201
11202 else
11203 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011204" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011205" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011206 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011207 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011208" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011209 endfor
11210
11211 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011212 sil! NetrwKeepj g/^$/d
11213 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011214 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011215" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011216 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11217
11218" call Dret("s:LocalListing")
11219endfun
11220
11221" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011222" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11223fun! s:NetrwLocalExecute(cmd)
11224" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11225 let ykeep= @@
11226 " sanity check
11227 if !executable(a:cmd)
11228 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11229 let @@= ykeep
11230" call Dret("s:NetrwLocalExecute")
11231 return
11232 endif
11233
11234 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011235" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011236 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011237" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011238
11239 " strip any ansi escape sequences off
11240 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11241
11242 " show user the result(s)
11243 echomsg result
11244 let @@= ykeep
11245
11246" call Dret("s:NetrwLocalExecute")
11247endfun
11248
11249" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011250" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011251fun! s:NetrwLocalRename(path) range
11252" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11253
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011254 if !exists("w:netrw_bannercnt")
11255 let w:netrw_bannercnt= b:netrw_bannercnt
11256 endif
11257
Bram Moolenaar97d62492012-11-15 21:28:22 +010011258 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011259 let ykeep = @@
11260 let ctr = a:firstline
11261 let svpos = winsaveview()
11262 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011263" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011264
11265 " rename files given by the markfilelist
11266 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11267 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011268" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011269 if exists("subfrom")
11270 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011271" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011272 else
11273 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011274 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011275 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011276 if newname =~ ''
11277 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11278 let newname = substitute(newname,'^.*','','')
11279 elseif newname =~ ''
11280 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11281 let newname = substitute(newname,'[^/]*','','')
11282 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011283 if newname =~ '^s/'
11284 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11285 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011286" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011287 let newname = substitute(oldname,subfrom,subto,'')
11288 endif
11289 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011290 if !all && filereadable(newname)
11291 call inputsave()
11292 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11293 call inputrestore()
11294 if response == "all"
11295 let all= 1
11296 elseif response != "y" && response != "yes"
11297 " refresh the directory
11298" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11299 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11300" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11301 NetrwKeepj call winrestview(svpos)
11302 let @@= ykeep
11303" call Dret("NetrwLocalRename")
11304 return
11305 endif
11306 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011307 call rename(oldname,newname)
11308 endfor
11309 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011310
Bram Moolenaar97d62492012-11-15 21:28:22 +010011311 else
11312
11313 " attempt to rename files/directories
11314 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011315 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011316
11317 " sanity checks
11318 if line(".") < w:netrw_bannercnt
11319 let ctr= ctr + 1
11320 continue
11321 endif
11322 let curword= s:NetrwGetWord()
11323 if curword == "./" || curword == "../"
11324 let ctr= ctr + 1
11325 continue
11326 endif
11327
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011328 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011329 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011330" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011331
11332 call inputsave()
11333 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11334 call inputrestore()
11335
11336 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011337" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011338
11339 let ctr= ctr + 1
11340 endwhile
11341 endif
11342
11343 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011344" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011345 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011346" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11347 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011348 let @@= ykeep
11349
11350" call Dret("NetrwLocalRename")
11351endfun
11352
11353" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011354" s:NetrwLocalRm: {{{2
11355fun! s:NetrwLocalRm(path) range
11356" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011357" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011358
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011359 if !exists("w:netrw_bannercnt")
11360 let w:netrw_bannercnt= b:netrw_bannercnt
11361 endif
11362
Bram Moolenaar446cb832008-06-24 21:56:24 +000011363 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011364 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011365 let ret = 0
11366 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011367 let svpos = winsaveview()
11368" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011369
11370 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11371 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011372" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011373 for fname in s:netrwmarkfilelist_{bufnr("%")}
11374 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011375 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011376 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011377 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011378 let all= 1
11379 endif
11380 endfor
11381 call s:NetrwUnMarkFile(1)
11382
11383 else
11384 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011385" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011386
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011387 let keepsol= &l:sol
11388 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011389 let ctr = a:firstline
11390 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011391 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011392
11393 " sanity checks
11394 if line(".") < w:netrw_bannercnt
11395 let ctr= ctr + 1
11396 continue
11397 endif
11398 let curword= s:NetrwGetWord()
11399 if curword == "./" || curword == "../"
11400 let ctr= ctr + 1
11401 continue
11402 endif
11403 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011404 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011405 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011406 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011407 let all= 1
11408 endif
11409 let ctr= ctr + 1
11410 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011411 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011412 endif
11413
11414 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011415" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011416 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011417 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011418" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11419 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011420 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011421 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011422
11423" call Dret("s:NetrwLocalRm")
11424endfun
11425
11426" ---------------------------------------------------------------------
11427" s:NetrwLocalRmFile: remove file fname given the path {{{2
11428" Give confirmation prompt unless all==1
11429fun! s:NetrwLocalRmFile(path,fname,all)
11430" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011431
Bram Moolenaar446cb832008-06-24 21:56:24 +000011432 let all= a:all
11433 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011434 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011435 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11436" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011437
11438 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11439 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011440" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011441 if !all
11442 echohl Statement
11443 call inputsave()
11444 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11445 call inputrestore()
11446 echohl NONE
11447 if ok == ""
11448 let ok="no"
11449 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011450" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011451 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011452" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011453 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011454 let all= 1
11455 endif
11456 endif
11457
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011458 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011459 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011460" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011461 endif
11462
11463 else
11464 " attempt to remove directory
11465 if !all
11466 echohl Statement
11467 call inputsave()
11468 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11469 call inputrestore()
11470 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11471 if ok == ""
11472 let ok="no"
11473 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011474 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011475 let all= 1
11476 endif
11477 endif
11478 let rmfile= substitute(rmfile,'[\/]$','','e')
11479
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011480 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar71badf92023-04-22 22:40:14 +010011481 if delete(rmfile,"d")
11482 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011483 endif
11484 endif
11485 endif
11486
11487" call Dret("s:NetrwLocalRmFile ".ok)
11488 return ok
11489endfun
11490
Bram Moolenaar85850f32019-07-19 22:05:51 +020011491" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011492" Support Functions: {{{1
11493
Bram Moolenaar488c6512005-08-11 20:09:58 +000011494" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011495" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11496" 0: marked file list of current buffer
11497" 1: marked file target
11498fun! netrw#Access(ilist)
11499 if a:ilist == 0
11500 if exists("s:netrwmarkfilelist_".bufnr('%'))
11501 return s:netrwmarkfilelist_{bufnr('%')}
11502 else
11503 return "no-list-buf#".bufnr('%')
11504 endif
11505 elseif a:ilist == 1
11506 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011507 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011508endfun
11509
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011510" ---------------------------------------------------------------------
11511" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11512fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011513 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011514endfun
11515
Bram Moolenaara6878372014-03-22 21:02:50 +010011516" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011517" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11518" I expect this function to be used in
11519" :PChkAssert netrw#Expose("netrwmarkfilelist")
11520" for example.
11521fun! netrw#Expose(varname)
11522" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011523 if exists("s:".a:varname)
11524 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011525" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011526 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011527" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011528 if type(retval) == 3
11529 let retval = copy(retval)
11530 let i = 0
11531 while i < len(retval)
11532 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11533 let i = i + 1
11534 endwhile
11535 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011536" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011537 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011538 else
11539" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011540 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011541 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011542" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011543 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011544 endif
11545
11546" call Dret("netrw#Expose ".string(retval))
11547 return retval
11548endfun
11549
11550" ---------------------------------------------------------------------
11551" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11552fun! netrw#Modify(varname,newvalue)
11553" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11554 exe "let s:".a:varname."= ".string(a:newvalue)
11555" call Dret("netrw#Modify")
11556endfun
11557
11558" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011559" netrw#RFC2396: converts %xx into characters {{{2
11560fun! netrw#RFC2396(fname)
11561" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011562 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011563" call Dret("netrw#RFC2396 ".fname)
11564 return fname
11565endfun
11566
11567" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011568" netrw#UserMaps: supports user-specified maps {{{2
11569" see :help function()
11570"
11571" g:Netrw_UserMaps is a List with members such as:
11572" [[keymap sequence, function reference],...]
11573"
11574" The referenced function may return a string,
11575" refresh : refresh the display
11576" -other- : this string will be executed
11577" or it may return a List of strings.
11578"
11579" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011580" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011581" Related functions:
11582" netrw#Expose(varname) -- see s:varname variables
11583" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11584" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11585fun! netrw#UserMaps(islocal)
11586" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11587" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11588
11589 " set up usermaplist
11590 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11591" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11592 for umap in g:Netrw_UserMaps
11593" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11594" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11595 " if umap[0] is a string and umap[1] is a string holding a function name
11596 if type(umap[0]) == 1 && type(umap[1]) == 1
11597" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11598 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11599 else
11600 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11601 endif
11602 endfor
11603 endif
11604" call Dret("netrw#UserMaps")
11605endfun
11606
11607" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011608" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11609fun! netrw#WinPath(path)
11610" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011611 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011612 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011613 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011614 " remove trailing slash (Win95)
11615 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11616 " remove escaped spaces
11617 let path = substitute(path, '\ ', ' ', 'g')
11618 " convert slashes to backslashes
11619 let path = substitute(path, '/', '\', 'g')
11620 else
11621 let path= a:path
11622 endif
11623" call Dret("netrw#WinPath <".path.">")
11624 return path
11625endfun
11626
11627" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011628" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11629" cb : bl2mf=0 add marked files to buffer list
11630" cB : bl2mf=1 use bufferlist to mark files
11631" (mnemonic: cb = copy (marked files) to buffer list)
11632fun! s:NetrwBadd(islocal,bl2mf)
11633" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11634 if a:bl2mf
11635 " cB: add buffer list to marked files
11636 redir => bufl
11637 ls
11638 redir END
11639 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11640 for fname in bufl
11641 call s:NetrwMarkFile(a:islocal,fname)
11642 endfor
11643 else
11644 " cb: add marked files to buffer list
11645 for fname in s:netrwmarkfilelist_{bufnr("%")}
11646" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11647 exe "badd ".fnameescape(fname)
11648 endfor
11649 let curbufnr = bufnr("%")
11650 let curdir = s:NetrwGetCurdir(a:islocal)
11651 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11652 endif
11653" call Dret("s:NetrwBadd")
11654endfun
11655
11656" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011657" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11658fun! s:ComposePath(base,subdir)
11659" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11660
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011661 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011662" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011663 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011664 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011665 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011666 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011667 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011668 endif
11669
Bram Moolenaar85850f32019-07-19 22:05:51 +020011670 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011671 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011672" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011673 let ret= a:subdir
11674
Nir Lichtman1e34b952024-05-08 19:19:34 +020011675 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011676" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011677 if a:base =~ '[/\\]$'
11678 let ret= a:base.a:subdir
11679 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011680 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011681 endif
11682
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011683 elseif a:base =~ '^\a\{3,}://'
11684" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011685 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11686 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11687 if a:subdir == '../'
11688 if curpath =~ '[^/]/[^/]\+/$'
11689 let curpath= substitute(curpath,'[^/]\+/$','','')
11690 else
11691 let curpath=""
11692 endif
11693 let ret= urlbase.curpath
11694 else
11695 let ret= urlbase.curpath.a:subdir
11696 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011697" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11698" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11699" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011700
11701 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011702" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011703 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11704 if a:base =~ '^//'
11705 " keeping initial '//' for the benefit of network share listing support
11706 let ret= '/'.ret
11707 endif
11708 let ret= simplify(ret)
11709 endif
11710
11711" call Dret("s:ComposePath ".ret)
11712 return ret
11713endfun
11714
11715" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011716" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11717" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11718fun! s:DeleteBookmark(fname)
11719" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11720 call s:MergeBookmarks()
11721
11722 if exists("g:netrw_bookmarklist")
11723 let indx= index(g:netrw_bookmarklist,a:fname)
11724 if indx == -1
11725 let indx= 0
11726 while indx < len(g:netrw_bookmarklist)
11727 if g:netrw_bookmarklist[indx] =~ a:fname
11728 call remove(g:netrw_bookmarklist,indx)
11729 let indx= indx - 1
11730 endif
11731 let indx= indx + 1
11732 endwhile
11733 else
11734 " remove exact match
11735 call remove(g:netrw_bookmarklist,indx)
11736 endif
11737 endif
11738
11739" call Dret("s:DeleteBookmark")
11740endfun
11741
11742" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011743" s:FileReadable: o/s independent filereadable {{{2
11744fun! s:FileReadable(fname)
11745" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11746
11747 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011748 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011749 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011750 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011751 endif
11752
11753" call Dret("s:FileReadable ".ret)
11754 return ret
11755endfun
11756
11757" ---------------------------------------------------------------------
11758" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11759" Places correct suffix on end of temporary filename,
11760" using the suffix provided with fname
11761fun! s:GetTempfile(fname)
11762" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11763
11764 if !exists("b:netrw_tmpfile")
11765 " get a brand new temporary filename
11766 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011767" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011768
Bram Moolenaarc236c162008-07-13 17:41:49 +000011769 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011770" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011771
Bram Moolenaar9964e462007-05-05 17:54:07 +000011772 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011773 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11774" 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 +010011775 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011776" call Dret("s:GetTempfile getcwd<".getcwd().">")
11777 return ""
11778 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011779
Bram Moolenaar9964e462007-05-05 17:54:07 +000011780 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011781 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011782" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011783
Bram Moolenaar9964e462007-05-05 17:54:07 +000011784 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011785 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011786 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011787 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011788 if !exists("+shellslash") || !&ssl
11789 let tmpfile = substitute(tmpfile,'/','\','g')
11790 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011791 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011792 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011793 endif
11794 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011795" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011796 else
11797 " re-use temporary filename
11798 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011799" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011800 endif
11801
11802 " use fname's suffix for the temporary file
11803 if a:fname != ""
11804 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011805" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011806 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011807 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011808 elseif a:fname =~ '.txz$'
11809 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011810 else
11811 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11812 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011813" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011814 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011815" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011816 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011817" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011818 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11819 endif
11820 endif
11821
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011822" 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 +000011823" call Dret("s:GetTempfile <".tmpfile.">")
11824 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011825endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011826
11827" ---------------------------------------------------------------------
11828" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011829" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011830fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011831" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011832 if s:user == ""
11833 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11834 else
11835 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11836 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011837 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011838 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011839 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011840 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011841 else
11842 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11843 endif
11844" call Dret("s:MakeSshCmd <".sshcmd.">")
11845 return sshcmd
11846endfun
11847
11848" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011849" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11850fun! s:MakeBookmark(fname)
11851" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11852
11853 if !exists("g:netrw_bookmarklist")
11854 let g:netrw_bookmarklist= []
11855 endif
11856
11857 if index(g:netrw_bookmarklist,a:fname) == -1
11858 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011859 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011860 call add(g:netrw_bookmarklist,a:fname.'/')
11861 elseif a:fname !~ '/'
11862 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11863 else
11864 call add(g:netrw_bookmarklist,a:fname)
11865 endif
11866 call sort(g:netrw_bookmarklist)
11867 endif
11868
11869" call Dret("s:MakeBookmark")
11870endfun
11871
11872" ---------------------------------------------------------------------
11873" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11874fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011875" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011876 " get bookmarks from .netrwbook file
11877 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011878 if filereadable(s:NetrwFile(savefile))
11879" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011880 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011881" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011882 NetrwKeepj call delete(savefile)
11883 endif
11884" call Dret("s:MergeBookmarks")
11885endfun
11886
11887" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011888" s:NetrwBMShow: {{{2
11889fun! s:NetrwBMShow()
11890" call Dfunc("s:NetrwBMShow()")
11891 redir => bmshowraw
11892 menu
11893 redir END
11894 let bmshowlist = split(bmshowraw,'\n')
11895 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011896 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011897 if bmshowfuncs != []
11898 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011899 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011900 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011901 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011902 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011903 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011904" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11905endfun
11906
11907" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011908" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011909fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011910 if !exists("w:netrw_liststyle")
11911 let w:netrw_liststyle= g:netrw_liststyle
11912 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011913" 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 +020011914
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011915" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11916
Bram Moolenaaradc21822011-04-01 18:03:16 +020011917 if &ft != "netrw"
11918 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11919 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011920" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011921
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011922 elseif g:netrw_cursor == 8
11923 if w:netrw_liststyle == s:WIDELIST
11924 setl cursorline
11925 setl cursorcolumn
11926 else
11927 setl cursorline
11928 endif
11929 elseif g:netrw_cursor == 7
11930 setl cursorline
11931 elseif g:netrw_cursor == 6
11932 if w:netrw_liststyle == s:WIDELIST
11933 setl cursorline
11934 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011935 elseif g:netrw_cursor == 4
11936 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011937" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011938 setl cursorline
11939 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011940
11941 elseif g:netrw_cursor == 3
11942 " thin-long-tree: cursorline, user's cursorcolumn
11943 " wide : cursorline, cursorcolumn
11944 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011945" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011946 setl cursorline
11947 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011948 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011949" 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 +020011950 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011951 endif
11952
11953 elseif g:netrw_cursor == 2
11954 " thin-long-tree: cursorline, user's cursorcolumn
11955 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011956" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011957 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011958
11959 elseif g:netrw_cursor == 1
11960 " thin-long-tree: user's cursorline, user's cursorcolumn
11961 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011962 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011963" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011964 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011965 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011966" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011967 endif
11968
11969 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011970 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011971" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011972 let &l:cursorline = s:netrw_usercul
11973 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011974 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011975
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011976" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011977" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011978endfun
11979
11980" ---------------------------------------------------------------------
11981" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11982fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011983" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011984 if exists("s:netrw_usercul")
11985 let &l:cursorline = s:netrw_usercul
11986 endif
11987 if exists("s:netrw_usercuc")
11988 let &l:cursorcolumn = s:netrw_usercuc
11989 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011990" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011991" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11992endfun
11993
11994" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011995" s:NetrwDelete: Deletes a file. {{{2
11996" Uses Steve Hall's idea to insure that Windows paths stay
11997" acceptable. No effect on Unix paths.
11998" Examples of use: let result= s:NetrwDelete(path)
11999fun! s:NetrwDelete(path)
12000" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12001
Bram Moolenaar5c736222010-01-06 20:54:52 +010012002 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012003 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012004 if exists("+shellslash")
12005 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012006 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012007 let result = delete(path)
12008 let &shellslash = sskeep
12009 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012010" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012011 let result= delete(path)
12012 endif
12013 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012014" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012015 let result= delete(path)
12016 endif
12017 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012018 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012019 endif
12020
12021" call Dret("s:NetrwDelete ".result)
12022 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012023endfun
12024
12025" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012026" s:NetrwBufRemover: removes a buffer that: {{{2s
12027" has buffer-id > 1
12028" is unlisted
12029" is unnamed
12030" does not appear in any window
12031fun! s:NetrwBufRemover(bufid)
12032" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12033" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12034" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12035" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12036" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12037
yasuda4dbb2662023-10-04 20:50:35 +020012038 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012039" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012040 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012041 endif
12042
12043" call Dret("s:NetrwBufRemover")
12044endfun
12045
12046" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012047" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012048fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012049" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012050" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012051
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012052 " Clean out the last buffer:
12053 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12054 " If so, delete it.
12055 call s:NetrwBufRemover(bufnr("$"))
12056
Bram Moolenaar446cb832008-06-24 21:56:24 +000012057 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012058" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012059 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12060 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12061 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12062 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12063 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12064 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12065 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12066 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12067 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12068 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12069 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12070 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12071 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12072 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12073 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12074 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12075
Bram Moolenaar85850f32019-07-19 22:05:51 +020012076 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012077" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012078 " when tree listing uses file TreeListing... a new buffer is made.
12079 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012080 " COMBAK: this causes a problem, see P43
12081" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012082 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012083 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012084 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012085" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012086 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012087
Bram Moolenaar446cb832008-06-24 21:56:24 +000012088 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012089" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012090 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12091 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12092 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12093 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12094 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12095 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12096 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12097 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12098 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12099 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12100 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12101 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12102 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12103 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12104 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12105 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12106
Bram Moolenaar5c736222010-01-06 20:54:52 +010012107 if a:0 > 0
12108 let b:netrw_curdir= a:1
12109 if b:netrw_curdir =~ '/$'
12110 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012111 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012112 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012113 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012114 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12115 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012116 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012117 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012118 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012119 endif
12120 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012121 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12122 let &l:bexpr = "netrw#BalloonHelp()"
12123 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012124
Bram Moolenaar8d043172014-01-23 14:24:41 +010012125" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012126endfun
12127
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012128" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012129" s:NetrwExe: executes a string using "!" {{{2
12130fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012131" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012132 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012133" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012134 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12135 set shell& shellcmdflag& shellxquote& shellxescape&
12136 set shellquote& shellpipe& shellredir& shellslash&
12137 exe a:cmd
12138 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12139 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012140" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012141 exe a:cmd
12142 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012143 if v:shell_error
12144 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12145 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012146" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012147endfun
12148
12149" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012150" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12151fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012152 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012153" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012154 let curbuf = bufnr("%")
12155 let curwin = winnr()
12156 let iwin = 1
12157 while iwin <= winnr("$")
12158 exe iwin."wincmd w"
12159 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12160 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12161 let winvars= w:
12162 break
12163 endif
12164 let iwin= iwin + 1
12165 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012166 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012167 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012168" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012169 for k in keys(winvars)
12170 let w:{k}= winvars[k]
12171 endfor
12172 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012173" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012174 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012175endfun
12176
Bram Moolenaara6878372014-03-22 21:02:50 +010012177" ---------------------------------------------------------------------
12178" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012179" Returns: 0=success
12180" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012181fun! s:NetrwLcd(newdir)
12182" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012183" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012184
Bram Moolenaar85850f32019-07-19 22:05:51 +020012185 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012186 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012187 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012188 catch /^Vim\%((\a\+)\)\=:E344/
12189 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12190 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012191 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012192 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12193 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012194 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012195 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12196 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012197 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012198 endif
12199 endif
12200 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012201 let err472= 1
12202 endtry
12203
12204 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012205 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12206 if exists("w:netrw_prvdir")
12207 let a:newdir= w:netrw_prvdir
12208 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012209 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012210" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012211 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012212" 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 +010012213 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012214 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012215" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12216 return -1
12217 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012218
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012219" call Decho("getcwd <".getcwd().">")
12220" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012221" call Dret("s:NetrwLcd 0")
12222 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012223endfun
12224
Bram Moolenaar9964e462007-05-05 17:54:07 +000012225" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012226" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12227" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12228fun! s:NetrwSaveWordPosn()
12229" call Dfunc("NetrwSaveWordPosn()")
12230 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12231" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12232endfun
12233
12234" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012235" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12236" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12237fun! s:NetrwHumanReadable(sz)
12238" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12239
12240 if g:netrw_sizestyle == 'h'
12241 if a:sz >= 1000000000
12242 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12243 elseif a:sz >= 10000000
12244 let sz = printf("%d",a:sz/1000000)."m"
12245 elseif a:sz >= 1000000
12246 let sz = printf("%.1f",a:sz/1000000.0)."m"
12247 elseif a:sz >= 10000
12248 let sz = printf("%d",a:sz/1000)."k"
12249 elseif a:sz >= 1000
12250 let sz = printf("%.1f",a:sz/1000.0)."k"
12251 else
12252 let sz= a:sz
12253 endif
12254
12255 elseif g:netrw_sizestyle == 'H'
12256 if a:sz >= 1073741824
12257 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12258 elseif a:sz >= 10485760
12259 let sz = printf("%d",a:sz/1048576)."M"
12260 elseif a:sz >= 1048576
12261 let sz = printf("%.1f",a:sz/1048576.0)."M"
12262 elseif a:sz >= 10240
12263 let sz = printf("%d",a:sz/1024)."K"
12264 elseif a:sz >= 1024
12265 let sz = printf("%.1f",a:sz/1024.0)."K"
12266 else
12267 let sz= a:sz
12268 endif
12269
12270 else
12271 let sz= a:sz
12272 endif
12273
12274" call Dret("s:NetrwHumanReadable ".sz)
12275 return sz
12276endfun
12277
12278" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012279" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12280" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12281fun! s:NetrwRestoreWordPosn()
12282" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012283 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012284" call Dret("NetrwRestoreWordPosn")
12285endfun
12286
12287" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012288" s:RestoreBufVars: {{{2
12289fun! s:RestoreBufVars()
12290" call Dfunc("s:RestoreBufVars()")
12291
12292 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12293 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12294 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12295 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12296 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12297 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12298
12299" call Dret("s:RestoreBufVars")
12300endfun
12301
12302" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012303" s:RemotePathAnalysis: {{{2
12304fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012305" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012306
Bram Moolenaara6878372014-03-22 21:02:50 +010012307 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012308 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012309 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012310 let s:user = substitute(a:dirname,dirpat,'\3','')
12311 let s:machine = substitute(a:dirname,dirpat,'\4','')
12312 let s:port = substitute(a:dirname,dirpat,'\5','')
12313 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012314 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012315 if s:machine =~ '@'
12316 let dirpat = '^\(.*\)@\(.\{-}\)$'
12317 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12318 let s:machine = substitute(s:machine,dirpat,'\2','')
12319 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012320
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012321" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12322" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12323" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12324" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12325" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12326" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012327
12328" call Dret("s:RemotePathAnalysis")
12329endfun
12330
12331" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012332" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12333" Returns status
12334" Runs system() on
12335" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012336" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012337fun! s:RemoteSystem(cmd)
12338" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12339 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012340 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 +000012341 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012342 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012343 else
12344 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12345 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12346 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012347 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012348 else
12349 let cmd= cmd.' '
12350 endif
12351 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012352" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012353 let ret= system(cmd)
12354 endif
12355" call Dret("s:RemoteSystem ".ret)
12356 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012357endfun
12358
12359" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012360" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012361fun! s:RestoreWinVars()
12362" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012363 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012364 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12365 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12366 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12367 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12368 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12369 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12370 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12371 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12372 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12373 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12374 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12375 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012376 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12377 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012378 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12379 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12380 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12381" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012382endfun
12383
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012384" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012385" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12386"
12387" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12388" is true) and a command, :Rexplore, which call this function.
12389"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012390" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012391"
12392" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012393fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012394 if exists("s:netrwdrag")
12395 return
12396 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012397" 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 +010012398" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12399" 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 +010012400
12401 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012402 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012403" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012404 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012405 unlet w:netrw_rexfile
12406" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012407 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012408" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012409" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12410" 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 +020012411 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012412
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012413 " ---------------------------
12414 " :Rex issued while in a file
12415 " ---------------------------
12416
Bram Moolenaara6878372014-03-22 21:02:50 +010012417 " record current file so :Rex can return to it from netrw
12418 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012419" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012420
12421 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012422" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012423 return
12424 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012425" 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 +020012426 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012427 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012428 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012429 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012430 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012431 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012432 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012433 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012434 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012435" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12436 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012437" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12438 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012439 if exists("s:rexposn_".bufnr('%'))
12440 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012441 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012442 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012443" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012444 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012445
Bram Moolenaar85850f32019-07-19 22:05:51 +020012446 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12447 if exists("s:explore_match")
12448 exe "2match netrwMarkFile /".s:explore_match."/"
12449 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012450 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012451
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012452" 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 +010012453" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012454endfun
12455
12456" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012457" s:SaveBufVars: save selected b: variables to s: variables {{{2
12458" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012459fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012460" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012461
12462 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12463 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12464 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12465 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12466 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12467 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12468
12469" call Dret("s:SaveBufVars")
12470endfun
12471
12472" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012473" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12474fun! s:SavePosn(posndict)
12475" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12476
Bram Moolenaar85850f32019-07-19 22:05:51 +020012477 if !exists("a:posndict[bufnr('%')]")
12478 let a:posndict[bufnr("%")]= []
12479 endif
12480" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12481 call add(a:posndict[bufnr("%")],winsaveview())
12482" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012483
12484" call Dret("s:SavePosn posndict")
12485 return a:posndict
12486endfun
12487
12488" ---------------------------------------------------------------------
12489" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12490fun! s:RestorePosn(posndict)
12491" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012492 if exists("a:posndict")
12493 if has_key(a:posndict,bufnr("%"))
12494" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12495 let posnlen= len(a:posndict[bufnr("%")])
12496 if posnlen > 0
12497 let posnlen= posnlen - 1
12498" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12499 call winrestview(a:posndict[bufnr("%")][posnlen])
12500 call remove(a:posndict[bufnr("%")],posnlen)
12501" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12502 endif
12503 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012504 endif
12505" call Dret("s:RestorePosn")
12506endfun
12507
12508" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012509" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012510fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012511" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012512 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12513 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12514 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12515 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12516 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12517 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12518 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12519 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12520 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12521 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12522 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12523 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12524 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12525 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12526 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12527 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12528 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12529 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12530" call Dret("s:SaveWinVars")
12531endfun
12532
12533" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012534" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012535" To allow separate windows to have their own activities, such as
12536" Explore **/pattern, several variables have been made window-oriented.
12537" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012538" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012539" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012540fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012541" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012542 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12543 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12544 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12545 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12546 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12547 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12548 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12549 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12550 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12551 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12552" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012553endfun
12554
12555" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012556" s:SetRexDir: set directory for :Rexplore {{{2
12557fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012558" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012559 let w:netrw_rexdir = a:dirname
12560 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012561 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012562" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12563" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012564" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012565" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012566" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012567endfun
12568
12569" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012570" s:ShowLink: used to modify thin and tree listings to show links {{{2
12571fun! s:ShowLink()
12572" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012573" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12574" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012575 if exists("b:netrw_curdir")
12576 norm! $?\a
12577 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12578 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012579" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12580" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12581" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12582 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012583 let dirlen = strlen(b:netrw_curdir)
12584 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012585" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012586 endif
12587 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012588" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12589" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012590 setl noro ma
12591 call setline(".",modline)
12592 setl ro noma nomod
12593 endif
12594" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12595endfun
12596
12597" ---------------------------------------------------------------------
12598" s:ShowStyle: {{{2
12599fun! s:ShowStyle()
12600 if !exists("w:netrw_liststyle")
12601 let liststyle= g:netrw_liststyle
12602 else
12603 let liststyle= w:netrw_liststyle
12604 endif
12605 if liststyle == s:THINLIST
12606 return s:THINLIST.":thin"
12607 elseif liststyle == s:LONGLIST
12608 return s:LONGLIST.":long"
12609 elseif liststyle == s:WIDELIST
12610 return s:WIDELIST.":wide"
12611 elseif liststyle == s:TREELIST
12612 return s:TREELIST.":tree"
12613 else
12614 return 'n/a'
12615 endif
12616endfun
12617
12618" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012619" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12620" Solution from Nicolai Weibull, vim docs (:help strlen()),
12621" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012622fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012623" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12624
12625 if v:version >= 703 && exists("*strdisplaywidth")
12626 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012627
Bram Moolenaar8d043172014-01-23 14:24:41 +010012628 elseif type(g:Align_xstrlen) == 1
12629 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12630 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012631
Bram Moolenaar8d043172014-01-23 14:24:41 +010012632 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012633 " number of codepoints (Latin a + combining circumflex is two codepoints)
12634 " (comment from TM, solution from NW)
12635 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012636
Bram Moolenaar8d043172014-01-23 14:24:41 +010012637 elseif g:Align_xstrlen == 2
12638 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012639 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12640 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012641 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012642
Bram Moolenaar8d043172014-01-23 14:24:41 +010012643 elseif g:Align_xstrlen == 3
12644 " virtual length (counting, for instance, tabs as anything between 1 and
12645 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012646 " preceded by lam, one otherwise, etc.)
12647 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012648 let modkeep= &l:mod
12649 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012650 call setline(line("."),a:x)
12651 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012652 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012653 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012654 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012655
Bram Moolenaar446cb832008-06-24 21:56:24 +000012656 else
12657 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012658 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012659 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012660" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012661 return ret
12662endfun
12663
12664" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012665" s:ShellEscape: shellescape(), or special windows handling {{{2
12666fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012667 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012668 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12669 endif
12670 let f = a:0 > 0 ? a:1 : 0
12671 return shellescape(a:s, f)
12672endfun
12673
12674" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012675" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012676fun! s:TreeListMove(dir)
12677" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012678 let curline = getline('.')
12679 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12680 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12681 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12682 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12683 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12684 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12685" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12686" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12687" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12688" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12689" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12690 " COMBAK : need to handle when on a directory
12691 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012692 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012693 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012694 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012695 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012696" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012697 elseif a:dir == '[]' && nxtline != ''
12698 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012699" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012700 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12701 if nl != 0
12702 NetrwKeepj norm! k
12703 else
12704 NetrwKeepj norm! G
12705 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012706" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012707 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012708 endif
12709
12710" call Dret("s:TreeListMove")
12711endfun
12712
12713" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012714" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12715" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12716" can't be called except via emenu. But due to locale, that menu line may not be called
12717" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12718fun! s:UpdateBuffersMenu()
12719" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012720 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012721 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012722 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012723 catch /^Vim\%((\a\+)\)\=:E/
12724 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012725 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012726 endtry
12727 endif
12728" call Dret("s:UpdateBuffersMenu")
12729endfun
12730
12731" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012732" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012733" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012734fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012735" call Dfunc("s:UseBufWinVars()")
12736 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012737 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12738 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12739 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12740 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12741 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12742 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12743 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12744 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12745 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 +000012746" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012747endfun
12748
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012749" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012750" s:UserMaps: supports user-defined UserMaps {{{2
12751" * calls a user-supplied funcref(islocal,curdir)
12752" * interprets result
12753" See netrw#UserMaps()
12754fun! s:UserMaps(islocal,funcname)
12755" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12756
12757 if !exists("b:netrw_curdir")
12758 let b:netrw_curdir= getcwd()
12759 endif
12760 let Funcref = function(a:funcname)
12761 let result = Funcref(a:islocal)
12762
12763 if type(result) == 1
12764 " if result from user's funcref is a string...
12765" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12766 if result == "refresh"
12767" call Decho("refreshing display",'~'.expand("<slnum>"))
12768 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12769 elseif result != ""
12770" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12771 exe result
12772 endif
12773
12774 elseif type(result) == 3
12775 " if result from user's funcref is a List...
12776" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12777 for action in result
12778 if action == "refresh"
12779" call Decho("refreshing display",'~'.expand("<slnum>"))
12780 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12781 elseif action != ""
12782" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12783 exe action
12784 endif
12785 endfor
12786 endif
12787
12788" call Dret("s:UserMaps")
12789endfun
12790
Bram Moolenaar85850f32019-07-19 22:05:51 +020012791" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012792" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012793" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012794let &cpo= s:keepcpo
12795unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012796
Bram Moolenaar85850f32019-07-19 22:05:51 +020012797" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012798" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012799" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012800" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012801" doing autoload/netrw.vim version v172g ~57
12802" varname<g:netrw_dirhistcnt> value=0 ~1
12803" varname<s:THINLIST> value=0 ~1
12804" varname<s:LONGLIST> value=1 ~1
12805" varname<s:WIDELIST> value=2 ~1
12806" varname<s:TREELIST> value=3 ~1
12807" varname<s:MAXLIST> value=4 ~1
12808" varname<g:netrw_use_errorwindow> value=2 ~1
12809" varname<g:netrw_http_xcmd> value=-q -O ~1
12810" varname<g:netrw_http_put_cmd> value=curl -T ~1
12811" varname<g:netrw_keepj> value=keepj ~1
12812" varname<g:netrw_rcp_cmd> value=rcp ~1
12813" varname<g:netrw_rsync_cmd> value=rsync ~1
12814" varname<g:netrw_rsync_sep> value=/ ~1
12815" varname<g:netrw_scp_cmd> value=scp -q ~1
12816" varname<g:netrw_sftp_cmd> value=sftp ~1
12817" varname<g:netrw_ssh_cmd> value=ssh ~1
12818" varname<g:netrw_alto> value=0 ~1
12819" varname<g:netrw_altv> value=1 ~1
12820" varname<g:netrw_banner> value=1 ~1
12821" varname<g:netrw_browse_split> value=0 ~1
12822" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12823" varname<g:netrw_chgwin> value=-1 ~1
12824" varname<g:netrw_clipboard> value=1 ~1
12825" varname<g:netrw_compress> value=gzip ~1
12826" varname<g:netrw_ctags> value=ctags ~1
12827" varname<g:netrw_cursor> value=2 ~1
12828" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12829" varname<g:netrw_cygdrive> value=/cygdrive ~1
12830" varname<s:didstarstar> value=0 ~1
12831" varname<g:netrw_dirhistcnt> value=0 ~1
12832" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12833" varname<g:netrw_dirhistmax> value=10 ~1
12834" varname<g:netrw_errorlvl> value=0 ~1
12835" varname<g:netrw_fastbrowse> value=1 ~1
12836" varname<g:netrw_ftp_browse_reject> value=^total\s\+\d\+$\|^Trying\s\+\d\+.*$\|^KERBEROS_V\d rejected\|^Security extensions not\|No such file\|: connect to address [0-9a-fA-F:]*: No route to host$ ~1
12837" varname<g:netrw_ftpmode> value=binary ~1
12838" varname<g:netrw_hide> value=1 ~1
12839" varname<g:netrw_keepdir> value=1 ~1
12840" varname<g:netrw_list_hide> value= ~1
12841" varname<g:netrw_localmkdir> value=mkdir ~1
12842" varname<g:netrw_remote_mkdir> value=mkdir ~1
12843" varname<g:netrw_liststyle> value=0 ~1
12844" varname<g:netrw_markfileesc> value=*./[\~ ~1
12845" varname<g:netrw_maxfilenamelen> value=32 ~1
12846" varname<g:netrw_menu> value=1 ~1
12847" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12848" varname<g:netrw_mousemaps> value=1 ~1
12849" varname<g:netrw_retmap> value=0 ~1
12850" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12851" varname<g:netrw_preview> value=0 ~1