blob: ef574773a4a1a408f50f882bc2a90fd477c3e6c1 [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
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Christian Brabandtf9ca1392024-02-19 20:37:11 +010018" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000019" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010020" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000021" Permission is hereby granted to use and distribute this code,
22" with or without modifications, provided that this copyright
23" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000024" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000025" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000026" expressed or implied. By using this plugin, you agree that
27" in no event will the copyright holder be liable for any damages
28" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010029"
30" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
31" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
32"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020033"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000034"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000035" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000036" (James 1:22 RSV)
37" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000038" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000039if &cp || exists("g:loaded_netrw")
40 finish
41endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020042
43" Check that vim has patches that netrw requires.
44" Patches needed for v7.4: 1557, and 213.
45" (netrw will benefit from vim's having patch#656, too)
46let s:needspatches=[1557,213]
47if exists("s:needspatches")
48 for ptch in s:needspatches
49 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
50 if !exists("s:needpatch{ptch}")
51 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
52 endif
53 let s:needpatch{ptch}= 1
54 finish
55 endif
56 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020057endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020058
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010059let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000060if !exists("s:NOTE")
61 let s:NOTE = 0
62 let s:WARNING = 1
63 let s:ERROR = 2
64endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000065
Bram Moolenaar1afcace2005-11-25 19:54:28 +000066let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010067setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020068"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010069"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010070"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000071
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000072" ======================
73" Netrw Variables: {{{1
74" ======================
75
Bram Moolenaar071d4272004-06-13 20:20:40 +000076" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020077" netrw#ErrorMsg: {{{2
78" 0=note = s:NOTE
79" 1=warning = s:WARNING
80" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010081" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
82" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
83" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010084" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020085fun! netrw#ErrorMsg(level,msg,errnum)
86" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
87
88 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020089" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020090 return
91 endif
92
93 if a:level == 1
94 let level= "**warning** (netrw) "
95 elseif a:level == 2
96 let level= "**error** (netrw) "
97 else
98 let level= "**note** (netrw) "
99 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100100" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200101
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200102 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
103 " use popup window
104 if type(a:msg) == 3
105 let msg = [level]+a:msg
106 else
107 let msg= level.a:msg
108 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200109 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200110 let s:popuperr_text= ""
111 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200112 " (default) netrw creates a one-line window to show error/warning
113 " messages (reliably displayed)
114
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100115 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200116 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100117" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200118
119 " getting messages out reliably is just plain difficult!
120 " This attempt splits the current window, creating a one line window.
121 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100122" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200123 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100124" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200125 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100126 if type(a:msg) == 3
127 for msg in a:msg
128 NetrwKeepj call setline(line("$")+1,level.msg)
129 endfor
130 else
131 NetrwKeepj call setline(line("$")+1,level.a:msg)
132 endif
133 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200134 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100135" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200136 bo 1split
137 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200138 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200139 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100140 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100141" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200142 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100143 if type(a:msg) == 3
144 for msg in a:msg
145 NetrwKeepj call setline(line("$")+1,level.msg)
146 endfor
147 else
148 NetrwKeepj call setline(line("$"),level.a:msg)
149 endif
150 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200151 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100152" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200153 if &fo !~ '[ta]'
154 syn clear
155 syn match netrwMesgNote "^\*\*note\*\*"
156 syn match netrwMesgWarning "^\*\*warning\*\*"
157 syn match netrwMesgError "^\*\*error\*\*"
158 hi link netrwMesgWarning WarningMsg
159 hi link netrwMesgError Error
160 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100161" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200162 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200163
164 else
165 " (optional) netrw will show messages using echomsg. Even if the
166 " message doesn't appear, at least it'll be recallable via :messages
167" redraw!
168 if a:level == s:WARNING
169 echohl WarningMsg
170 elseif a:level == s:ERROR
171 echohl Error
172 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100173
174 if type(a:msg) == 3
175 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100176 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100177 endfor
178 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100179 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100180 endif
181
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100182" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200183 echohl None
184 endif
185
186" call Dret("netrw#ErrorMsg")
187endfun
188
189" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100190" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100191" Loosely, varname = value.
192fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100193" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100194 if !exists(a:varname)
195 if type(a:value) == 0
196 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200197 elseif type(a:value) == 1 && a:value =~ '^[{[]'
198 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100199 elseif type(a:value) == 1
200 exe "let ".a:varname."="."'".a:value."'"
201 else
202 exe "let ".a:varname."=".a:value
203 endif
204 endif
205endfun
206
207" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000208" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200209call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000210if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100211 call s:NetrwInit("s:THINLIST",0)
212 call s:NetrwInit("s:LONGLIST",1)
213 call s:NetrwInit("s:WIDELIST",2)
214 call s:NetrwInit("s:TREELIST",3)
215 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000216endif
217
218" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200219" Default option values: {{{2
220let g:netrw_localcopycmdopt = ""
221let g:netrw_localcopydircmdopt = ""
222let g:netrw_localmkdiropt = ""
223let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200224
225" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000226" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200227if (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")
228 call s:NetrwInit("g:netrw_use_errorwindow",2)
229else
230 call s:NetrwInit("g:netrw_use_errorwindow",1)
231endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200232
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000233if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100234 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000235 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100236 elseif executable("curl")
237 let g:netrw_dav_cmd = "curl"
238 else
239 let g:netrw_dav_cmd = ""
240 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000241endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000242if !exists("g:netrw_fetch_cmd")
243 if executable("fetch")
244 let g:netrw_fetch_cmd = "fetch -o"
245 else
246 let g:netrw_fetch_cmd = ""
247 endif
248endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100249if !exists("g:netrw_file_cmd")
250 if executable("elinks")
251 call s:NetrwInit("g:netrw_file_cmd","elinks")
252 elseif executable("links")
253 call s:NetrwInit("g:netrw_file_cmd","links")
254 endif
255endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000256if !exists("g:netrw_ftp_cmd")
257 let g:netrw_ftp_cmd = "ftp"
258endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200259let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200260if !exists("g:netrw_ftp_options")
261 let g:netrw_ftp_options= "-i -n"
262endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000263if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100264 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100265 let g:netrw_http_cmd = "wget"
266 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100267 elseif executable("curl")
268 let g:netrw_http_cmd = "curl"
269 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200270 elseif executable("elinks")
271 let g:netrw_http_cmd = "elinks"
272 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000273 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100274 let g:netrw_http_cmd = "fetch"
275 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200276 elseif executable("links")
277 let g:netrw_http_cmd = "links"
278 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000279 else
280 let g:netrw_http_cmd = ""
281 endif
282endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100283call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100284call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100285call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
286call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200287call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200288if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200289 if executable("scp")
290 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
291 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200292 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200293 else
294 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
295 endif
296endif
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")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100372 if exists("g:netrw_list_cmd_options")
373 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
374 else
375 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
376 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000377 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200378 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100379 if exists("g:netrw_list_cmd_options")
380 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
381 else
382 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
383 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000384 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100385" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000386 let g:netrw_list_cmd= ""
387 endif
388endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100389call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000390" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200391if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200392 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200393 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
394endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100395if !exists("g:netrw_localcmdshell")
396 let g:netrw_localcmdshell= ""
397endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000398if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200399 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000400 if g:netrw_cygwin
401 let g:netrw_localcopycmd= "cp"
402 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000403 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200404 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000405 endif
406 elseif has("unix") || has("macunix")
407 let g:netrw_localcopycmd= "cp"
408 else
409 let g:netrw_localcopycmd= ""
410 endif
411endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100412if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200413 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100414 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200415 let g:netrw_localcopydircmd = "cp"
416 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100417 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000418 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200419 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100420 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200421 elseif has("unix")
422 let g:netrw_localcopydircmd = "cp"
423 let g:netrw_localcopydircmdopt= " -R"
424 elseif has("macunix")
425 let g:netrw_localcopydircmd = "cp"
426 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100427 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200428 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100429 endif
430endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200431if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100432 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200433 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
434endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200435if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200436 if g:netrw_cygwin
437 call s:NetrwInit("g:netrw_localmkdir","mkdir")
438 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000439 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200440 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200441 endif
442else
443 call s:NetrwInit("g:netrw_localmkdir","mkdir")
444endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200445call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200446if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200447 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200448 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
449endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000450if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200451 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000452 if g:netrw_cygwin
453 let g:netrw_localmovecmd= "mv"
454 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000455 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200456 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000457 endif
458 elseif has("unix") || has("macunix")
459 let g:netrw_localmovecmd= "mv"
460 else
461 let g:netrw_localmovecmd= ""
462 endif
463endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100464" following serves as an example for how to insert a version&patch specific test
465"if v:version < 704 || (v:version == 704 && !has("patch1107"))
466"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100467call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
468" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000469if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000470 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000471endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000472if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000473 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
474endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000475" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100476call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
477call s:NetrwInit("g:netrw_maxfilenamelen", 32)
478call s:NetrwInit("g:netrw_menu" , 1)
479call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200480call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100481call s:NetrwInit("g:netrw_retmap" , 0)
482if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
483 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200484elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100485 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
486else
487 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000488endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100489call s:NetrwInit("g:netrw_preview" , 0)
490call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100491call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100492call s:NetrwInit("g:netrw_sshport" , "-p")
493call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
494call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
495call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100496call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
497" Default values - q-s ---------- {{{3
498call s:NetrwInit("g:netrw_quickhelp",0)
499let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100500 \ "(create new) %:file d:directory",
501 \ "(windows split&open) o:horz v:vert p:preview",
502 \ "i:style qf:file info O:obtain r:reverse",
503 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
504 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
505 \ "(history) qb:list u:go up U:go down",
506 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100507" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
508call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100509if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
510 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
511else
512 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
513endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100514call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
515call s:NetrwInit("g:netrw_sort_options" , "")
516call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000517if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100518 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200519 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100520 else
521 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000522 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000523endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100524call s:NetrwInit("g:netrw_special_syntax" , 0)
525call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200526call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100527call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100528call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000529" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100530call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200531if !exists("g:netrw_xstrlen")
532 if exists("g:Align_xstrlen")
533 let g:netrw_xstrlen= g:Align_xstrlen
534 elseif exists("g:drawit_xstrlen")
535 let g:netrw_xstrlen= g:drawit_xstrlen
536 elseif &enc == "latin1" || !has("multi_byte")
537 let g:netrw_xstrlen= 0
538 else
539 let g:netrw_xstrlen= 1
540 endif
541endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100542call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200543call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100544call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200545if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000546" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000547" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100548call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200549if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200550 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200551else
Bram Moolenaarff034192013-04-24 18:51:19 +0200552 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200553endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200554call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100555call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
556call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100557if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100558 let s:treedepthstring= "│ "
559else
560 let s:treedepthstring= "| "
561endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200562call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000563
564" BufEnter event ignored by decho when following variable is true
565" Has a side effect that doau BufReadPost doesn't work, so
566" files read by network transfer aren't appropriately highlighted.
567"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568
Bram Moolenaaradc21822011-04-01 18:03:16 +0200569" ======================
570" Netrw Initialization: {{{1
571" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200572if 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 +0100573" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100574 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200575" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100576 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100577 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
578 au VimEnter * let s:initbeval= &beval
579"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100580" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
581" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
582" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
583" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
584" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
585" 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 +0200586endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200587au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200588
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200589if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100590 com! -nargs=* NetrwKeepj keepj <args>
591else
592 let g:netrw_keepj= ""
593 com! -nargs=* NetrwKeepj <args>
594endif
595
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000596" ==============================
597" Netrw Utility Functions: {{{1
598" ==============================
599
Bram Moolenaaradc21822011-04-01 18:03:16 +0200600" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100601" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100602if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100603" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100604 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100605 if &ft != "netrw"
606 return ""
607 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200608 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
609 " popup error window is still showing
610 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
611 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
612 " text under mouse hasn't changed; only close window when it changes
613 call popup_close(s:popuperr_id)
614 unlet s:popuperr_text
615 else
616 let s:popuperr_text= v:beval_text
617 endif
618 let mesg= ""
619 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 +0100620 let mesg= ""
621 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
622 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
623 elseif getline(v:beval_lnum) =~ '^"\s*/'
624 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
625 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100626 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100627 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
628 let mesg = "S: edit sorting sequence"
629 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
630 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
631 elseif v:beval_text == "Quick" || v:beval_text == "Help"
632 let mesg = "Help: press <F1>"
633 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
634 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
635 else
636 let mesg= ""
637 endif
638 return mesg
639 endfun
640"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100641" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
642" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
643" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
644" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
645" 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 +0200646endif
647
Bram Moolenaar071d4272004-06-13 20:20:40 +0000648" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200649" netrw#Explore: launch the local browser in the directory of the current file {{{2
650" indx: == -1: Nexplore
651" == -2: Pexplore
652" == +: this is overloaded:
653" * If Nexplore/Pexplore is in use, then this refers to the
654" indx'th item in the w:netrw_explore_list[] of items which
655" matched the */pattern **/pattern *//pattern **//pattern
656" * If Hexplore or Vexplore, then this will override
657" g:netrw_winsize to specify the qty of rows or columns the
658" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100659" 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 +0200660" dosplit==1: the window will be split before running the local browser
661" style == 0: Explore style == 1: Explore!
662" == 2: Hexplore style == 3: Hexplore!
663" == 4: Vexplore style == 5: Vexplore!
664" == 6: Texplore
665fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100666" 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 +0100667" 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 +0200668 if !exists("b:netrw_curdir")
669 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100670" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200671 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100672
673 " record current file for Rexplore's benefit
674 if &ft != "netrw"
675 let w:netrw_rexfile= expand("%:p")
676 endif
677
678 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200679 let curdir = simplify(b:netrw_curdir)
680 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200681 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200682 let curdir= substitute(curdir,'\','/','g')
683 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100684" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100685
686 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
687 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
688 " try Explore again.
689 if a:0 > 0
690" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100691 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
692 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
693 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
694 \ '~'.expand("<slnum>"))
695 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
696" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100697 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
698" call Dret("netrw#Explore : returning from retry")
699 return
700" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100701" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100702 endif
703 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200704
705 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200706 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100707" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100708 sil! let keepregstar = @*
709 sil! let keepregplus = @+
710 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200711 sil! let keepregslash= @/
712
Bram Moolenaar8d043172014-01-23 14:24:41 +0100713 " if dosplit
714 " -or- file has been modified AND file not hidden when abandoned
715 " -or- Texplore used
716 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100717" 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 +0200718 call s:SaveWinVars()
719 let winsz= g:netrw_winsize
720 if a:indx > 0
721 let winsz= a:indx
722 endif
723
724 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100725" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200726 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200727 if winsz == 0|let winsz= ""|endif
728 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100729" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200730
731 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100732" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200733 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200734 if winsz == 0|let winsz= ""|endif
735 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100736" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200737
738 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100739" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200740 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200741 if winsz == 0|let winsz= ""|endif
742 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100743" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200744
745 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100746" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200747 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200748 if winsz == 0|let winsz= ""|endif
749 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100750" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200751
752 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100753" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200754 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200755 if winsz == 0|let winsz= ""|endif
756 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100757" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200758
759 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100760" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200761 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200762 if winsz == 0|let winsz= ""|endif
763 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100764" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200765
766 elseif a:style == 6 " Texplore
767 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100768" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200769 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100770" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200771 call s:RestoreBufVars()
772 endif
773 call s:RestoreWinVars()
774" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100775" 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 +0200776 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100777 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200778
779 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100780" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200781 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
788 if dirname !~ '/$'
789 let dirname= dirname."/"
790 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100791" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200792 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200796 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200800 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 let dirname= a:1
803 endif
804 else
805 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100806" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200807 call s:NetrwClearExplore()
808" call Dret("netrw#Explore : cleared list")
809 return
810 endif
811
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100812" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200813 if dirname =~ '\.\./\=$'
814 let dirname= simplify(fnamemodify(dirname,':p:h'))
815 elseif dirname =~ '\.\.' || dirname == '.'
816 let dirname= simplify(fnamemodify(dirname,':p'))
817 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100818" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200819
820 if dirname =~ '^\*//'
821 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100822" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200823 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
824 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100825" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200826 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
827
828 elseif dirname =~ '^\*\*//'
829 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100830" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200831 let pattern= substitute(dirname,'^\*\*//','','')
832 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100833" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200834
835 elseif dirname =~ '/\*\*/'
836 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100837" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200838 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200839 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200840 let b:netrw_curdir = prefixdir
841 else
842 let b:netrw_curdir= getcwd().'/'.prefixdir
843 endif
844 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
845 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100846" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
847" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200848
849 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200850 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200851 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100852" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200853
854 elseif dirname=~ '^\*\*/'
855 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
856 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100857" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200858
859 else
860 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100861" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200862 endif
863
864 if starpat == 0 && a:indx >= 0
865 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100866" 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 +0200867 if dirname == ""
868 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100869" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200870 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200871 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200872 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200873 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200874 if dirname == ""
875 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200876 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100877 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100878 " depending on whether backslashes have been converted to forward slashes by earlier code).
879 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200880 let dirname= b:netrw_curdir."/".dirname
881 endif
882 elseif dirname !~ '^/'
883 let dirname= b:netrw_curdir."/".dirname
884 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100885" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200886 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100887" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
888" 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 +0200889 endif
890 if exists("w:netrw_bannercnt")
891 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
892 " If one wants to return the same place in the netrw window, use :Rex instead.
893 exe w:netrw_bannercnt
894 endif
895
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100896" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200897 " ---------------------------------------------------------------------
898 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
899" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100900" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200901" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100902" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200903" endif
904 " ---------------------------------------------------------------------
905
906 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
907 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
908 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
909 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
910 elseif a:indx <= 0
911 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100912" 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 +0200913 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100914" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200915 let s:didstarstar= 1
916 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
917 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
918 endif
919
920 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100921" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200922 if !exists("w:netrw_explore_indx")
923 let w:netrw_explore_indx= 0
924 endif
925
926 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100927" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200928
929 if indx == -1
930 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100931" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200932 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100933 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 +0200934 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100935" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100936 if @* != keepregstar | sil! let @* = keepregstar | endif
937 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100938 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200939 sil! let @/ = keepregslash
940" call Dret("netrw#Explore")
941 return
942 endif
943 let indx= w:netrw_explore_indx
944 if indx < 0 | let indx= 0 | endif
945 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
946 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100947" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200948 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
949 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100950" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200951 endwhile
952 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100953" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200954
955 elseif indx == -2
956 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100957" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200958 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100959 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 +0200960 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100961" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100962 if @* != keepregstar | sil! let @* = keepregstar | endif
963 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100964 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200965 sil! let @/ = keepregslash
966" call Dret("netrw#Explore")
967 return
968 endif
969 let indx= w:netrw_explore_indx
970 if indx < 0 | let indx= 0 | endif
971 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
972 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100973" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200974 while indx >= 0 && curfile == w:netrw_explore_list[indx]
975 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100976" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200977 endwhile
978 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100979" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200980
981 else
982 " Explore -- initialize
983 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100984" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100985 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200986 let w:netrw_explore_indx= 0
987 if !exists("b:netrw_curdir")
988 let b:netrw_curdir= getcwd()
989 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100990" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200991
992 " switch on starpat to build the w:netrw_explore_list of files
993 if starpat == 1
994 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100995" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
996" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200997 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100998 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200999 catch /^Vim\%((\a\+)\)\=:E480/
1000 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1001" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1002 return
1003 endtry
1004 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1005 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1006
1007 elseif starpat == 2
1008 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001009" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1010" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001011 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001012 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001013 catch /^Vim\%((\a\+)\)\=:E480/
1014 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1015 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001016 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001017" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001018 if @* != keepregstar | sil! let @* = keepregstar | endif
1019 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001020 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001021 sil! let @/ = keepregslash
1022" call Dret("netrw#Explore : no files matched pattern")
1023 return
1024 endtry
1025 let s:netrw_curdir = b:netrw_curdir
1026 let w:netrw_explore_list = getqflist()
1027 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1028 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1029
1030 elseif starpat == 3
1031 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001032" 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 +02001033 let filepat= substitute(dirname,'^\*/','','')
1034 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001035" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1036" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001037 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1038 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1039
1040 elseif starpat == 4
1041 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001042" 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 +02001043 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1044 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1045 endif " switch on starpat to build w:netrw_explore_list
1046
1047 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001048" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1049" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001050
1051 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001052 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001053 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001054" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001055 if @* != keepregstar | sil! let @* = keepregstar | endif
1056 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001057 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001058 sil! let @/ = keepregslash
1059" call Dret("netrw#Explore : no files matched")
1060 return
1061 endif
1062 endif " if indx ... endif
1063
1064 " NetrwStatusLine support - for exploring support
1065 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001066" 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 +02001067
1068 " wrap the indx around, but issue a note
1069 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001070" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001071 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1072 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001073 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001074 endif
1075
1076 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001077" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001078 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001079" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001080
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001081" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001082 call netrw#LocalBrowseCheck(newdir)
1083 if !exists("w:netrw_liststyle")
1084 let w:netrw_liststyle= g:netrw_liststyle
1085 endif
1086 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001087 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001088 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001089 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001090 endif
1091 let w:netrw_explore_mtchcnt = indx + 1
1092 let w:netrw_explore_bufnr = bufnr("%")
1093 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001094 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001095" 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 +02001096
1097 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001098" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001099 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001100 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 +02001101 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001102 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001103" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001104 if @* != keepregstar | sil! let @* = keepregstar | endif
1105 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001106 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001107 sil! let @/ = keepregslash
1108" call Dret("netrw#Explore : missing +path_extra")
1109 return
1110 endif
1111
1112 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001113" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001114 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1115 sil! unlet w:netrw_treedict
1116 sil! unlet w:netrw_treetop
1117 endif
1118 let newdir= dirname
1119 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001120 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001121 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001122 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001123 endif
1124 endif
1125
1126 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001127" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1128" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001129 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001130" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001131 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001132 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001133" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001134 let s:explore_prvdir = b:netrw_curdir
1135 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001136 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001137 if b:netrw_curdir !~ '/$'
1138 let dirlen= dirlen + 1
1139 endif
1140 let prvfname= ""
1141 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001142" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001143 if fname =~ '^'.b:netrw_curdir
1144 if s:explore_match == ""
1145 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1146 else
1147 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1148 endif
1149 elseif fname !~ '^/' && fname != prvfname
1150 if s:explore_match == ""
1151 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1152 else
1153 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1154 endif
1155 endif
1156 let prvfname= fname
1157 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001158" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001159 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1160 exe "2match netrwMarkFile /".s:explore_match."/"
1161 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001162 endif
1163 echo "<s-up>==Pexplore <s-down>==Nexplore"
1164 else
1165 2match none
1166 if exists("s:explore_match") | unlet s:explore_match | endif
1167 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001168" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001169 endif
1170
Bram Moolenaara6878372014-03-22 21:02:50 +01001171 " since Explore may be used to initialize netrw's browser,
1172 " there's no danger of a late FocusGained event on initialization.
1173 " Consequently, set s:netrw_events to 2.
1174 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001175 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001176" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001177 if @* != keepregstar | sil! let @* = keepregstar | endif
1178 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001179 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001180 sil! let @/ = keepregslash
1181" call Dret("netrw#Explore : @/<".@/.">")
1182endfun
1183
1184" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001185" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001186" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1187" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1188" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1189" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1190" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001191fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001192" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001193 let curwin= winnr()
1194
Bram Moolenaara6878372014-03-22 21:02:50 +01001195 if a:0 > 0 && a:1 != ""
1196 " if a netrw window is already on the left-side of the tab
1197 " and a directory has been specified, explore with that
1198 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001199" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001200 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001201" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001202 exe "1wincmd w"
1203 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001204" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001205 exe "Explore ".fnameescape(a1)
1206 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001207 let s:lexplore_win= curwin
1208 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001210" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001211 unlet t:netrw_lexposn
1212 endif
1213" call Dret("netrw#Lexplore")
1214 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001215 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001216 exe curwin."wincmd w"
1217 else
1218 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001219" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001220 endif
1221
Bram Moolenaar8d043172014-01-23 14:24:41 +01001222 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001223 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001224 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001225" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001226 else
1227 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001228" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001229 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001230" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001231
1232 if lexwinnr > 0
1233 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001234" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001235 exe lexwinnr."wincmd w"
1236 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001237 let t:netrw_lexposn = winsaveview()
1238" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001239" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001240 close
1241 if lexwinnr < curwin
1242 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001243 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001244 if lexwinnr != curwin
1245 exe curwin."wincmd w"
1246 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001247 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001248" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001249
1250 else
1251 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001252" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001253 exe "1wincmd w"
1254 let keep_altv = g:netrw_altv
1255 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001256 if a:count != 0
1257 let netrw_winsize = g:netrw_winsize
1258 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001259 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001260 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001261" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262 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 +02001263" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001264 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001265" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001266 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001267 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001268 elseif curfile =~ '^\a\{3,}://'
1269" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001270 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001271 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001272" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001273 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001274 endif
1275 if a:count != 0
1276 let g:netrw_winsize = netrw_winsize
1277 endif
1278 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001279 let g:netrw_altv = keep_altv
1280 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001281 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1282 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001283 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001284 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001285" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1286" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001287 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001288" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001289" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1290 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001291 unlet t:netrw_lexposn
1292 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001293 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001294
1295 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001296 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001297 if a:rightside
1298 let g:netrw_chgwin= 1
1299 else
1300 let g:netrw_chgwin= 2
1301 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001302" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001303 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001304
Bram Moolenaar8d043172014-01-23 14:24:41 +01001305" call Dret("netrw#Lexplore")
1306endfun
1307
1308" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001309" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001310" supports :NetrwClean -- remove netrw from first directory on runtimepath
1311" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001312fun! netrw#Clean(sys)
1313" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001314
1315 if a:sys
1316 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1317 else
1318 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1319 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001320" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001321 let diddel= 0
1322 let diddir= ""
1323
1324 if choice == 1
1325 for dir in split(&rtp,',')
1326 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001327" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001328 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1329 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1330 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1331 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1332 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1333 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 +00001334 let diddir= dir
1335 let diddel= diddel + 1
1336 if !a:sys|break|endif
1337 endif
1338 endfor
1339 endif
1340
1341 echohl WarningMsg
1342 if diddel == 0
1343 echomsg "netrw is either not installed or not removable"
1344 elseif diddel == 1
1345 echomsg "removed one copy of netrw from <".diddir.">"
1346 else
1347 echomsg "removed ".diddel." copies of netrw"
1348 endif
1349 echohl None
1350
Bram Moolenaara6878372014-03-22 21:02:50 +01001351" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001352endfun
1353
Bram Moolenaar5c736222010-01-06 20:54:52 +01001354" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001355" netrw#MakeTgt: make a target out of the directory name provided {{{2
1356fun! netrw#MakeTgt(dname)
1357" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1358 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001359 let svpos = winsaveview()
1360" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001361 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1362" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001363 if s:netrwmftgt_islocal
1364 let netrwmftgt= simplify(a:dname)
1365 else
1366 let netrwmftgt= a:dname
1367 endif
1368 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1369 " re-selected target, so just clear it
1370 unlet s:netrwmftgt s:netrwmftgt_islocal
1371 else
1372 let s:netrwmftgt= netrwmftgt
1373 endif
1374 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001375 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001376 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001377" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1378 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001379" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001380endfun
1381
Bram Moolenaara6878372014-03-22 21:02:50 +01001382" ---------------------------------------------------------------------
1383" netrw#Obtain: {{{2
1384" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001385" islocal=0 obtain from remote source
1386" =1 obtain from local source
1387" fname : a filename or a list of filenames
1388" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001389fun! netrw#Obtain(islocal,fname,...)
1390" 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 +02001391 " NetrwStatusLine support - for obtaining support
1392
1393 if type(a:fname) == 1
1394 let fnamelist= [ a:fname ]
1395 elseif type(a:fname) == 3
1396 let fnamelist= a:fname
1397 else
1398 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 +01001399" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001400 return
1401 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001402" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001403 if a:0 > 0
1404 let tgtdir= a:1
1405 else
1406 let tgtdir= getcwd()
1407 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001408" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001409
1410 if exists("b:netrw_islocal") && b:netrw_islocal
1411 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001412" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001413 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1414 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001415 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001416 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001417" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001418 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001419" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001420 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001421 if v:shell_error != 0
1422 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 +01001423" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001424 return
1425 endif
1426 endfor
1427 else
1428 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001429" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1430 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1431" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001432 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001433 if v:shell_error != 0
1434 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 +01001435" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001436 return
1437 endif
1438 endif
1439 elseif !exists("b:netrw_curdir")
1440 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1441 else
1442 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1443 endif
1444
1445 else
1446 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001447" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001448 if type(a:fname) == 1
1449 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1450 endif
1451 call s:NetrwMethod(b:netrw_curdir)
1452
1453 if b:netrw_method == 4
1454 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001455" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001456 if exists("g:netrw_port") && g:netrw_port != ""
1457 let useport= " ".g:netrw_scpport." ".g:netrw_port
1458 else
1459 let useport= ""
1460 endif
1461 if b:netrw_fname =~ '/'
1462 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1463 else
1464 let path= ""
1465 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001466 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001467 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 +02001468
1469 elseif b:netrw_method == 2
1470 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001471" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001472 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001473 let tmpbufnr= bufnr("%")
1474 setl ff=unix
1475 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001476 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001477" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001478 endif
1479
1480 if exists("b:netrw_fname") && b:netrw_fname != ""
1481 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001482" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001483 endif
1484
1485 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001486 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001487" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001488 endif
1489 for fname in fnamelist
1490 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001491" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001492 endfor
1493 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001494 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 +02001495 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001496 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001497 endif
1498 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1499 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1500 let debugkeep= &debug
1501 setl debug=msg
1502 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1503 let &debug= debugkeep
1504 endif
1505
1506 elseif b:netrw_method == 3
1507 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001508" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001509 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001510 let tmpbufnr= bufnr("%")
1511 setl ff=unix
1512
1513 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001514 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001515" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001516 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001517 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001518" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001519 endif
1520
1521 if exists("g:netrw_uid") && g:netrw_uid != ""
1522 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001523 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001524" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001525 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001526 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001527 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001528" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001529 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001530 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001531" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001532 endif
1533 endif
1534
1535 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001536 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001537" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001538 endif
1539
1540 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001541 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001542" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001543 endif
1544
1545 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001546 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001547" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001548 endif
1549
1550 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001551 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001552" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001553 endif
1554 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001555 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001556 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001557" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001558
1559 " perform ftp:
1560 " -i : turns off interactive prompting from ftp
1561 " -n unix : DON'T use <.netrc>, even though it exists
1562 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001563 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1564 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001565 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001566 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1567 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001568" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001569 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001570 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001571 endif
1572 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001573
1574 elseif b:netrw_method == 9
1575 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001576" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001577 if a:fname =~ '/'
1578 let localfile= substitute(a:fname,'^.*/','','')
1579 else
1580 let localfile= a:fname
1581 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001582 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 +02001583
Bram Moolenaarff034192013-04-24 18:51:19 +02001584 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001585 " probably a badly formed url; protocol not recognized
1586" call Dret("netrw#Obtain : unsupported method")
1587 return
1588
1589 else
1590 " protocol recognized but not supported for Obtain (yet?)
1591 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001592 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001593 endif
1594" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001595 return
1596 endif
1597
1598 " restore status line
1599 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001600 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001601 endif
1602
1603 endif
1604
1605 " cleanup
1606 if exists("tmpbufnr")
1607 if bufnr("%") != tmpbufnr
1608 exe tmpbufnr."bw!"
1609 else
1610 q!
1611 endif
1612 endif
1613
Bram Moolenaara6878372014-03-22 21:02:50 +01001614" call Dret("netrw#Obtain")
1615endfun
1616
1617" ---------------------------------------------------------------------
1618" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1619fun! netrw#Nread(mode,fname)
1620" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001621 let svpos= winsaveview()
1622" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001623 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001624" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1625 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001626
1627 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1628 if exists("w:netrw_bannercnt")
1629 " start with cursor just after the banner
1630 exe w:netrw_bannercnt
1631 endif
1632 endif
1633" call Dret("netrw#Nread")
1634endfun
1635
1636" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001637" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1638" Options get restored by s:NetrwOptionsRestore()
1639"
1640" Option handling:
1641" * save user's options (s:NetrwOptionsSave)
1642" * set netrw-safe options (s:NetrwOptionsSafe)
1643" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1644" * restore user's options (s:netrwOPtionsRestore)
1645" - restore a user option when != safe option (s:NetrwRestoreSetting)
1646" vt: (variable type) normally its either "w:" or "s:"
1647fun! s:NetrwOptionsSave(vt)
1648" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1649" 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 +02001650" 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>"))
1651" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001652
1653 if !exists("{a:vt}netrw_optionsave")
1654 let {a:vt}netrw_optionsave= 1
1655 else
1656" call Dret("s:NetrwOptionsSave : options already saved")
1657 return
1658 endif
1659" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1660
1661 " Save current settings and current directory
1662" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1663 let s:yykeep = @@
1664 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1665 let {a:vt}netrw_aikeep = &l:ai
1666 let {a:vt}netrw_awkeep = &l:aw
1667 let {a:vt}netrw_bhkeep = &l:bh
1668 let {a:vt}netrw_blkeep = &l:bl
1669 let {a:vt}netrw_btkeep = &l:bt
1670 let {a:vt}netrw_bombkeep = &l:bomb
1671 let {a:vt}netrw_cedit = &cedit
1672 let {a:vt}netrw_cikeep = &l:ci
1673 let {a:vt}netrw_cinkeep = &l:cin
1674 let {a:vt}netrw_cinokeep = &l:cino
1675 let {a:vt}netrw_comkeep = &l:com
1676 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001677 let {a:vt}netrw_cuckeep = &l:cuc
1678 let {a:vt}netrw_culkeep = &l:cul
1679" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001680 let {a:vt}netrw_diffkeep = &l:diff
1681 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001682 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1683 let {a:vt}netrw_ffkeep = &l:ff
1684 endif
1685 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1686 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001687 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001688 let {a:vt}netrw_hidkeep = &l:hidden
1689 let {a:vt}netrw_imkeep = &l:im
1690 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001691 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001692 let {a:vt}netrw_lskeep = &l:ls
1693 let {a:vt}netrw_makeep = &l:ma
1694 let {a:vt}netrw_magickeep = &l:magic
1695 let {a:vt}netrw_modkeep = &l:mod
1696 let {a:vt}netrw_nukeep = &l:nu
1697 let {a:vt}netrw_rnukeep = &l:rnu
1698 let {a:vt}netrw_repkeep = &l:report
1699 let {a:vt}netrw_rokeep = &l:ro
1700 let {a:vt}netrw_selkeep = &l:sel
1701 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001702 if !g:netrw_use_noswf
1703 let {a:vt}netrw_swfkeep = &l:swf
1704 endif
1705 let {a:vt}netrw_tskeep = &l:ts
1706 let {a:vt}netrw_twkeep = &l:tw " textwidth
1707 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1708 let {a:vt}netrw_wrapkeep = &l:wrap
1709 let {a:vt}netrw_writekeep = &l:write
1710
1711 " save a few selected netrw-related variables
1712" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1713 if g:netrw_keepdir
1714 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001715" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001716 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001717 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001718 sil! let {a:vt}netrw_starkeep = @*
1719 sil! let {a:vt}netrw_pluskeep = @+
1720 endif
1721 sil! let {a:vt}netrw_slashkeep= @/
1722
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001723" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001724" 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>"))
1725" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1726endfun
1727
1728" ---------------------------------------------------------------------
1729" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1730" Use s:NetrwSaveOptions() to save user settings
1731" Use s:NetrwOptionsRestore() to restore user settings
1732fun! s:NetrwOptionsSafe(islocal)
1733" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1734" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1735" 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>"))
1736 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1737 call s:NetrwSetSafeSetting("&l:ai",0)
1738 call s:NetrwSetSafeSetting("&l:aw",0)
1739 call s:NetrwSetSafeSetting("&l:bl",0)
1740 call s:NetrwSetSafeSetting("&l:bomb",0)
1741 if a:islocal
1742 call s:NetrwSetSafeSetting("&l:bt","nofile")
1743 else
1744 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1745 endif
1746 call s:NetrwSetSafeSetting("&l:ci",0)
1747 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001748 if g:netrw_fastbrowse > a:islocal
1749 call s:NetrwSetSafeSetting("&l:bh","hide")
1750 else
1751 call s:NetrwSetSafeSetting("&l:bh","delete")
1752 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001753 call s:NetrwSetSafeSetting("&l:cino","")
1754 call s:NetrwSetSafeSetting("&l:com","")
1755 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1756 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1757 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001758 if &go =~ 'a' | set go-=a | endif
1759 if &go =~ 'A' | set go-=A | endif
1760 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001761 call s:NetrwSetSafeSetting("&l:hid",0)
1762 call s:NetrwSetSafeSetting("&l:im",0)
1763 setl isk+=@ isk+=* isk+=/
1764 call s:NetrwSetSafeSetting("&l:magic",1)
1765 if g:netrw_use_noswf
1766 call s:NetrwSetSafeSetting("swf",0)
1767 endif
1768 call s:NetrwSetSafeSetting("&l:report",10000)
1769 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1770 call s:NetrwSetSafeSetting("&l:spell",0)
1771 call s:NetrwSetSafeSetting("&l:tw",0)
1772 call s:NetrwSetSafeSetting("&l:wig","")
1773 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001774
1775 " set up cuc and cul based on g:netrw_cursor and listing style
1776 " COMBAK -- cuc cul related
1777 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001778
1779 " allow the user to override safe options
1780" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1781 if &ft == "netrw"
1782" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1783 keepalt NetrwKeepj doau FileType netrw
1784 endif
1785
1786" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1787" 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>"))
1788" call Dret("s:NetrwOptionsSafe")
1789endfun
1790
1791" ---------------------------------------------------------------------
1792" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1793fun! s:NetrwOptionsRestore(vt)
1794" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001795" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001796" 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 +01001797 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001798" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001799
1800 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1801 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001802" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001803 filetype detect
1804" 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>"))
1805 else
1806 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001807 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001808" 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 +02001809" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001810 return
1811 endif
1812 unlet {a:vt}netrw_optionsave
1813
1814 if exists("+acd")
1815 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001816" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001817 let curdir = getcwd()
1818 let &l:acd = {a:vt}netrw_acdkeep
1819 unlet {a:vt}netrw_acdkeep
1820 if &l:acd
1821 call s:NetrwLcd(curdir)
1822 endif
1823 endif
1824 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001825" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001826 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1827 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1828 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1829 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1830 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001831" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001832 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1833 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1834 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1835 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1836 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001837" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001838 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1839 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1840 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1841 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1842 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001843 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001844" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1845 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1846 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001847 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001848 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1849" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1850 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1851 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1852" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1853 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1854" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1855 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1856 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001857 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001858 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1859 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1860" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1861 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1862 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1863 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1864 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1865" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001866 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001867 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1868 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1869 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001870 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001871" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001872 call s:NetrwRestoreSetting("s:yykeep","@@")
1873 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1874 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1875 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1876 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1877
Bram Moolenaara6878372014-03-22 21:02:50 +01001878 if exists("{a:vt}netrw_swfkeep")
1879 if &directory == ""
1880 " user hasn't specified a swapfile directory;
1881 " netrw will temporarily set the swapfile directory
1882 " to the current directory as returned by getcwd().
1883 let &l:directory= getcwd()
1884 sil! let &l:swf = {a:vt}netrw_swfkeep
1885 setl directory=
1886 unlet {a:vt}netrw_swfkeep
1887 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001888 if !g:netrw_use_noswf
1889 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1890 sil! let &l:swf= {a:vt}netrw_swfkeep
1891 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001892 unlet {a:vt}netrw_swfkeep
1893 endif
1894 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001895 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001896 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1897 if exists("{a:vt}netrw_dirkeep")
1898 call s:NetrwLcd(dirkeep)
1899 unlet {a:vt}netrw_dirkeep
1900 endif
1901 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001902 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001903" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001904 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1905 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001906 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001907 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001908
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001909" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1910" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1911" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1912" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1913" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001914 " Moved the filetype detect here from NetrwGetFile() because remote files
1915 " were having their filetype detect-generated settings overwritten by
1916 " NetrwOptionRestore.
1917 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001918" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1919 filetype detect
1920" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001921 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001922" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001923" 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 +02001924" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001925endfun
1926
1927" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001928" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1929" but only when the options' value and the safe setting differ
1930" Doing this means that netrw will not come up as having changed a
1931" setting last when it really didn't actually change it.
1932"
1933" Called from s:NetrwOptionsSafe
1934" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1935fun! s:NetrwSetSafeSetting(setting,safesetting)
1936" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001937
Bram Moolenaar85850f32019-07-19 22:05:51 +02001938 if a:setting =~ '^&'
1939" call Decho("fyi: a:setting starts with &")
1940 exe "let settingval= ".a:setting
1941" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001942
Bram Moolenaar85850f32019-07-19 22:05:51 +02001943 if settingval != a:safesetting
1944" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1945 if type(a:safesetting) == 0
1946 exe "let ".a:setting."=".a:safesetting
1947 elseif type(a:safesetting) == 1
1948 exe "let ".a:setting."= '".a:safesetting."'"
1949 else
1950 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1951 endif
1952 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001953 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001954
Bram Moolenaar85850f32019-07-19 22:05:51 +02001955" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001956endfun
1957
1958" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001959" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1960" but only if the setting value differs from the associated keepvar.
1961" Doing this means that netrw will not come up as having changed a
1962" setting last when it really didn't actually change it.
1963"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001964" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001965" keepvars are set up by s:NetrwOptionsSave
1966fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001967""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001968
Bram Moolenaar85850f32019-07-19 22:05:51 +02001969 " typically called from s:NetrwOptionsRestore
1970 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1971 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001972 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001973 if exists(a:keepvar)
1974 exe "let keepvarval= ".a:keepvar
1975 exe "let setting= ".a:setting
1976
1977"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1978"" call Decho("fyi: keepvarval=".keepvarval)
1979"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1980
1981 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001982"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001983 if type(a:setting) == 0
1984 exe "let ".a:setting."= ".keepvarval
1985 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001986 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001987 else
1988 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1989 endif
1990 endif
1991
1992 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001993 endif
1994
Bram Moolenaar85850f32019-07-19 22:05:51 +02001995"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001996endfun
1997
1998" ---------------------------------------------------------------------
1999" NetrwStatusLine: {{{2
2000fun! NetrwStatusLine()
2001
2002" vvv NetrwStatusLine() debugging vvv
2003" let g:stlmsg=""
2004" if !exists("w:netrw_explore_bufnr")
2005" let g:stlmsg="!X<explore_bufnr>"
2006" elseif w:netrw_explore_bufnr != bufnr("%")
2007" let g:stlmsg="explore_bufnr!=".bufnr("%")
2008" endif
2009" if !exists("w:netrw_explore_line")
2010" let g:stlmsg=" !X<explore_line>"
2011" elseif w:netrw_explore_line != line(".")
2012" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2013" endif
2014" if !exists("w:netrw_explore_list")
2015" let g:stlmsg=" !X<explore_list>"
2016" endif
2017" ^^^ NetrwStatusLine() debugging ^^^
2018
2019 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")
2020 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002021 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002022 let &laststatus = s:netrw_users_ls
2023 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2024 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2025 return ""
2026 else
2027 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2028 endif
2029endfun
2030
Bram Moolenaar85850f32019-07-19 22:05:51 +02002031" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002032" Netrw Transfer Functions: {{{1
2033" ===============================
2034
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002036" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002037" mode: =0 read remote file and insert before current line
2038" =1 read remote file and insert after current line
2039" =2 replace with remote file
2040" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002041fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002042" 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 +00002043
Bram Moolenaar5c736222010-01-06 20:54:52 +01002044 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002045 call s:NetrwOptionsSave("w:")
2046 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002047 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002048 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2049 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2050 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002051" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002052
Bram Moolenaar5c736222010-01-06 20:54:52 +01002053 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002054 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002055 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002057 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002058 elseif a:mode == 2 " replace with remote file
2059 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002060 elseif a:mode == 3 " skip read of file (leave as temporary)
2061 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002062 else
2063 exe a:mode
2064 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002065 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002066 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002067" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002068
Bram Moolenaar5c736222010-01-06 20:54:52 +01002069 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002070 let tmpfile= s:GetTempfile("")
2071 if tmpfile == ""
2072" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002073 return
2074 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002075
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002077
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002078 " attempt to repeat with previous host-file-etc
2079 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002080" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002081 let choice = b:netrw_lastfile
2082 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002083
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002084 else
2085 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002086" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002087
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002088 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002089 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002090 echomsg 'NetRead Usage:'
2091 echomsg ':Nread machine:path uses rcp'
2092 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2093 echomsg ':Nread "machine id password path" uses ftp'
2094 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2095 echomsg ':Nread fetch://machine/path uses fetch'
2096 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2097 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002098 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002099 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002100 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2101 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2102 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2103 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002104 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002105 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002106
Bram Moolenaar9964e462007-05-05 17:54:07 +00002107 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002108 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002109" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002110 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002111 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002112 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002113 else
2114 " case "... ... ..."
2115 let choice = strpart(choice,1,strlen(choice)-1)
2116 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002117
Bram Moolenaar9964e462007-05-05 17:54:07 +00002118 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002119 let wholechoice = wholechoice . " " . choice
2120 let ichoice = ichoice + 1
2121 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002122 if !exists("g:netrw_quiet")
2123 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2124 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002125" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002126 return
2127 endif
2128 let choice= a:{ichoice}
2129 endwhile
2130 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2131 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 endif
2133 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002135" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002136 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002137
Bram Moolenaar5c736222010-01-06 20:54:52 +01002138 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002139 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002140 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002141" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002142 return
2143 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002144 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002145
Bram Moolenaar8d043172014-01-23 14:24:41 +01002146 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002147" 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 +02002148 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002149" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002150 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002151" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002152 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002154
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002155 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002156 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002157 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002158 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2159 echo "(netrw) Processing your read request..."
2160 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002161
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002162 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002163 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002164 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002165" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002166 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002167 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002168 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002169 " ER: the tmpfile is full path: rcp sees C:\... as host C
2170 if s:netrw_has_nt_rcp == 1
2171 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2172 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2173 else
2174 " Any way needed it machine contains a '.'
2175 let uid_machine = g:netrw_machine .'.'. $USERNAME
2176 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002178 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2179 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2180 else
2181 let uid_machine = g:netrw_machine
2182 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002184 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 +00002185 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002186 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002187
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002188 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002189 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002190 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002191" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002192 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002193 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002194 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002195 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002196 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002197" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002198 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002199 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002200" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002201 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002202 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002203" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002204 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205 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 +00002206 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002207 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002208 endif
2209 " 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 +00002210 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002211 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002212 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002213 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002214 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002215 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002216 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002217 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002218 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2219 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002220 q!
2221 endif
2222 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002223 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002224 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002225
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002227 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2229 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002230" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002231 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002232 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002233 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002234 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002235 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002236 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002237" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002238 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002239 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002240" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002241 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002242
Bram Moolenaar97d62492012-11-15 21:28:22 +01002243 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002244 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002245 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002246" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002247 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002248 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002249 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002250" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002251 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002252 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002253" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002254 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002255 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002256
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002257 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002258 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002259" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002260 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002261 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002262 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002263" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002264 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002265 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002266" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002267
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002268 " perform ftp:
2269 " -i : turns off interactive prompting from ftp
2270 " -n unix : DON'T use <.netrc>, even though it exists
2271 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002272 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002273 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002274 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2275 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002276" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002277 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002278 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002279 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002280 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002281 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002282 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002283 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002284
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002285 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002286 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002287 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002288" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002289 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002290 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002291 else
2292 let useport= ""
2293 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002294 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2295 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002296 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002297 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2298 else
2299 let tmpfile_get = tmpfile
2300 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002301 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 +00002302 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002303 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002304
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002305 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002306 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002307 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002308" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002309 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002310 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002311 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002312 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002313" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002314 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002315 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002316
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002317 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2318 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002319" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002320 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002321 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 +00002322 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002323 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 +00002324 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002325 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002326
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002327 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002328 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002329" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002330 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2331 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002332" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2333" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2334 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 +00002335 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002336" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002337 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002338 endif
2339 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002340" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002341 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002342
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002343 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002344 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002345 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002346" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002347
Bram Moolenaar5c736222010-01-06 20:54:52 +01002348 if !executable(g:netrw_dav_cmd)
2349 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2350" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2351 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002352 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002353 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002354 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 +01002355 else
2356 " Construct execution string (four lines) which will be passed through filter
2357 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2358 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002359 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002360 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002361 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002362 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002363 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002364 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002365 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002366 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002367 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002368 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2369 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002370
Bram Moolenaar5c736222010-01-06 20:54:52 +01002371 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002372 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002373 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002374 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002375 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002376 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002377 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002378
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002379 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002380 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002381 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002382" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002383 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 +00002384 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002385 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002386
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002388 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002390 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002391" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002392 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002393 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002394 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002395 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002396" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002397 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002398 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002399 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002400 let netrw_option= "http"
2401 else
2402 let netrw_option= "ftp"
2403 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002404" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002405
Bram Moolenaar446cb832008-06-24 21:56:24 +00002406 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002407 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 +00002408 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002409 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 +00002410 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002411
Bram Moolenaar446cb832008-06-24 21:56:24 +00002412 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002413 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002414" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002415 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002416
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002417 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002418 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002419 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002420" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2421 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 +00002422 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002423 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002424
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002425 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002426 " NetRead: (file) NetRead Method #10 {{{3
2427 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002428" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2429 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002430 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2431 let b:netrw_lastfile = choice
2432
2433 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002434 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002435 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002436 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002437 endif
2438 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002439
Bram Moolenaar5c736222010-01-06 20:54:52 +01002440 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002441 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002442" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002443 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002444 unlet b:netrw_fname
2445 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002446 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 +01002447" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002448 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002449 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002450 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002451
Bram Moolenaar9964e462007-05-05 17:54:07 +00002452" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002453endfun
2454
2455" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002456" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002457fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002458" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002459
Bram Moolenaar5c736222010-01-06 20:54:52 +01002460 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002461 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002462 call s:NetrwOptionsSave("w:")
2463 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002464
Bram Moolenaar5c736222010-01-06 20:54:52 +01002465 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002466 let tmpfile= s:GetTempfile("")
2467 if tmpfile == ""
2468" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002469 return
2470 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002471
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002472 if a:0 == 0
2473 let ichoice = 0
2474 else
2475 let ichoice = 1
2476 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002477
Bram Moolenaar9964e462007-05-05 17:54:07 +00002478 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002479" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002480 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002481 " For binary writes, always write entire file.
2482 " (line numbers don't really make sense for that).
2483 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002484" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002485 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002486 elseif g:netrw_cygwin
2487 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002488 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002489" 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 +01002490 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002491 else
2492 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002493" 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 +01002494 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002495 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002496
Bram Moolenaar9964e462007-05-05 17:54:07 +00002497 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002498 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002499 " on the temporary file's name. Deletion of the temporary file during
2500 " cleanup then causes an error message.
2501 0file!
2502 endif
2503
Bram Moolenaar5c736222010-01-06 20:54:52 +01002504 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002505 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002506
Bram Moolenaar9964e462007-05-05 17:54:07 +00002507 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002508 " attempt to repeat with previous host-file-etc
2509 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002510" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002511 let choice = b:netrw_lastfile
2512 let ichoice= ichoice + 1
2513 else
2514 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002515
Bram Moolenaar8d043172014-01-23 14:24:41 +01002516 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002517 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002518 echomsg 'NetWrite Usage:"'
2519 echomsg ':Nwrite machine:path uses rcp'
2520 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2521 echomsg ':Nwrite "machine id password path" uses ftp'
2522 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2523 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2524 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2525 echomsg ':Nwrite rcp://machine/path uses rcp'
2526 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2527 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2528 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002529 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002530 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002531
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002532 elseif match(choice,"^\"") != -1
2533 if match(choice,"\"$") != -1
2534 " case "..."
2535 let choice=strpart(choice,1,strlen(choice)-2)
2536 else
2537 " case "... ... ..."
2538 let choice = strpart(choice,1,strlen(choice)-1)
2539 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002540
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002541 while match(choice,"\"$") == -1
2542 let wholechoice= wholechoice . " " . choice
2543 let ichoice = ichoice + 1
2544 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002545 if !exists("g:netrw_quiet")
2546 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2547 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002548" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002549 return
2550 endif
2551 let choice= a:{ichoice}
2552 endwhile
2553 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2554 endif
2555 endif
2556 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002557 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002558" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002559
Bram Moolenaar9964e462007-05-05 17:54:07 +00002560 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002561 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002562 if !exists("b:netrw_method") || b:netrw_method < 0
2563" call Dfunc("netrw#NetWrite : unsupported method")
2564 return
2565 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002566
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002567 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002568 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002569 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002570 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2571 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002572" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002573 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002574
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002575 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002576 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002577 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002578" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002579 if s:netrw_has_nt_rcp == 1
2580 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2581 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2582 else
2583 let uid_machine = g:netrw_machine .'.'. $USERNAME
2584 endif
2585 else
2586 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2587 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2588 else
2589 let uid_machine = g:netrw_machine
2590 endif
2591 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002592 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 +00002593 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002594
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002595 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002596 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002597 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002598" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002599 let netrw_fname = b:netrw_fname
2600
2601 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2602 let bhkeep = &l:bh
2603 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002604 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002605 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002606
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002607" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002608 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002609 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002610" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002611 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002612 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002613" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002614 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002615 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002616" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002618 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 +00002619 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002620" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2621 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 endif
2623 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2624 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002625 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002626 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002627 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002628 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002630
2631 " remove enew buffer (quietly)
2632 let filtbuf= bufnr("%")
2633 exe curbuf."b!"
2634 let &l:bh = bhkeep
2635 exe filtbuf."bw!"
2636
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002638
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002639 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002640 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002641 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002642 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002643" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644 let netrw_fname = b:netrw_fname
2645 let bhkeep = &l:bh
2646
2647 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2648 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002649 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002650 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002651 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002652
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002653 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002654 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002655" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002656 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002657 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002658" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002659 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002660 if exists("g:netrw_uid") && g:netrw_uid != ""
2661 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002662 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002663" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002664 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002665 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002666 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002667" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002668 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002669 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002670" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002671 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002672 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002673 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002674" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002675 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002676 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002677" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002678 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002679 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002680" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002681 " save choice/id/password for future use
2682 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002683
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002684 " perform ftp:
2685 " -i : turns off interactive prompting from ftp
2686 " -n unix : DON'T use <.netrc>, even though it exists
2687 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002688 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002689 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002690 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2691 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002692 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002693 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002694 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002695 let mod=1
2696 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002697
2698 " remove enew buffer (quietly)
2699 let filtbuf= bufnr("%")
2700 exe curbuf."b!"
2701 let &l:bh= bhkeep
2702 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002703
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002704 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002705 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002706 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002707" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002708 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002709 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002710 else
2711 let useport= ""
2712 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002713 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 +00002714 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002715
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002716 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002717 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002718 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002719" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002720 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2721 if executable(curl)
2722 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002723 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 +01002724 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002725 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002726 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002727
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002728 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002729 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002730 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002731" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002732
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002733 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002734 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2735 let bhkeep = &l:bh
2736
2737 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2738 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002739 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002740 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002741
Bram Moolenaarff034192013-04-24 18:51:19 +02002742 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002743 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002744 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002745 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002746 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002747 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002748 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002749 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002750 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002751 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002752
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002753 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002754 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002755 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002756
2757 " remove enew buffer (quietly)
2758 let filtbuf= bufnr("%")
2759 exe curbuf."b!"
2760 let &l:bh = bhkeep
2761 exe filtbuf."bw!"
2762
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002763 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002764
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002765 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002766 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002767 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002768" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002769 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 +00002770 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002771
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002772 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002773 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002774 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002775" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002776 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2778 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2779 else
2780 let uid_machine = g:netrw_machine
2781 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002782
2783 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2784 let bhkeep = &l:bh
2785 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002786 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002787 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002788
Bram Moolenaarff034192013-04-24 18:51:19 +02002789 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002790 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002791" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002792 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002793 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002794 let filtbuf= bufnr("%")
2795 exe curbuf."b!"
2796 let &l:bh = bhkeep
2797 exe filtbuf."bw!"
2798 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002799
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002800 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002801 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002802 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002803 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002804 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002806 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002807
Bram Moolenaar5c736222010-01-06 20:54:52 +01002808 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002809" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002810 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002811" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002812 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002813 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002814 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002815
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002816 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002817 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002818 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002819" 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 +02002820 elseif !exists("leavemod")
2821 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002822" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002823 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002824" 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 +00002825 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002826
Bram Moolenaar9964e462007-05-05 17:54:07 +00002827" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002828endfun
2829
2830" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002831" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002832" uses NetRead to get a copy of the file into a temporarily file,
2833" then sources that file,
2834" then removes that file.
2835fun! netrw#NetSource(...)
2836" call Dfunc("netrw#NetSource() a:0=".a:0)
2837 if a:0 > 0 && a:1 == '?'
2838 " give help
2839 echomsg 'NetSource Usage:'
2840 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2841 echomsg ':Nsource fetch://machine/path uses fetch'
2842 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002843 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002844 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2845 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2846 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2847 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2848 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002849 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002850 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002851 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002852 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002853" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002854 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002855" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002856 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002857" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002858 if delete(s:netrw_tmpfile)
2859 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2860 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002861 unlet s:netrw_tmpfile
2862 else
2863 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2864 endif
2865 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002866 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002867 endif
2868" call Dret("netrw#NetSource")
2869endfun
2870
Bram Moolenaar8d043172014-01-23 14:24:41 +01002871" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002872" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2873" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002874fun! netrw#SetTreetop(iscmd,...)
2875" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2876" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002877
Bram Moolenaar85850f32019-07-19 22:05:51 +02002878 " iscmd==0: netrw#SetTreetop called using gn mapping
2879 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2880" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002881 " clear out the current tree
2882 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002883" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002884 let inittreetop= w:netrw_treetop
2885 unlet w:netrw_treetop
2886 endif
2887 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002888" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002889 unlet w:netrw_treedict
2890 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002891" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002892
Bram Moolenaar85850f32019-07-19 22:05:51 +02002893 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002894 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002895" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002896 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002897 if isdirectory(s:NetrwFile(a:1))
2898" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002899 let treedir = a:1
2900 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002901 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002902 let treedir = b:netrw_curdir."/".a:1
2903 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002904" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002905 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002906 " normally the cursor is left in the message window.
2907 " However, here this results in the directory being listed in the message window, which is not wanted.
2908 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002909 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002910 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002911 let treedir = "."
2912 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002913 endif
2914 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002915" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002916
2917 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002918 let islocal= expand("%") !~ '^\a\{3,}://'
2919" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002920
2921 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002922 if islocal
2923 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2924 else
2925 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2926 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002927
Bram Moolenaara6878372014-03-22 21:02:50 +01002928" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002929endfun
2930
Bram Moolenaar9964e462007-05-05 17:54:07 +00002931" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002932" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002933" readcmd == %r : replace buffer with newly read file
2934" == 0r : read file at top of buffer
2935" == r : read file after current line
2936" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002937fun! s:NetrwGetFile(readcmd, tfile, method)
2938" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002939
2940 " readcmd=='t': simply do nothing
2941 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002942" 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 +01002943" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002944 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002945 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002946
Bram Moolenaar9964e462007-05-05 17:54:07 +00002947 " get name of remote filename (ie. url and all)
2948 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002949" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002950
Bram Moolenaar9964e462007-05-05 17:54:07 +00002951 if exists("*NetReadFixup")
2952 " for the use of NetReadFixup (not otherwise used internally)
2953 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002954 endif
2955
Bram Moolenaar9964e462007-05-05 17:54:07 +00002956 if a:readcmd[0] == '%'
2957 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002958" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002959
2960 " rename the current buffer to the temp file (ie. tfile)
2961 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002962 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002963 else
2964 let tfile= a:tfile
2965 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002966 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002967
2968 " edit temporary file (ie. read the temporary file in)
2969 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002970" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971 call zip#Browse(tfile)
2972 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002973" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002974 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002975 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002976" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002977 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002978 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002979" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002980 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002981 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002982" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002983 call tar#Browse(tfile)
2984 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002985" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002986 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002987 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002988" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002989 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002990 endif
2991
2992 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002993 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002994
Bram Moolenaar71badf92023-04-22 22:40:14 +01002995 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002996 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002997 " Note that isk must not include a "/" for scripts.vim
2998 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002999" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
3000" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003001" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003002" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3003 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003004 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003005 filetype detect
3006" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003007 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003008" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003009 let line1 = 1
3010 let line2 = line("$")
3011
Bram Moolenaar8d043172014-01-23 14:24:41 +01003012 elseif !&ma
3013 " 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 +01003014 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003015" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003016 return
3017
Bram Moolenaar9964e462007-05-05 17:54:07 +00003018 elseif s:FileReadable(a:tfile)
3019 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003020" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003021 let curline = line(".")
3022 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003023" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003024 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003025 let line1= curline + 1
3026 let line2= line("$") - lastline + 1
3027
3028 else
3029 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003030" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3031" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003032 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003033" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003034 return
3035 endif
3036
3037 " User-provided (ie. optional) fix-it-up command
3038 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003039" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003040 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003041" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003042" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003043 endif
3044
Bram Moolenaaradc21822011-04-01 18:03:16 +02003045 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003046 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003047 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003048 endif
3049
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003050" 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 +00003051
3052 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003053" redraw!
3054
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003055" 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 +00003056" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003057endfun
3058
Bram Moolenaar9964e462007-05-05 17:54:07 +00003059" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003060" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003061" Input:
3062" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3063" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003064" b:netrw_method= 1: rcp
3065" 2: ftp + <.netrc>
3066" 3: ftp + machine, id, password, and [path]filename
3067" 4: scp
3068" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003069" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003070" 7: rsync
3071" 8: fetch
3072" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003073" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003074" g:netrw_machine= hostname
3075" b:netrw_fname = filename
3076" g:netrw_port = optional port number (for ftp)
3077" g:netrw_choice = copy of input url (choice)
3078fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003079" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003080
Bram Moolenaar251e1912011-06-19 05:09:16 +02003081 " sanity check: choice should have at least three slashes in it
3082 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3083 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3084 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003085" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003086 return
3087 endif
3088
Bram Moolenaar5c736222010-01-06 20:54:52 +01003089 " record current g:netrw_machine, if any
3090 " curmachine used if protocol == ftp and no .netrc
3091 if exists("g:netrw_machine")
3092 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003093" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003094 else
3095 let curmachine= "N O T A HOST"
3096 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003097 if exists("g:netrw_port")
3098 let netrw_port= g:netrw_port
3099 endif
3100
3101 " insure that netrw_ftp_cmd starts off every method determination
3102 " with the current g:netrw_ftp_cmd
3103 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003104
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003105 " initialization
3106 let b:netrw_method = 0
3107 let g:netrw_machine = ""
3108 let b:netrw_fname = ""
3109 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003110 let g:netrw_choice = a:choice
3111
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003112 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003113 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003114 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3115 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003116 " rcpurm : rcp://[user@]host/filename Use rcp
3117 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003118 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003119 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003120 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003121 " rsyncurm : rsync://host[:port]/path Use rsync
3122 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3123 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003124 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003125 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3126 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003127 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3128 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003130 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003131 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003132 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003133 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003134 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003135 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003136 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003137
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003138" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003140 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003141 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003142" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003143 let b:netrw_method = 1
3144 let userid = substitute(a:choice,rcpurm,'\1',"")
3145 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3146 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003147 if userid != ""
3148 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003150
Bram Moolenaaradc21822011-04-01 18:03:16 +02003151 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003152 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003153" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003154 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003155 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3156 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3157 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003158
Bram Moolenaar15146672011-10-20 22:22:38 +02003159 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003160 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003161" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003162 let b:netrw_method = 5
3163 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3164 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003165 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003166
Bram Moolenaaradc21822011-04-01 18:03:16 +02003167 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003168 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003169" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003170 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003171 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003172 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3173 else
3174 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3175 endif
3176 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003177
Bram Moolenaaradc21822011-04-01 18:03:16 +02003178 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003179 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003180" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003181 let b:netrw_method = 7
3182 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3183 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003184
Bram Moolenaaradc21822011-04-01 18:03:16 +02003185 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003186 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003187" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003188 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003189 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3190 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3191 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003192" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003193 if userid != ""
3194 let g:netrw_uid= userid
3195 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003196
Bram Moolenaaradc21822011-04-01 18:03:16 +02003197 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003198 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003199 call NetUserPass("ftp:".g:netrw_machine)
3200 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003201 " if there's a change in hostname, require password re-entry
3202 unlet s:netrw_passwd
3203 endif
3204 if exists("netrw_port")
3205 unlet netrw_port
3206 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003207 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003208
Bram Moolenaar446cb832008-06-24 21:56:24 +00003209 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003210 let b:netrw_method = 3
3211 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003212 let host= substitute(g:netrw_machine,'\..*$','','')
3213 if exists("s:netrw_hup[host]")
3214 call NetUserPass("ftp:".host)
3215
Nir Lichtman1e34b952024-05-08 19:19:34 +02003216 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003217" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3218" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003219 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003220 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003221" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003222 endif
3223 let b:netrw_method= 2
3224 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003225" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003226 let b:netrw_method= 2
3227 else
3228 if !exists("g:netrw_uid") || g:netrw_uid == ""
3229 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003230 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003231 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003232 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003233 endif
3234 let b:netrw_method= 3
3235 endif
3236 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003237
Bram Moolenaaradc21822011-04-01 18:03:16 +02003238 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003239 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003240" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003241 let b:netrw_method = 8
3242 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3243 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3244 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3245 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003246
Bram Moolenaaradc21822011-04-01 18:03:16 +02003247 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003248 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003249" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003251 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3252 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003253 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003254 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003255 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003256
Bram Moolenaaradc21822011-04-01 18:03:16 +02003257 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003258 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003259" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003260 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003261 let b:netrw_method = 3
3262 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3263 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003264
Bram Moolenaar9964e462007-05-05 17:54:07 +00003265 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003266 let b:netrw_method = 2
3267 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3268 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3269 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003270
Bram Moolenaaradc21822011-04-01 18:03:16 +02003271 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003272 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003273" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003274 let b:netrw_method = 9
3275 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3276 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003277
Bram Moolenaaradc21822011-04-01 18:03:16 +02003278 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003279 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003280" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003281 let b:netrw_method = 1
3282 let userid = substitute(a:choice,rcphf,'\2',"")
3283 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3284 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003285" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3286" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3287" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3288" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003289 if userid != ""
3290 let g:netrw_uid= userid
3291 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003292
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003293 " Method#10: file://user@hostname/...path-to-file {{{3
3294 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003295" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003296 let b:netrw_method = 10
3297 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003298" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003299
Bram Moolenaaradc21822011-04-01 18:03:16 +02003300 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003301 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003302 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003303 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003304 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003305 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003307 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003308
Bram Moolenaar81695252004-12-29 20:58:21 +00003309 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003310 " remove any leading [:#] from port number
3311 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3312 elseif exists("netrw_port")
3313 " retain port number as implicit for subsequent ftp operations
3314 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003315 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003316
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003317" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3318" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3319" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3320" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003321" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003322" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003323" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003324" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003325" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003326" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003327" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003328" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330
Bram Moolenaar9964e462007-05-05 17:54:07 +00003331" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003332" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003333" Usage: :call NetUserPass() -- will prompt for userid and password
3334" :call NetUserPass("uid") -- will prompt for password
3335" :call NetUserPass("uid","password") -- sets global userid and password
3336" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3337" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338fun! NetUserPass(...)
3339
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003340" call Dfunc("NetUserPass() a:0=".a:0)
3341
3342 if !exists('s:netrw_hup')
3343 let s:netrw_hup= {}
3344 endif
3345
Bram Moolenaar071d4272004-06-13 20:20:40 +00003346 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003347 " case: no input arguments
3348
3349 " change host and username if not previously entered; get new password
3350 if !exists("g:netrw_machine")
3351 let g:netrw_machine= input('Enter hostname: ')
3352 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003354 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355 let g:netrw_uid= input('Enter username: ')
3356 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003357 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003358 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003359
3360 " set up hup database
3361 let host = substitute(g:netrw_machine,'\..*$','','')
3362 if !exists('s:netrw_hup[host]')
3363 let s:netrw_hup[host]= {}
3364 endif
3365 let s:netrw_hup[host].uid = g:netrw_uid
3366 let s:netrw_hup[host].passwd = s:netrw_passwd
3367
3368 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003369 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003370
3371 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003372 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003373 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003374" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003375 let host = substitute(a:1,'^ftp:','','')
3376 let host = substitute(host,'\..*','','')
3377 if exists("s:netrw_hup[host]")
3378 let g:netrw_uid = s:netrw_hup[host].uid
3379 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003380" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3381" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003382 else
3383 let g:netrw_uid = input("Enter UserId: ")
3384 let s:netrw_passwd = inputsecret("Enter Password: ")
3385 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003386
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003387 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003388 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003389" 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 +02003390 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003391 if g:netrw_machine =~ '[0-9.]\+'
3392 let host= g:netrw_machine
3393 else
3394 let host= substitute(g:netrw_machine,'\..*$','','')
3395 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003396 else
3397 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003398 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003399 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003400" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003401 if exists("g:netrw_passwd")
3402 " ask for password if one not previously entered
3403 let s:netrw_passwd= g:netrw_passwd
3404 else
3405 let s:netrw_passwd = inputsecret("Enter Password: ")
3406 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003407 endif
3408
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003409" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003410 if exists("host")
3411 if !exists('s:netrw_hup[host]')
3412 let s:netrw_hup[host]= {}
3413 endif
3414 let s:netrw_hup[host].uid = g:netrw_uid
3415 let s:netrw_hup[host].passwd = s:netrw_passwd
3416 endif
3417
3418 elseif a:0 == 2
3419 let g:netrw_uid = a:1
3420 let s:netrw_passwd = a:2
3421
3422 elseif a:0 == 3
3423 " enter hostname, user-id, and password into the hup dictionary
3424 let host = substitute(a:1,'^\a\+:','','')
3425 let host = substitute(host,'\..*$','','')
3426 if !exists('s:netrw_hup[host]')
3427 let s:netrw_hup[host]= {}
3428 endif
3429 let s:netrw_hup[host].uid = a:2
3430 let s:netrw_hup[host].passwd = a:3
3431 let g:netrw_uid = s:netrw_hup[host].uid
3432 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003433" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3434" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003436
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003437" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003438endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439
Bram Moolenaar85850f32019-07-19 22:05:51 +02003440" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003441" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003442" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003444" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003445" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3446fun! s:ExplorePatHls(pattern)
3447" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3448 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003449" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003450 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003451" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003452 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3453" call Dret("s:ExplorePatHls repat<".repat.">")
3454 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003455endfun
3456
3457" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003458" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003459" 0: (user: <mb>) bookmark current directory
3460" 1: (user: <gb>) change to the bookmarked directory
3461" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003462" 3: (browsing) records current directory history
3463" 4: (user: <u>) go up (previous) directory, using history
3464" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003465" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003466fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003467" 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 +02003468 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3469" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3470 return
3471 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003472
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003473 let ykeep = @@
3474 let curbufnr = bufnr("%")
3475
Bram Moolenaar9964e462007-05-05 17:54:07 +00003476 if a:chg == 0
3477 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003478" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003479 if exists("s:netrwmarkfilelist_{curbufnr}")
3480 call s:NetrwBookmark(0)
3481 echo "bookmarked marked files"
3482 else
3483 call s:MakeBookmark(a:curdir)
3484 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003485 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003486
KSR-Yasudaf4498252023-10-06 03:34:17 +09003487 try
3488 call s:NetrwBookHistSave()
3489 catch
3490 endtry
3491
Bram Moolenaar9964e462007-05-05 17:54:07 +00003492 elseif a:chg == 1
3493 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003494" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003495 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003496" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003497 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003498 else
3499 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3500 endif
3501
3502 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003503" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003504 let didwork= 0
3505 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003506" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003507 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003508" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003509 let cnt= 1
3510 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003511" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003512 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003513 let didwork = 1
3514 let cnt = cnt + 1
3515 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003516 endif
3517
3518 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003519 " Note: history is saved only when PerformListing is done;
3520 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3521 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003522 let first = 1
3523 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003524 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003525 while ( first || cnt != g:netrw_dirhistcnt )
3526" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003527 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003528" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003529 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003530 let didwork= 1
3531 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003532 let histcnt = histcnt + 1
3533 let first = 0
3534 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003535 if cnt < 0
3536 let cnt= cnt + g:netrw_dirhistmax
3537 endif
3538 endwhile
3539 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003540 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003541 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003542 if didwork
3543 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3544 endif
3545
3546 elseif a:chg == 3
3547 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003548" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003549 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 +02003550 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003551 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3552 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003553 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003554" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003555 endif
3556
3557 elseif a:chg == 4
3558 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003559" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003560 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003561 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3562 if g:netrw_dirhistcnt < 0
3563 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003564 endif
3565 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003566 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003567 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003568 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3569" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003570 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003571 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003572" call Decho("setl ma noro",'~'.expand("<slnum>"))
3573 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003574 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003575" call Decho("setl nomod",'~'.expand("<slnum>"))
3576" 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 +00003577 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003578" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3579 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003580 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003581 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003582 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003583 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003584 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003585 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003586 echo "Sorry, no predecessor directory exists yet"
3587 endif
3588
3589 elseif a:chg == 5
3590 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003591" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003592 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003593 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3594 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3595" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003596 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003597" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003598 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003599 sil! NetrwKeepj %d _
3600" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3601" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003602 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003603" 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 +02003604 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003605" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3606 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003607 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003608 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3609 if g:netrw_dirhistcnt < 0
3610 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003611 endif
3612 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003613 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003614 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003615 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003616 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003617 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003618
3619 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003620" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003621 if exists("s:netrwmarkfilelist_{curbufnr}")
3622 call s:NetrwBookmark(1)
3623 echo "removed marked files from bookmarks"
3624 else
3625 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003626 let iremove = v:count
3627 let dremove = g:netrw_bookmarklist[iremove - 1]
3628" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003629 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003630" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3631 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3632 echo "removed ".dremove." from g:netrw_bookmarklist"
3633" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003634 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003635" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003636
3637 try
3638 call s:NetrwBookHistSave()
3639 catch
3640 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003641 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003642 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003643 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003644 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003645" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003646endfun
3647
3648" ---------------------------------------------------------------------
3649" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003650" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003651" Sister function: s:NetrwBookHistSave()
3652fun! s:NetrwBookHistRead()
3653" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003654 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003655" 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 +02003656 return
3657 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003658 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003659
3660 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003661 if !exists("s:netrw_initbookhist")
3662 let home = s:NetrwHome()
3663 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003664 if filereadable(s:NetrwFile(savefile))
3665" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003666 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003667 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003668
3669 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003670 if g:netrw_dirhistmax > 0
3671 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003672 if filereadable(s:NetrwFile(savefile))
3673" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003674 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003675 endif
3676 let s:netrw_initbookhist= 1
3677 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003678 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003679 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003680
Bram Moolenaar97d62492012-11-15 21:28:22 +01003681 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003682" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3683" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003684" call Dret("s:NetrwBookHistRead")
3685endfun
3686
3687" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003688" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003689" Sister function: s:NetrwBookHistRead()
3690" I used to do this via viminfo but that appears to
3691" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003692" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3693" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003694" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003695fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003696" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003697 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003698" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003699 return
3700 endif
3701
Bram Moolenaar5c736222010-01-06 20:54:52 +01003702 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003703" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003704 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003705
3706 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003707 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003708" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003709 if g:netrw_use_noswf
3710 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3711 else
3712 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3713 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003714 setl nocin noai noci magic nospell nohid wig= noaw
3715 setl ma noro write
3716 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003717 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003718
Bram Moolenaar85850f32019-07-19 22:05:51 +02003719 " rename enew'd file: .netrwhist -- no attempt to merge
3720 " record dirhistmax and current dirhistcnt
3721 " save history
3722" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003723 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003724 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003725 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3726 if g:netrw_dirhistmax > 0
3727 let lastline = line("$")
3728 let cnt = g:netrw_dirhistcnt
3729 let first = 1
3730 while ( first || cnt != g:netrw_dirhistcnt )
3731 let lastline= lastline + 1
3732 if exists("g:netrw_dirhist_{cnt}")
3733 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3734" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3735 endif
3736 let first = 0
3737 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3738 if cnt < 0
3739 let cnt= cnt + g:netrw_dirhistmax
3740 endif
3741 endwhile
3742 exe "sil! w! ".savefile
3743" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3744 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003745
Bram Moolenaar85850f32019-07-19 22:05:51 +02003746 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003747 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003748 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003749" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003750 " merge and write .netrwbook
3751 let savefile= s:NetrwHome()."/.netrwbook"
3752
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003753 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003754 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003755 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003756 for bdm in booklist
3757 if index(g:netrw_bookmarklist,bdm) == -1
3758 call add(g:netrw_bookmarklist,bdm)
3759 endif
3760 endfor
3761 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003762 endif
3763
3764 " construct and save .netrwbook
3765 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003766 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003767" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003768 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003769
3770 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003771 let bgone= bufnr("%")
3772 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003773 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003774
3775" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003776endfun
3777
3778" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003779" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3780" list of the contents of a local or remote directory. It is assumed that the
3781" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3782" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003783" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003784fun! s:NetrwBrowse(islocal,dirname)
3785 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003786" 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 +02003787" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3788" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3789" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003790
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003791 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3792 " This is useful when one edits a local file, then :e ., then :Rex
3793 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3794 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003795" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003796 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003797
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003798 " s:NetrwBrowse : initialize history {{{3
3799 if !exists("s:netrw_initbookhist")
3800 NetrwKeepj call s:NetrwBookHistRead()
3801 endif
3802
3803 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003804 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003805 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003806" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003807 else
3808 let dirname= a:dirname
3809 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003810
Bram Moolenaar85850f32019-07-19 22:05:51 +02003811 " repoint t:netrw_lexbufnr if appropriate
3812 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3813" call Decho("set repointlexbufnr to true!")
3814 let repointlexbufnr= 1
3815 endif
3816
3817 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003818 if exists("s:netrw_skipbrowse")
3819 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003820" 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 +01003821" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003822 return
3823 endif
3824 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003825 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003826" call Dret("s:NetrwBrowse : missing shellescape()")
3827 return
3828 endif
3829 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003830 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003831" call Dret("s:NetrwBrowse : missing fnameescape()")
3832 return
3833 endif
3834
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003835 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003836 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003837
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003838 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003839 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3840 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3841" call Decho("clearing marked files",'~'.expand("<slnum>"))
3842 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3843 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003844 endif
3845
3846 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003847 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003848" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3849" 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 +02003850 if s:NetrwLcd(dirname)
3851" call Dret("s:NetrwBrowse : lcd failure")
3852 return
3853 endif
3854 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003855" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003856
Bram Moolenaar5c736222010-01-06 20:54:52 +01003857 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003858 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003859" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003860 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003861" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003862 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003863 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003864 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003865" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003866
3867 " remove any filetype indicator from end of dirname, except for the
3868 " "this is a directory" indicator (/).
3869 " There shouldn't be one of those here, anyway.
3870 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003871" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003872 call s:RemotePathAnalysis(dirname)
3873
3874 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3875 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003876 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003877 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003878" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003879 let b:netrw_curdir = dirname
3880 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003881 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003882 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3883 sil call netrw#NetRead(2,url)
3884 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003885" call Decho("url<".url.">",'~'.expand("<slnum>"))
3886" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3887" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003888 if s:path =~ '.bz2'
3889 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3890 elseif s:path =~ '.gz'
3891 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3892 elseif s:path =~ '.gz'
3893 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3894 else
3895 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3896 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003897 endif
3898
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003899 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003900 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003901 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003902" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003903 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003904" 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 +00003905
Bram Moolenaar446cb832008-06-24 21:56:24 +00003906" call Dret("s:NetrwBrowse : file<".s:fname.">")
3907 return
3908 endif
3909
Bram Moolenaaradc21822011-04-01 18:03:16 +02003910 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003911 call s:UseBufWinVars()
3912
3913 " set up some variables {{{3
3914 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003915 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003916 let s:last_sort_by = g:netrw_sort_by
3917
3918 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003919 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003920
Bram Moolenaar97d62492012-11-15 21:28:22 +01003921 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003922" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003923 let svpos = winsaveview()
3924" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003925 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003926
Bram Moolenaar446cb832008-06-24 21:56:24 +00003927 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003928 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3929 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3930" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3931" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3932 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3933 else
3934" " call Decho("2match none",'~'.expand("<slnum>"))
3935 2match none
3936 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003937 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003938 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003939 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003940" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003941 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003942" 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 +01003943" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003944 return
3945 endif
3946
3947 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003948" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003949 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003950 if b:netrw_curdir =~ '[/\\]$'
3951 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3952 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003953 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003954 let b:netrw_curdir= b:netrw_curdir."/"
3955 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003956 if b:netrw_curdir == ''
3957 if has("amiga")
3958 " On the Amiga, the empty string connotes the current directory
3959 let b:netrw_curdir= getcwd()
3960 else
3961 " under unix, when the root directory is encountered, the result
3962 " from the preceding substitute is an empty string.
3963 let b:netrw_curdir= '/'
3964 endif
3965 endif
3966 if !a:islocal && b:netrw_curdir !~ '/$'
3967 let b:netrw_curdir= b:netrw_curdir.'/'
3968 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003969" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003970
3971 " ------------
3972 " (local only) {{{3
3973 " ------------
3974 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003975" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003976
3977 " Set up ShellCmdPost handling. Append current buffer to browselist
3978 call s:LocalFastBrowser()
3979
3980 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3981 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003982" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3983" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003984 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003985 if s:NetrwLcd(b:netrw_curdir)
3986" call Dret("s:NetrwBrowse : lcd failure")
3987 return
3988 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003989 endif
3990 endif
3991
3992 " --------------------------------
3993 " remote handling: {{{3
3994 " --------------------------------
3995 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003996" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003997
Bram Moolenaar97d62492012-11-15 21:28:22 +01003998 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003999" 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 +02004000 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004001 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004002" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004003 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4004 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4005 if dirname !~ '/$'
4006 let dirname= dirname.'/'
4007 endif
4008 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004009" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004010 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004011 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004012" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004013 endif
4014
4015 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4016 if dirname !~ dirpat
4017 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004018 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004019 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004020 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004021" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004022 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004023" 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 +00004024" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4025 return
4026 endif
4027 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004028" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004029 endif " (additional remote handling)
4030
Bram Moolenaar85850f32019-07-19 22:05:51 +02004031 " -------------------------------
4032 " Perform Directory Listing: {{{3
4033 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004034 NetrwKeepj call s:NetrwMaps(a:islocal)
4035 NetrwKeepj call s:NetrwCommands(a:islocal)
4036 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004037
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004038 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004039 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004040" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4041
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004042 " If there is a rexposn: restore position with rexposn
4043 " Otherwise : set rexposn
4044 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004045" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4046 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4047 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4048 NetrwKeepj exe w:netrw_bannercnt
4049 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004050 else
4051 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4052 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004053 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004054 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004055" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004056 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004057 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004058
Bram Moolenaar85850f32019-07-19 22:05:51 +02004059 " repoint t:netrw_lexbufnr if appropriate
4060 if exists("repointlexbufnr")
4061 let t:netrw_lexbufnr= bufnr("%")
4062" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4063 endif
4064
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004065 " restore position
4066 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004067" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4068 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004069 endif
4070
Bram Moolenaara6878372014-03-22 21:02:50 +01004071 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004072 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4073 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004074" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4075" 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 +02004076" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004077 return
4078endfun
4079
4080" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004081" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4082" may not apply correctly; ie. netrw's idea of the current directory may
4083" differ from vim's. This function insures that netrw's idea of the current
4084" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004085" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004086fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004087" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4088" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4089" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4090" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4091" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004092
4093 " clean up any leading treedepthstring
4094 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4095 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004096" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004097 else
4098 let fname= a:fname
4099 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004100
4101 if g:netrw_keepdir
4102 " vim's idea of the current directory possibly may differ from netrw's
4103 if !exists("b:netrw_curdir")
4104 let b:netrw_curdir= getcwd()
4105 endif
4106
Nir Lichtman1e34b952024-05-08 19:19:34 +02004107 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004108 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004109 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004110 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004111" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004112 else
4113 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004114 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004115" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004116 endif
4117
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004118 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004119 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004120 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004121" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004122 else
4123 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004124 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004125" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004126 endif
4127 else
4128 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004129 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004130" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4131" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4132" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004133 endif
4134
Bram Moolenaar85850f32019-07-19 22:05:51 +02004135" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004136 return ret
4137endfun
4138
4139" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004140" s:NetrwFileInfo: supports qf (query for file information) {{{2
4141fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004142" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004143 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004144 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004145 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004146 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004147 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004148 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004149 let lsopt= "-lsadh --si"
4150 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004151" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004152 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004153
4154 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004155 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004156" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004157
Bram Moolenaara6878372014-03-22 21:02:50 +01004158 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004159 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004160" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004161
4162 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004163 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004165
Bram Moolenaar446cb832008-06-24 21:56:24 +00004166 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004167" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004168 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004169" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004170 endif
4171 else
4172 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004173" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4174 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004175 let fname= substitute(a:fname,".$","","")
4176 else
4177 let fname= a:fname
4178 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004179 let t = getftime(s:NetrwFile(fname))
4180 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004181 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004182 let sz= s:NetrwHumanReadable(sz)
4183 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004184 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4185" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004186 endif
4187 else
4188 echo "sorry, \"qf\" not supported yet for remote files"
4189 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004190 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004191" call Dret("s:NetrwFileInfo")
4192endfun
4193
4194" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004195" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4196fun! s:NetrwFullPath(filename)
4197" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4198 let filename= a:filename
4199 if filename !~ '^/'
4200 let filename= resolve(getcwd().'/'.filename)
4201 endif
4202 if filename != "/" && filename =~ '/$'
4203 let filename= substitute(filename,'/$','','')
4204 endif
4205" " call Dret("s:NetrwFullPath <".filename.">")
4206 return filename
4207endfun
4208
4209" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004210" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004211" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004212" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004213" 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 +00004214fun! s:NetrwGetBuffer(islocal,dirname)
4215" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004216" 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 +02004217" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4218" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004219 let dirname= a:dirname
4220
4221 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004222" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004223 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004224" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004225 let s:netrwbuf= {}
4226 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004227" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4228" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4229
4230 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4231 let bufnum = -1
4232
4233 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4234 if has_key(s:netrwbuf,"NetrwTreeListing")
4235 let bufnum= s:netrwbuf["NetrwTreeListing"]
4236 else
4237 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4238 endif
4239" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4240 if !bufexists(bufnum)
4241 call remove(s:netrwbuf,"NetrwTreeListing"])
4242 let bufnum= -1
4243 endif
4244 elseif bufnr("NetrwTreeListing") != -1
4245 let bufnum= bufnr("NetrwTreeListing")
4246" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4247 else
4248" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4249 let bufnum= -1
4250 endif
4251
4252 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004253 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004254" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004255 if !bufexists(bufnum)
4256 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4257 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004258 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004259
Bram Moolenaar446cb832008-06-24 21:56:24 +00004260 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004261" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004262 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004263 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004264" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4265
Bram Moolenaar71badf92023-04-22 22:40:14 +01004266 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004267 " IF the buffer already has the desired name
4268 " AND it is empty
4269 let curbuf = bufname("%")
4270 if curbuf == '.'
4271 let curbuf = getcwd()
4272 endif
4273" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004274" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004275" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4276" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4277" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4278" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4279 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004280" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4281 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004282 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004283" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004284 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004285 " 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 +00004286
4287 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004288 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004289" 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 +00004290 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004291" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004292 " name the buffer
4293 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4294 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004295" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004296 let w:netrw_treebufnr = bufnr("%")
4297 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004298 if g:netrw_use_noswf
4299 setl nobl bt=nofile noswf
4300 else
4301 setl nobl bt=nofile
4302 endif
4303 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4304 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4305 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4306 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004307" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004308 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004309 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004310 " enter the new buffer into the s:netrwbuf dictionary
4311 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4312" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4313" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004314 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004315" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004316
4317 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004318" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004319 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004320 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004321 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004322
4323 if &ft == "netrw"
4324" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4325 exe "sil! NetrwKeepj noswapfile b ".bufnum
4326" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004327 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004328" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4329 call s:NetrwEditBuf(bufnum)
4330" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004331 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004332" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004333 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004334 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004335 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004336
4337 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004338 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004339
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004340 if line("$") <= 1 && getline(1) == ""
4341 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004342 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004343" 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>"))
4344" 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 +01004345" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4346 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004347
Bram Moolenaar97d62492012-11-15 21:28:22 +01004348 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004349" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004350 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004351 sil NetrwKeepj %d _
4352" 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>"))
4353" 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 +01004354" 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 +00004355 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004356
Bram Moolenaar446cb832008-06-24 21:56:24 +00004357 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004358" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4359" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004360 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004361 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004362 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004363" 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>"))
4364" 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 +01004365" 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 +00004366 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004367
Bram Moolenaar446cb832008-06-24 21:56:24 +00004368 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004369" 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>"))
4370" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4371" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004372 return 1
4373 endif
4374 endif
4375
4376 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4377 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4378 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4379 " med 1 D H
4380 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004381" 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 +00004382 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004383 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004384 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004385
4386 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004387" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4388" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4389 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004390
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004391" 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>"))
4392" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4393" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004394 return 0
4395endfun
4396
4397" ---------------------------------------------------------------------
4398" s:NetrwGetcwd: get the current directory. {{{2
4399" Change backslashes to forward slashes, if any.
4400" If doesc is true, escape certain troublesome characters
4401fun! s:NetrwGetcwd(doesc)
4402" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4403 let curdir= substitute(getcwd(),'\\','/','ge')
4404 if curdir !~ '[\/]$'
4405 let curdir= curdir.'/'
4406 endif
4407 if a:doesc
4408 let curdir= fnameescape(curdir)
4409 endif
4410" call Dret("NetrwGetcwd <".curdir.">")
4411 return curdir
4412endfun
4413
4414" ---------------------------------------------------------------------
4415" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4416fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004417" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4418" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4419 let keepsol= &l:sol
4420 setl nosol
4421
Bram Moolenaar446cb832008-06-24 21:56:24 +00004422 call s:UseBufWinVars()
4423
4424 " insure that w:netrw_liststyle is set up
4425 if !exists("w:netrw_liststyle")
4426 if exists("g:netrw_liststyle")
4427 let w:netrw_liststyle= g:netrw_liststyle
4428 else
4429 let w:netrw_liststyle= s:THINLIST
4430 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004431" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004432 endif
4433
4434 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4435 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004436" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004437 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004438 let dirname= "./"
4439 let curline= getline('.')
4440
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004441 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004442 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004443 let s:netrw_skipbrowse= 1
4444 echo 'Pressing "s" also works'
4445
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004446 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004447 let s:netrw_skipbrowse= 1
4448 echo 'Press "S" to edit sorting sequence'
4449
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004450 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004451 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004452 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004453
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004454 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004455 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004456 let s:netrw_skipbrowse= 1
4457 echo 'Pressing "a" also works'
4458
4459 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004460 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004461 endif
4462
4463 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004464" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004465 NetrwKeepj norm! 0
4466 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004467
4468 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004469" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004470 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004471 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4472
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004473 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004474" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004475 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004476 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004477
4478 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004479" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004480 let dirname= getline('.')
4481
4482 if !exists("b:netrw_cpf")
4483 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004484 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 +01004485 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004486" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004487 endif
4488
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004489" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004491" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4492" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004493 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004494 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004495 else
4496 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004497 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004498 endif
4499 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004500 let eofname= filestart + b:netrw_cpf + 1
4501 if eofname <= col("$")
4502 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004503 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004504 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004505 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004506 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004507 let dirname = @a
4508 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004509" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004510 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004511" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004512 endif
4513
4514 " symlinks are indicated by a trailing "@". Remove it before further processing.
4515 let dirname= substitute(dirname,"@$","","")
4516
4517 " executables are indicated by a trailing "*". Remove it before further processing.
4518 let dirname= substitute(dirname,"\*$","","")
4519
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004520 let &l:sol= keepsol
4521
Bram Moolenaar446cb832008-06-24 21:56:24 +00004522" call Dret("s:NetrwGetWord <".dirname.">")
4523 return dirname
4524endfun
4525
4526" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004527" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4528" g:netrw_bufsettings will be used after the listing is produced.
4529" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004530fun! s:NetrwListSettings(islocal)
4531" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004532" 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 +00004533 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004534" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4535 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4536 setl bt=nofile nobl ma nonu nowrap noro nornu
4537 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004538 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004539 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004540 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004541" call Dredir("ls!","s:NetrwListSettings")
4542" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004543 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004544 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004546 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004547 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004548 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004549 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004550" 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 +00004551" call Dret("s:NetrwListSettings")
4552endfun
4553
4554" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004555" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004556" islocal=0: remote browsing
4557" =1: local browsing
4558fun! s:NetrwListStyle(islocal)
4559" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004560
Bram Moolenaar97d62492012-11-15 21:28:22 +01004561 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004562 let fname = s:NetrwGetWord()
4563 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004564 let svpos = winsaveview()
4565" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004566 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004567" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4568" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4569" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004570
Bram Moolenaar85850f32019-07-19 22:05:51 +02004571 " repoint t:netrw_lexbufnr if appropriate
4572 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4573" call Decho("set repointlexbufnr to true!")
4574 let repointlexbufnr= 1
4575 endif
4576
Bram Moolenaar446cb832008-06-24 21:56:24 +00004577 if w:netrw_liststyle == s:THINLIST
4578 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004579" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004580 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4581
4582 elseif w:netrw_liststyle == s:LONGLIST
4583 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004584" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004585 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4586
4587 elseif w:netrw_liststyle == s:WIDELIST
4588 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004589" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004590 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4591
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004592 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004593" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004594 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4595
4596 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004597 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004598 let g:netrw_liststyle = s:THINLIST
4599 let w:netrw_liststyle = g:netrw_liststyle
4600 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4601 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004602 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004603" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004604
4605 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004606" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4607 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004608 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004609" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004610 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004611" 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 +00004612
4613 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004614" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004615 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004616 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004617
Bram Moolenaar85850f32019-07-19 22:05:51 +02004618 " repoint t:netrw_lexbufnr if appropriate
4619 if exists("repointlexbufnr")
4620 let t:netrw_lexbufnr= bufnr("%")
4621" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4622 endif
4623
Bram Moolenaar13600302014-05-22 18:26:40 +02004624 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004625" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4626 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004627 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004628
4629" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4630endfun
4631
4632" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004633" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4634fun! s:NetrwBannerCtrl(islocal)
4635" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4636
Bram Moolenaar97d62492012-11-15 21:28:22 +01004637 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004638 " toggle the banner (enable/suppress)
4639 let g:netrw_banner= !g:netrw_banner
4640
4641 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004642 let svpos= winsaveview()
4643" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004644 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4645
4646 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004647 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4648 let fname= s:NetrwGetWord()
4649 sil NetrwKeepj $
4650 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4651" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4652 if result <= 0 && exists("w:netrw_bannercnt")
4653 exe "NetrwKeepj ".w:netrw_bannercnt
4654 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004655 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004656 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004657" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4658endfun
4659
4660" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004661" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4662"
4663" No bang: enters files/directories into Netrw's bookmark system
4664" No argument and in netrw buffer:
4665" if there are marked files: bookmark marked files
4666" otherwise : bookmark file/directory under cursor
4667" No argument and not in netrw buffer: bookmarks current open file
4668" Has arguments: globs them individually and bookmarks them
4669"
4670" With bang: deletes files/directories from Netrw's bookmark system
4671fun! s:NetrwBookmark(del,...)
4672" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4673 if a:0 == 0
4674 if &ft == "netrw"
4675 let curbufnr = bufnr("%")
4676
4677 if exists("s:netrwmarkfilelist_{curbufnr}")
4678 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004679" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004680 let svpos = winsaveview()
4681" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004682 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004683 for fname in s:netrwmarkfilelist_{curbufnr}
4684 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4685 endfor
4686 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4687 call s:NetrwUnmarkList(curbufnr,curdir)
4688 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004689" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4690 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004691 else
4692 let fname= s:NetrwGetWord()
4693 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4694 endif
4695
4696 else
4697 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004698" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004699 let fname= expand("%")
4700 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4701 endif
4702
4703 else
4704 " bookmark specified files
4705 " attempts to infer if working remote or local
4706 " by deciding if the current file begins with an url
4707 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004708 let islocal= expand("%") !~ '^\a\{3,}://'
4709" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004710 let i = 1
4711 while i <= a:0
4712 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004713 if v:version > 704 || (v:version == 704 && has("patch656"))
4714 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004715 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004716 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004717 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004718 else
4719 let mbfiles= [a:{i}]
4720 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004721" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004722 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004723" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004724 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4725 endfor
4726 let i= i + 1
4727 endwhile
4728 endif
4729
4730 " update the menu
4731 call s:NetrwBookmarkMenu()
4732
4733" call Dret("s:NetrwBookmark")
4734endfun
4735
4736" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004737" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4738" .2.[cnt] for bookmarks, and
4739" .3.[cnt] for history
4740" (see s:NetrwMenu())
4741fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004742 if !exists("s:netrw_menucnt")
4743 return
4744 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004745" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004746
4747 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004748 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004749 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004750" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004751 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4752 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004753 endif
4754 if !exists("s:netrw_initbookhist")
4755 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004756 endif
4757
4758 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004759 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004760 let cnt= 1
4761 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004762" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004763 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004764
4765 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004766 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004767
4768 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004769 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 +01004770 let cnt= cnt + 1
4771 endfor
4772
4773 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004774
4775 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004776 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004777 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004778 let first = 1
4779 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004780 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004781 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004782 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004783 if exists("g:netrw_dirhist_{cnt}")
4784 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004785" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004786 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4787 endif
4788 let first = 0
4789 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4790 if cnt < 0
4791 let cnt= cnt + g:netrw_dirhistmax
4792 endif
4793 endwhile
4794 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004795
Bram Moolenaar9964e462007-05-05 17:54:07 +00004796 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004797" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004798endfun
4799
4800" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004801" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4802" directory and a new directory name. Also, if the
4803" "new directory name" is actually a file,
4804" NetrwBrowseChgDir() edits the file.
4805fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004806" 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 +01004807" 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 +00004808
Bram Moolenaar97d62492012-11-15 21:28:22 +01004809 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004810 if !exists("b:netrw_curdir")
4811 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4812 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004813 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004814" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4815" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004816" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004817" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004818 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004819 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004820" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004821
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004822 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004823" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004824 call s:SavePosn(s:netrw_posn)
4825 NetrwKeepj call s:NetrwOptionsSave("s:")
4826 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004827 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004828 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004829 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004830 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004831 endif
4832 let newdir = a:newdir
4833 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004834 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004835" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004836" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004837" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004838
4839 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004840" 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 +01004841 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004842" 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 +01004843 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004844 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004845" 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 +01004846 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004847" 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 +02004848 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004849 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004850 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004851 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004852" 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 +01004853 endif
4854 endif
4855" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004856" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004857 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004858
Bram Moolenaar446cb832008-06-24 21:56:24 +00004859 " set up o/s-dependent directory recognition pattern
4860 if has("amiga")
4861 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004862 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004863 let dirpat= '[\/]$'
4864 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004865" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004866
4867 if dirname !~ dirpat
4868 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004869 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004871" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004872 endif
4873
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004874" 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 +01004875 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004876 " ------------------------------
4877 " NetrwBrowseChgDir: edit a file {{{3
4878 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004879" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004880
Bram Moolenaar97d62492012-11-15 21:28:22 +01004881 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004882 let s:rexposn_{bufnr("%")}= winsaveview()
4883" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004884" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4885" 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 +01004886
Bram Moolenaar446cb832008-06-24 21:56:24 +00004887 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004888" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4889" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004890" let newdir = s:NetrwTreePath(s:netrw_treetop)
4891" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004892 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004893 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4894" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4895 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004896 if dirname =~ '/$'
4897 let dirname= dirname.newdir
4898 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004899 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004900 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004901" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4902" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004904" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004905 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004906 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004907 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004908 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004909" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004910 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004911 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004912" 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 +02004913 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004914 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004915 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004916" " 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 +01004917 if type(g:netrw_browse_split) == 3
4918 " open file in server
4919 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004920" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004921 call s:NetrwServerEdit(a:islocal,dirname)
4922" call Dret("s:NetrwBrowseChgDir")
4923 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004924
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004925 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004926 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004927" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004928 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4929 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004930 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004931 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004932 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004933 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004934
Bram Moolenaar446cb832008-06-24 21:56:24 +00004935 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004936 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004937" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004938 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4939 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004940 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004941 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004942 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004943 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004944
Bram Moolenaar446cb832008-06-24 21:56:24 +00004945 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004946 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004947" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004948 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004949 if !exists("b:netrw_curdir")
4950 let b:netrw_curdir= getcwd()
4951 endif
4952 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004953
Bram Moolenaar446cb832008-06-24 21:56:24 +00004954 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004955 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004956" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004957 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004958 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004959" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004960 return
4961 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004962 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004963
Bram Moolenaar9964e462007-05-05 17:54:07 +00004964 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004965 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004966" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004967 call s:NetrwMenu(0)
4968 " optional change to window
4969 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004970" 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 +02004971 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004972 " if g:netrw_chgwin is set to one more than the last window, then
4973 " vertically split the last window to make that window available.
4974 let curwin= winnr()
4975 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4976 vs
4977 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004978 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004979 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004980 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004981 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004982 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004983
Bram Moolenaar9964e462007-05-05 17:54:07 +00004984 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004985
Bram Moolenaar446cb832008-06-24 21:56:24 +00004986 " the point where netrw actually edits the (local) file
4987 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004988 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004989 if !&mod
4990 " if e the new file would fail due to &mod, then don't change any of the flags
4991 let dolockout= 1
4992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004993 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004994" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004995 " some like c-^ to return to the last edited file
4996 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004997 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4998 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004999 call s:NetrwEditFile("e","",dirname)
5000" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005001 " COMBAK -- cuc cul related
5002 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005003 if &hidden || &bufhidden == "hide"
5004 " file came from vim's hidden storage. Don't "restore" options with it.
5005 let dorestore= 0
5006 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005007 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005008" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005009 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005010
5011 " handle g:Netrw_funcref -- call external-to-netrw functions
5012 " This code will handle g:Netrw_funcref as an individual function reference
5013 " or as a list of function references. It will ignore anything that's not
5014 " a function reference. See :help Funcref for information about function references.
5015 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005016" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005017 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005018" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005019 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005020 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005021" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005022 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005023 if type(Fncref) == 2
5024 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005025 endif
5026 endfor
5027 endif
5028 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005029 endif
5030
5031 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005032 " ----------------------------------------------------
5033 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5034 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005035" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005036 let dirname = newdir
5037 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005038 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005039 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005040
5041 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005042 " ---------------------------------------------
5043 " NetrwBrowseChgDir: refresh the directory list {{{3
5044 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005045" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005046 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005047 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005048
5049 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005050 " --------------------------------------
5051 " NetrwBrowseChgDir: go up one directory {{{3
5052 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005053" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005054
5055 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5056 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005057" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5058" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005059 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005060 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005061 endif
5062
5063 if has("amiga")
5064 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005065" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005066 if a:islocal
5067 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5068 let dirname= substitute(dirname,'/$','','')
5069 else
5070 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5071 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005072" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005073
Nir Lichtman1e34b952024-05-08 19:19:34 +02005074 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005075 " windows
5076 if a:islocal
5077 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5078 if dirname == ""
5079 let dirname= '/'
5080 endif
5081 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005082 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005083 endif
5084 if dirname =~ '^\a:$'
5085 let dirname= dirname.'/'
5086 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005087" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005088
Bram Moolenaar446cb832008-06-24 21:56:24 +00005089 else
5090 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005091" 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 +00005092 if a:islocal
5093 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5094 if dirname == ""
5095 let dirname= '/'
5096 endif
5097 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005098 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005099 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005100" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005101 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005102 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005103 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005104
5105 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005106 " --------------------------------------
5107 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5108 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005109" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005110 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5111" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005112 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005113 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005114" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5115 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005116 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005117 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005118" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005119 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005120 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005121" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005122
5123 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005124" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005125 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005126" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005127 let haskey= 1
5128 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005129" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005130 endif
5131
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005132 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005133" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005134 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005135 if has_key(w:netrw_treedict,treedir."/")
5136 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005137" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005138 let haskey = 1
5139 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005140" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005141 endif
5142 endif
5143
5144 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005145" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005146 if !haskey && treedir =~ '/$'
5147 let treedir= substitute(treedir,'/$','','')
5148 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005149" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005150 let haskey = 1
5151 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005152" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005153 endif
5154 endif
5155
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005156" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005157 if haskey
5158 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005159" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005161" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5162" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005163 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 else
5165 " go down one directory
5166 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005167" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5168" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005169 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005170 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005171" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005172 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005173
5174 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005175 " ----------------------------------------
5176 " NetrwBrowseChgDir: Go down one directory {{{3
5177 " ----------------------------------------
5178 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005179" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005180 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005181 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005182 endif
5183
Bram Moolenaar97d62492012-11-15 21:28:22 +01005184 " --------------------------------------
5185 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5186 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005187 if dorestore
5188 " dorestore is zero'd when a local file was hidden or bufhidden;
5189 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005190" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005191 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005192" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005193" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005194 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005195 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005196" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005197 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005198" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5199" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005200 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005201" 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 +02005202 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005203" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5204" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005205 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005206" 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 +02005207 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005208 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005209 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005210 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005211
Bram Moolenaar446cb832008-06-24 21:56:24 +00005212" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5213 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005214endfun
5215
5216" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005217" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5218" for thin, long, and wide: cursor placed just after banner
5219" for tree, keeps cursor on current filename
5220fun! s:NetrwBrowseUpDir(islocal)
5221" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005222 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5223 " this test needed because occasionally this function seems to be incorrectly called
5224 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005225 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005226 " directories.
5227" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5228 return
5229 endif
5230
Bram Moolenaara6878372014-03-22 21:02:50 +01005231 norm! 0
5232 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005233" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005234 let curline= getline(".")
5235 let swwline= winline() - 1
5236 if exists("w:netrw_treetop")
5237 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005238 elseif exists("b:netrw_curdir")
5239 let w:netrw_treetop= b:netrw_curdir
5240 else
5241 let w:netrw_treetop= getcwd()
5242 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005243 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005244 let curfile = getline(".")
5245 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005246 if a:islocal
5247 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5248 else
5249 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5250 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005251" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5252" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5253 if w:netrw_treetop == '/'
5254 keepj call search('^\M'.curfile,"w")
5255 elseif curfile == '../'
5256 keepj call search('^\M'.curfile,"wb")
5257 else
5258" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5259 while 1
5260 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5261 let treepath= s:NetrwTreePath(w:netrw_treetop)
5262" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5263 if treepath == curpath
5264 break
5265 endif
5266 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005267 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005268
Bram Moolenaara6878372014-03-22 21:02:50 +01005269 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005270" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005271 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005272 if exists("b:netrw_curdir")
5273 let curdir= b:netrw_curdir
5274 else
5275 let curdir= expand(getcwd())
5276 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005277 if a:islocal
5278 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5279 else
5280 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5281 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005282 call s:RestorePosn(s:netrw_posn)
5283 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005284 let curdir= '\<'. escape(curdir, '~'). '/'
5285 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005286 endif
5287" call Dret("s:NetrwBrowseUpDir")
5288endfun
5289
5290" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005291" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005292" given filename; typically this means given their extension.
5293" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005294fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005295 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005296" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005297
Bram Moolenaar91359012019-11-30 17:57:03 +01005298 if a:remote == 0 && isdirectory(a:fname)
5299 " if its really just a local directory, then do a "gf" instead
5300" 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 +01005301" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5302 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005303" call Dret("netrw#BrowseX")
5304 return
5305 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5306 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5307" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5308" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5309" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5310" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5311 norm! gf
5312" call Dret("netrw#BrowseX")
5313 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005314 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005315" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005316
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005317 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5318 let remote = a:remote
5319 else
5320 let remote = 0
5321 endif
5322
Bram Moolenaar97d62492012-11-15 21:28:22 +01005323 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005324 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005325" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005326
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005327 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5328 let awkeep = &aw
5329 set noaw
5330
Bram Moolenaar5c736222010-01-06 20:54:52 +01005331 " special core dump handler
5332 if a:fname =~ '/core\(\.\d\+\)\=$'
5333 if exists("g:Netrw_corehandler")
5334 if type(g:Netrw_corehandler) == 2
5335 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005336" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005337 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005338 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005339 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005340" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005341 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005342 if type(Fncref) == 2
5343 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005344 endif
5345 endfor
5346 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005347" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005348 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005349 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005350 let &aw= awkeep
5351" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005352 return
5353 endif
5354 endif
5355
Bram Moolenaar446cb832008-06-24 21:56:24 +00005356 " set up the filename
5357 " (lower case the extension, make a local copy of a remote file)
5358 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005359 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005360 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005361 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005362 if exten =~ "[\\/]"
5363 let exten= ""
5364 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005365" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005366
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005367 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005368 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005369" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005370 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005371 call netrw#NetRead(3,a:fname)
5372 " attempt to rename tempfile
5373 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005374 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005375" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5376" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005377 if s:netrw_tmpfile != newname && newname != ""
5378 if rename(s:netrw_tmpfile,newname) == 0
5379 " renaming succeeded
5380" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5381 let fname= newname
5382 else
5383 " renaming failed
5384" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5385 let fname= s:netrw_tmpfile
5386 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005387 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005388 let fname= s:netrw_tmpfile
5389 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005390 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005391" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005392 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005393 " special ~ handler for local
5394 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005395" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5396 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005397 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005398 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005399" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5400" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005401
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005402 " set up redirection (avoids browser messages)
5403 " by default, g:netrw_suppress_gx_mesg is true
5404 if g:netrw_suppress_gx_mesg
5405 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005406 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005407 let redir= substitute(&srr,"%s","nul","")
5408 else
5409 let redir= substitute(&srr,"%s","/dev/null","")
5410 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005411 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005412 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005413 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005414 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005415 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005416 else
5417 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005418 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005419" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005420
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005421 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005422 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005423" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005424 if g:netrw_browsex_viewer =~ '\s'
5425 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5426 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5427 let oviewer = ''
5428 let cnt = 1
5429 while !executable(viewer) && viewer != oviewer
5430 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5431 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5432 let cnt = cnt + 1
5433 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005434" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005435 endwhile
5436 else
5437 let viewer = g:netrw_browsex_viewer
5438 let viewopt = ""
5439 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005440" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005441 endif
5442
5443 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005444" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005445 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005446" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005447 let ret= netrwFileHandlers#Invoke(exten,fname)
5448
5449 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005450" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005451 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005452 let ret= v:shell_error
5453
Nir Lichtman1e34b952024-05-08 19:19:34 +02005454 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005455" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005456 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005457 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005458 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005459 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005460 else
5461 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5462 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005463 let ret= v:shell_error
5464
Bram Moolenaar97d62492012-11-15 21:28:22 +01005465 elseif has("win32unix")
5466 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005467" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005468 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005469" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005470 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005471 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005472" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005473 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005474 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005475" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005476 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005477 else
5478 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5479 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005480 let ret= v:shell_error
5481
Bram Moolenaar85850f32019-07-19 22:05:51 +02005482 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005483" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5484 if a:fname =~ '^https\=://'
5485 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5486 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005487" call Decho("fname<".fname.">")
5488" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005489 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5490
5491 else
5492 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5493 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005494 let ret= v:shell_error
5495
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005496 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5497" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5498 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5499 let ret= v:shell_error
5500
5501 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5502" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5503 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5504 let ret= v:shell_error
5505
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005506 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005507" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005508 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005509 let ret= v:shell_error
5510
5511 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005512" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005513 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005514 let ret= v:shell_error
5515
5516 else
5517 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005518" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005519 let ret= netrwFileHandlers#Invoke(exten,fname)
5520 endif
5521
5522 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5523 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005524" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005525 let ret= netrwFileHandlers#Invoke(exten,fname)
5526 endif
5527
Bram Moolenaarc236c162008-07-13 17:41:49 +00005528 " restoring redraw! after external file handlers
5529 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005530
5531 " cleanup: remove temporary file,
5532 " delete current buffer if success with handler,
5533 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005534 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005535 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005536" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005537"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005538" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005539" endif
5540
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005541 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005542 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005543 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005544 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005545 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005546 if use_ctrlo
5547 exe "sil! NetrwKeepj norm! \<c-o>"
5548 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005549 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005550" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005551 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005552 let @@ = ykeep
5553 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005554
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005555" call Dret("netrw#BrowseX")
5556endfun
5557
5558" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005559" netrw#GX: gets word under cursor for gx support {{{2
5560" See also: netrw#BrowseXVis
5561" netrw#BrowseX
5562fun! netrw#GX()
5563" call Dfunc("netrw#GX()")
5564 if &ft == "netrw"
5565 let fname= s:NetrwGetWord()
5566 else
5567 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5568 endif
5569" call Dret("netrw#GX <".fname.">")
5570 return fname
5571endfun
5572
5573" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005574" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5575fun! netrw#BrowseXVis()
5576" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005577 let akeep = @a
5578 norm! gv"ay
5579 let gxfile= @a
5580 let @a = akeep
5581 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005582" call Dret("netrw#BrowseXVis")
5583endfun
5584
5585" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005586" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5587" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5588" to become an unlisted buffer, so in that case don't bwipe it.
5589fun! s:NetrwBufRename(newname)
5590" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5591" call Dredir("ls!","s:NetrwBufRename (before rename)")
5592 let oldbufname= bufname(bufnr("%"))
5593" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5594
5595 if oldbufname != a:newname
5596" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5597 let b:junk= 1
5598" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5599 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005600" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005601 let oldbufnr= bufnr(oldbufname)
5602" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5603" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5604 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5605" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5606 exe "bwipe! ".oldbufnr
5607" else " Decho
5608" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005609" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5610" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5611" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005612 endif
5613" call Dredir("ls!","s:NetrwBufRename (after rename)")
5614" else " Decho
5615" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5616 endif
5617
5618" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5619endfun
5620
5621" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005622" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005623fun! netrw#CheckIfRemote(...)
5624" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5625 if a:0 > 0
5626 let curfile= a:1
5627 else
5628 let curfile= expand("%")
5629 endif
5630" call Decho("curfile<".curfile.">")
5631 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005632" call Dret("netrw#CheckIfRemote 1")
5633 return 1
5634 else
5635" call Dret("netrw#CheckIfRemote 0")
5636 return 0
5637 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005638endfun
5639
5640" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005641" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5642fun! s:NetrwChgPerm(islocal,curdir)
5643" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005644 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005645 call inputsave()
5646 let newperm= input("Enter new permission: ")
5647 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005648 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5649 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5650" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005651 call system(chgperm)
5652 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005653 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005654 endif
5655 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005656 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005657 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005658 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005659" call Dret("s:NetrwChgPerm")
5660endfun
5661
5662" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005663" s:CheckIfKde: checks if kdeinit is running {{{2
5664" Returns 0: kdeinit not running
5665" 1: kdeinit is running
5666fun! s:CheckIfKde()
5667" call Dfunc("s:CheckIfKde()")
5668 " seems kde systems often have gnome-open due to dependencies, even though
5669 " gnome-open's subsidiary display tools are largely absent. Kde systems
5670 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5671 if !exists("s:haskdeinit")
5672 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005673 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005674 if v:shell_error
5675 let s:haskdeinit = 0
5676 endif
5677 else
5678 let s:haskdeinit= 0
5679 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005680" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005681 endif
5682
5683" call Dret("s:CheckIfKde ".s:haskdeinit)
5684 return s:haskdeinit
5685endfun
5686
5687" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005688" s:NetrwClearExplore: clear explore variables (if any) {{{2
5689fun! s:NetrwClearExplore()
5690" call Dfunc("s:NetrwClearExplore()")
5691 2match none
5692 if exists("s:explore_match") |unlet s:explore_match |endif
5693 if exists("s:explore_indx") |unlet s:explore_indx |endif
5694 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5695 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5696 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5697 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5698 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5699 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5700 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5701" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005702" call Dret("s:NetrwClearExplore")
5703endfun
5704
5705" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005706" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5707fun! s:NetrwEditBuf(bufnum)
5708" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5709 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5710" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5711 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5712 else
5713" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005714 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005715 endif
5716" call Dret("s:NetrwEditBuf")
5717endfun
5718
5719" ---------------------------------------------------------------------
5720" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5721" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5722fun! s:NetrwEditFile(cmd,opt,fname)
5723" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5724 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5725" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5726 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5727 else
5728" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005729 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5730 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5731 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005732 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5733 endif
5734" call Dret("s:NetrwEditFile")
5735endfun
5736
5737" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005738" s:NetrwExploreListUniq: {{{2
5739fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005740" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005741
5742 " this assumes that the list is already sorted
5743 let newexplist= []
5744 for member in a:explist
5745 if !exists("uniqmember") || member != uniqmember
5746 let uniqmember = member
5747 let newexplist = newexplist + [ member ]
5748 endif
5749 endfor
5750
Bram Moolenaar15146672011-10-20 22:22:38 +02005751" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005752 return newexplist
5753endfun
5754
5755" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005756" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5757fun! s:NetrwForceChgDir(islocal,newdir)
5758" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005759 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005760 if a:newdir !~ '/$'
5761 " ok, looks like force is needed to get directory-style treatment
5762 if a:newdir =~ '@$'
5763 let newdir= substitute(a:newdir,'@$','/','')
5764 elseif a:newdir =~ '[*=|\\]$'
5765 let newdir= substitute(a:newdir,'.$','/','')
5766 else
5767 let newdir= a:newdir.'/'
5768 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005769" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005770 else
5771 " should already be getting treatment as a directory
5772 let newdir= a:newdir
5773 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005774 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005775 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005776 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005777" call Dret("s:NetrwForceChgDir")
5778endfun
5779
5780" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005781" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005782" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5783" expr : this is the expression to follow the directory. Will use s:ComposePath()
5784" pare =1: remove the current directory from the resulting glob() filelist
5785" =0: leave the current directory in the resulting glob() filelist
5786fun! s:NetrwGlob(direntry,expr,pare)
5787" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005788 if netrw#CheckIfRemote()
5789 keepalt 1sp
5790 keepalt enew
5791 let keep_liststyle = w:netrw_liststyle
5792 let w:netrw_liststyle = s:THINLIST
5793 if s:NetrwRemoteListing() == 0
5794 keepj keepalt %s@/@@
5795 let filelist= getline(1,$)
5796 q!
5797 else
5798 " remote listing error -- leave treedict unchanged
5799 let filelist= w:netrw_treedict[a:direntry]
5800 endif
5801 let w:netrw_liststyle= keep_liststyle
5802 else
Christian Brabandt14879472024-06-13 21:25:35 +02005803 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
5804 if has("win64")
5805 " escape [ so it is not detected as wildcard character, see :h wildcard
5806 let path= substitute(path, '[', '[[]', 'g')
5807 endif
5808 if v:version > 704 || (v:version == 704 && has("patch656"))
5809 let filelist= glob(path,0,1,1)
5810 else
5811 let filelist= glob(path,0,1)
5812 endif
5813 if a:pare
5814 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5815 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005816 endif
5817" call Dret("s:NetrwGlob ".string(filelist))
5818 return filelist
5819endfun
5820
5821" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005822" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5823fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005824" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005825 if a:newfile =~ '[/@*=|\\]$'
5826 let newfile= substitute(a:newfile,'.$','','')
5827 else
5828 let newfile= a:newfile
5829 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005830 if a:islocal
5831 call s:NetrwBrowseChgDir(a:islocal,newfile)
5832 else
5833 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5834 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005835" call Dret("s:NetrwForceFile")
5836endfun
5837
5838" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005839" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5840" and switches the hiding mode. The actual hiding is done by
5841" s:NetrwListHide().
5842" g:netrw_hide= 0: show all
5843" 1: show not-hidden files
5844" 2: show hidden files only
5845fun! s:NetrwHide(islocal)
5846" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005847 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005848 let svpos= winsaveview()
5849" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005850
5851 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005852" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5853" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005854
5855 " hide the files in the markfile list
5856 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005857" 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 +00005858 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5859 " remove fname from hiding list
5860 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5861 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5862 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005863" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864 else
5865 " append fname to hiding list
5866 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5867 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5868 else
5869 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5870 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005871" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005872 endif
5873 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005874 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005875 let g:netrw_hide= 1
5876
5877 else
5878
5879 " switch between show-all/show-not-hidden/show-hidden
5880 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005881 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005882 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005883 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005884 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005885" call Dret("NetrwHide")
5886 return
5887 endif
5888 endif
5889
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005890 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005891" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5892 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005893 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005894" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005895endfun
5896
5897" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005898" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5899fun! s:NetrwHideEdit(islocal)
5900" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5901
5902 let ykeep= @@
5903 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005904 let svpos= winsaveview()
5905" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005906
5907 " get new hiding list from user
5908 call inputsave()
5909 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5910 call inputrestore()
5911 let g:netrw_list_hide= newhide
5912" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5913
5914 " refresh the listing
5915 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5916
5917 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005918" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5919 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005920 let @@= ykeep
5921
5922" call Dret("NetrwHideEdit")
5923endfun
5924
5925" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005926" s:NetrwHidden: invoked by "gh" {{{2
5927fun! s:NetrwHidden(islocal)
5928" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005929 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005930 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005931 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005932" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005933
5934 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005935 " remove .file pattern from hiding list
5936" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005937 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005938 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005939" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005940 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5941 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005942" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005943 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5944 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005945 if g:netrw_list_hide =~ '^,'
5946 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5947 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005948
5949 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005950 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005951" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5952 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005953 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005954" call Dret("s:NetrwHidden")
5955endfun
5956
5957" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005958" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5959fun! s:NetrwHome()
5960 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005961 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005962 else
5963 " go to vim plugin home
5964 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005965 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005966 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005967 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005968 let home= basehome."/.vim"
5969 break
5970 endif
5971 endfor
5972 if home == ""
5973 " just pick the first directory
5974 let home= substitute(&rtp,',.*$','','')
5975 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005976 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005977 let home= substitute(home,'/','\\','g')
5978 endif
5979 endif
5980 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005981 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005982" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005983 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005984" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005985 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005986 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005987" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005988 call mkdir(home)
5989 endif
5990 endif
5991 let g:netrw_home= home
5992 return home
5993endfun
5994
5995" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005996" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5997fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005998 if exists("s:netrwdrag")
5999 return
6000 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006001 if &ft != "netrw"
6002 return
6003 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006004" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006005
Bram Moolenaar97d62492012-11-15 21:28:22 +01006006 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006007 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006008 while getchar(0) != 0
6009 "clear the input stream
6010 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006011 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006012 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006013 let mouse_lnum = v:mouse_lnum
6014 let wlastline = line('w$')
6015 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006016" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6017" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006018 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6019 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006020 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006021" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6022 return
6023 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006024 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006025 " 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 +01006026 " without this test when its disabled.
6027 " 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 +01006028" 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 +01006029 if v:mouse_col > virtcol('.')
6030 let @@= ykeep
6031" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6032 return
6033 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006034
Bram Moolenaar446cb832008-06-24 21:56:24 +00006035 if a:islocal
6036 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006037 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006038 endif
6039 else
6040 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006041 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006042 endif
6043 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006044 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006045" call Dret("s:NetrwLeftmouse")
6046endfun
6047
6048" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006049" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6050fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006051 if &ft != "netrw"
6052 return
6053 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006054" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6055 call s:NetrwMarkFileTgt(a:islocal)
6056" call Dret("s:NetrwCLeftmouse")
6057endfun
6058
6059" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006060" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6061" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006062" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006063" a:islocal=2 : <c-r> used, remote
6064" a:islocal=3 : <c-r> used, local
6065fun! s:NetrwServerEdit(islocal,fname)
6066" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6067 let islocal = a:islocal%2 " =0: remote =1: local
6068 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006069" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006070
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006071 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006072 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006073 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006074" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006075 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006076 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006077 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6078 unlet s:netrw_browse_split_{winnr()}
6079 endif
6080 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6081" call Dret("s:NetrwServerEdit")
6082 return
6083 endif
6084
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006085" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006086 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006087" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006088
6089 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006090" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006091 let srvrname = g:netrw_browse_split[0]
6092 let tabnum = g:netrw_browse_split[1]
6093 let winnum = g:netrw_browse_split[2]
6094
6095 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006096" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006097
6098 if !ctrlr
6099 " user must have closed the server window and the user did not use <c-r>, but
6100 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006101" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006102 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006103 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006104 endif
6105 let g:netrw_browse_split= 0
6106 if exists("s:netrw_browse_split_".winnr())
6107 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6108 endif
6109 call s:NetrwBrowseChgDir(islocal,a:fname)
6110" call Dret("s:NetrwServerEdit")
6111 return
6112
6113 elseif has("win32") && executable("start")
6114 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006115" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006116 call system("start gvim --servername ".srvrname)
6117
6118 else
6119 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006120" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006121 call system("gvim --servername ".srvrname)
6122 endif
6123 endif
6124
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006125" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006126 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6127 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006128 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006129
6130 else
6131
6132 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6133
6134 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006135" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006136 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006137 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006138 endif
6139 let g:netrw_browse_split= 0
6140 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6141" call Dret("s:NetrwServerEdit")
6142 return
6143
6144 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006145" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006146 if has("win32") && executable("start")
6147 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006148" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006149 call system("start gvim --servername ".g:netrw_servername)
6150 else
6151 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006152" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006153 call system("gvim --servername ".g:netrw_servername)
6154 endif
6155 endif
6156 endif
6157
6158 while 1
6159 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006160" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6161 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006162 break
6163 catch /^Vim\%((\a\+)\)\=:E241/
6164 sleep 200m
6165 endtry
6166 endwhile
6167
6168 if exists("g:netrw_browse_split")
6169 if type(g:netrw_browse_split) != 3
6170 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6171 endif
6172 unlet g:netrw_browse_split
6173 endif
6174 let g:netrw_browse_split= [g:netrw_servername,1,1]
6175 endif
6176
6177 else
6178 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6179 endif
6180
6181" call Dret("s:NetrwServerEdit")
6182endfun
6183
6184" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006185" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6186fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006187 if &ft != "netrw"
6188 return
6189 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006190" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006191
Bram Moolenaar8d043172014-01-23 14:24:41 +01006192 let s:ngw= s:NetrwGetWord()
6193 call s:NetrwMarkFile(a:islocal,s:ngw)
6194
6195" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006196endfun
6197
6198" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006199" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6200" Used to mark multiple files.
6201fun! s:NetrwSLeftdrag(islocal)
6202" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6203 if !exists("s:netrwdrag")
6204 let s:netrwdrag = winnr()
6205 if a:islocal
6206 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006207 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006208 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006209 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006210 endif
6211 let ngw = s:NetrwGetWord()
6212 if !exists("s:ngw") || s:ngw != ngw
6213 call s:NetrwMarkFile(a:islocal,ngw)
6214 endif
6215 let s:ngw= ngw
6216" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6217endfun
6218
6219" ---------------------------------------------------------------------
6220" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6221fun! s:NetrwSLeftrelease(islocal)
6222" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6223 if exists("s:netrwdrag")
6224 nunmap <s-leftrelease>
6225 let ngw = s:NetrwGetWord()
6226 if !exists("s:ngw") || s:ngw != ngw
6227 call s:NetrwMarkFile(a:islocal,ngw)
6228 endif
6229 if exists("s:ngw")
6230 unlet s:ngw
6231 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006232 unlet s:netrwdrag
6233 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006234" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006235endfun
6236
6237" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006238" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6239" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006240fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006241" 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 +02006242" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006243 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006244
6245 " 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 +02006246 " How-it-works: take the hiding command, convert it into a range.
6247 " Duplicate characters don't matter.
6248 " Remove all such characters from the '/~@#...890' string.
6249 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006250" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006251 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006252 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006253" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006254
6255 while listhide != ""
6256 if listhide =~ ','
6257 let hide = substitute(listhide,',.*$','','e')
6258 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6259 else
6260 let hide = listhide
6261 let listhide = ""
6262 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006263" 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 +01006264 if g:netrw_sort_by =~ '^[ts]'
6265 if hide =~ '^\^'
6266" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6267 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6268 elseif hide =~ '^\\(\^'
6269 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6270 endif
6271" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6272 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006273
6274 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006275" 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 +00006276 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006277" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006278 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006279 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006280" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006281 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006282 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006283" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006284 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006285
Bram Moolenaar446cb832008-06-24 21:56:24 +00006286 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006287 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006288" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006289 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006290" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006291 endif
6292
Bram Moolenaaradc21822011-04-01 18:03:16 +02006293 " remove any blank lines that have somehow remained.
6294 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006295 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006296
Bram Moolenaar97d62492012-11-15 21:28:22 +01006297 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006298" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006299endfun
6300
6301" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006302" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006303" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006304fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006305" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306
Bram Moolenaar97d62492012-11-15 21:28:22 +01006307 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006308 " get name of new directory from user. A bare <CR> will skip.
6309 " if its currently a directory, also request will be skipped, but with
6310 " a message.
6311 call inputsave()
6312 let newdirname= input("Please give directory name: ")
6313 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006314" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006315
6316 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006317 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006318" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006319 return
6320 endif
6321
6322 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006323" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006324
6325 " Local mkdir:
6326 " sanity checks
6327 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006328" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6329 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006330 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006331 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006332 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006333 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006334" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335 return
6336 endif
6337 if s:FileReadable(fullnewdir)
6338 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006339 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006340 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006341 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006342" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006343 return
6344 endif
6345
6346 " requested new local directory is neither a pre-existing file or
6347 " directory, so make it!
6348 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006349 if has("unix")
6350 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6351 else
6352 call mkdir(fullnewdir,"p")
6353 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006354 else
6355 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006356 if s:NetrwLcd(b:netrw_curdir)
6357" call Dret("s:NetrwMakeDir : lcd failure")
6358 return
6359 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006360" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006361 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006362 if v:shell_error != 0
6363 let @@= ykeep
6364 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 +01006365" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006366 return
6367 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006368 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006369" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006370 if s:NetrwLcd(netrw_origdir)
6371" call Dret("s:NetrwBrowse : lcd failure")
6372 return
6373 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006374 endif
6375 endif
6376
6377 if v:shell_error == 0
6378 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006379" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006380 let svpos= winsaveview()
6381" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006382 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006383" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6384 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006385 elseif !exists("g:netrw_quiet")
6386 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6387 endif
6388" redraw!
6389
6390 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006391 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006392" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006393 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6394 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006395 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006396 if v:shell_error == 0
6397 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006398 let svpos= winsaveview()
6399" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006400 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006401" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6402 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006403 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006404 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006405 endif
6406" redraw!
6407
6408 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006409 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006410 let svpos= winsaveview()
6411" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006412" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006413 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006414" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006415 let remotepath= b:netrw_fname
6416 else
6417 let remotepath= ""
6418 endif
6419 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006420 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006421" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6422 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006423
Bram Moolenaar446cb832008-06-24 21:56:24 +00006424 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006425 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006426 let svpos= winsaveview()
6427" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006428" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006429 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006430" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006431 let remotepath= b:netrw_fname
6432 else
6433 let remotepath= ""
6434 endif
6435 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006436 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006437" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6438 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006439 endif
6440
Bram Moolenaar97d62492012-11-15 21:28:22 +01006441 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006442" call Dret("s:NetrwMakeDir")
6443endfun
6444
6445" ---------------------------------------------------------------------
6446" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6447fun! s:TreeSqueezeDir(islocal)
6448" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6449 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6450 " its a tree-listing style
6451 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006452 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006453 let depth = strchars(substitute(curdepth,' ','','g'))
6454 let srch = -1
6455" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6456" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006457" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006458" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6459 if depth >= 2
6460 NetrwKeepj norm! 0
6461 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6462 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6463" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6464" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6465 elseif depth == 1
6466 NetrwKeepj norm! 0
6467 let treedepthchr= substitute(s:treedepthstring,' ','','')
6468 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6469" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6470 endif
6471 if srch > 0
6472" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6473 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6474 exe srch
6475 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006476 endif
6477" call Dret("s:TreeSqueezeDir")
6478endfun
6479
6480" ---------------------------------------------------------------------
6481" s:NetrwMaps: {{{2
6482fun! s:NetrwMaps(islocal)
6483" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6484
Bram Moolenaar85850f32019-07-19 22:05:51 +02006485 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006486 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006487" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006488 if !hasmapto("<Plug>NetrwReturn")
6489 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006490" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006491 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6492 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006493" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006494 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6495 endif
6496 endif
6497 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006498" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006499 endif
6500
Bram Moolenaar85850f32019-07-19 22:05:51 +02006501 " generate default <Plug> maps {{{3
6502 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006503 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006504 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6505 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6506 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6507 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6508 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6509 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6510 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6511 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6512 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6513 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6514" ---------------------------------------------------------------------
6515" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6516" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6517" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6518" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6519" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6520" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6521" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6522" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6523" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6524" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6525" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6526" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6527" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6528" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6529" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6530" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6531" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6532" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6533" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6534" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6535" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6536" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6537" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6538" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6539" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6540" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6541" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6542" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6543" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6544" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6545" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6546" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6547" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6548" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6549" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6550" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6551" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6552" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6553" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6554" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6555" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6556" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6557" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6558" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6559" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6560" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6561" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6562
Bram Moolenaara6878372014-03-22 21:02:50 +01006563 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006564" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006565 " local normal-mode maps {{{3
6566 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6567 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6568 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6569 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6570 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6571 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6572 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6573 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6574 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6575 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6576 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6577" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006578 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6579 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6580 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006581 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006582 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006583 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6584 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6585 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6586 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006587 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6588 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6589 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6590 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6591 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6592 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6593 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6594 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6595 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6596 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6597 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6598 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6599 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006600 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006601 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006602 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6603 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6604 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6605 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6606 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006607 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006608 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006609 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6610 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006611 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6612 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6613 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006614 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006615 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006616 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6617 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006618 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006619 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006620 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6621 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6622 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006623 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6624 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006625
6626 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 +01006627 if !hasmapto('<Plug>NetrwHideEdit')
6628 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006629 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006630 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006631 if !hasmapto('<Plug>NetrwRefresh')
6632 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006633 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006634 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 +01006635 if s:didstarstar || !mapcheck("<s-down>","n")
6636 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006637 endif
6638 if s:didstarstar || !mapcheck("<s-up>","n")
6639 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006640 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006641 if !hasmapto('<Plug>NetrwTreeSqueeze')
6642 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006643 endif
6644 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006645 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6646 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006647 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6648 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6649 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6650 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6651 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6652 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6653 imap <buffer> <leftmouse> <Plug>ILeftmouse
6654 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006655 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6656 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6657 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6658 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6659 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006660 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006661 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6662 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006663 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006664 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6665 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6666 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6667 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6668 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6669 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6670 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006671 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6672
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006673 " support user-specified maps
6674 call netrw#UserMaps(1)
6675
Bram Moolenaar85850f32019-07-19 22:05:51 +02006676 else
6677 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006678" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006679 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006680 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6681 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6682 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6683 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6684 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6685 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6686 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6687 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6688 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6689 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6690 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6691" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006692 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6693 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6694 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6695 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6696 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6697 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6698 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6699 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006700 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006701 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006702 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6703 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6704 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6705 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6706 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6707 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6708 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6709 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6710 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6711 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6712 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006713 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006714 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006715 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6716 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6717 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6718 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6719 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006720 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6721 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6722 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6723 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006724 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006725 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6726 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006727 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006728 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 +01006729 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6730 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6731 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6732 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6733 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6734 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6735 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6736 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6737 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006738 if !hasmapto('<Plug>NetrwHideEdit')
6739 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006740 endif
6741 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6742 if !hasmapto('<Plug>NetrwRefresh')
6743 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006744 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006745 if !hasmapto('<Plug>NetrwTreeSqueeze')
6746 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006747 endif
6748 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006749
6750 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006751 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006752
6753 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6754 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006755 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006756 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006757 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006758 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006759 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006760 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006761 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006762 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006763 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006764 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006765 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6766 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6767 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006768 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006769 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006770 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6771 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006772 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006773 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6774 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6775 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6776 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6777 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6778 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6779 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006780 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006781
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006782 " support user-specified maps
6783 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006784 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006785
6786" call Dret("s:NetrwMaps")
6787endfun
6788
6789" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006790" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006791" If -buffer, the command is only available from within netrw buffers
6792" Otherwise, the command is available from any window, so long as netrw
6793" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006794fun! s:NetrwCommands(islocal)
6795" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6796
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006797 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6798 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006799 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 +01006800 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006801 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006802 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006803 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006804 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006805 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006806
6807" call Dret("s:NetrwCommands")
6808endfun
6809
6810" ---------------------------------------------------------------------
6811" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6812" glob()ing only works with local files
6813fun! s:NetrwMarkFiles(islocal,...)
6814" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006815 let curdir = s:NetrwGetCurdir(a:islocal)
6816 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006817 while i <= a:0
6818 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006819 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006820 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006821 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006822 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006823 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006824 else
6825 let mffiles= [a:{i}]
6826 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006827" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006828 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006829" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006830 call s:NetrwMarkFile(a:islocal,mffile)
6831 endfor
6832 let i= i + 1
6833 endwhile
6834" call Dret("s:NetrwMarkFiles")
6835endfun
6836
6837" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006838" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006839fun! s:NetrwMarkTarget(...)
6840" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6841 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006842 let curdir = s:NetrwGetCurdir(1)
6843 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006844 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6846 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006847 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006848" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006849 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006850 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6851 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006852 let svpos = winsaveview()
6853" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006854 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006855" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6856 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006857" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006858endfun
6859
6860" ---------------------------------------------------------------------
6861" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6862" mark and unmark files. If a markfile list exists,
6863" then the rename and delete functions will use it instead
6864" of whatever may happen to be under the cursor at that
6865" moment. When the mouse and gui are available,
6866" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006867"
6868" Creates two lists
6869" s:netrwmarkfilelist -- holds complete paths to all marked files
6870" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6871"
6872" Creates a marked file match string
6873" s:netrwmarfilemtch_# -- used with 2match to display marked files
6874"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006875" Creates a buffer version of islocal
6876" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006877fun! s:NetrwMarkFile(islocal,fname)
6878" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006879" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006880
6881 " sanity check
6882 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006883" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006884 return
6885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006886 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006887
Bram Moolenaar97d62492012-11-15 21:28:22 +01006888 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006889 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006890 if a:fname =~ '^\a'
6891 let leader= '\<'
6892 else
6893 let leader= ''
6894 endif
6895 if a:fname =~ '\a$'
6896 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6897 else
6898 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6899 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006900
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006901 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006902 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006903" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6904" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6905" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006906 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006907
6908 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006909 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006910" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006911 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006912 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006913
6914 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006915 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006916" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006917 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6918 if s:netrwmarkfilelist_{curbufnr} == []
6919 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006920" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 call s:NetrwUnmarkList(curbufnr,curdir)
6922 else
6923 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006924" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006925 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006926 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927 for fname in s:netrwmarkfilelist_{curbufnr}
6928 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006929 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006930 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006931 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006932 endif
6933 let first= 0
6934 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006935" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936 endif
6937 endif
6938
6939 else
6940 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006941" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006943" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006944 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006945 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6946" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006947
6948 " build initial markfile matching pattern
6949 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006950 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006951 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006952 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006953 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006954" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006955 endif
6956
6957 " handle global markfilelist
6958 if exists("s:netrwmarkfilelist")
6959 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6960 if index(s:netrwmarkfilelist,dname) == -1
6961 " append new filename to global markfilelist
6962 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006963" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006964 else
6965 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006966" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6967" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006968 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006969" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006970 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006971" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006972 unlet s:netrwmarkfilelist
6973 endif
6974 endif
6975 else
6976 " initialize new global-directory markfilelist
6977 let s:netrwmarkfilelist= []
6978 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006979" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006980 endif
6981
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006982 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006983 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6984 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6985" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6986 if exists("g:did_drchip_netrwlist_syntax")
6987 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6988 endif
6989 else
6990" " call Decho("2match none",'~'.expand("<slnum>"))
6991 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006993 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006994 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006995" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6996" 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 +00006997endfun
6998
6999" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007000" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7001" mA: move the argument list to marked file list (tomflist=1)
7002" Uses the global marked file list
7003fun! s:NetrwMarkFileArgList(islocal,tomflist)
7004" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7005
7006 let svpos = winsaveview()
7007" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7008 let curdir = s:NetrwGetCurdir(a:islocal)
7009 let curbufnr = bufnr("%")
7010
7011 if a:tomflist
7012 " mA: move argument list to marked file list
7013 while argc()
7014 let fname= argv(0)
7015" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7016 exe "argdel ".fnameescape(fname)
7017 call s:NetrwMarkFile(a:islocal,fname)
7018 endwhile
7019
7020 else
7021 " ma: move marked file list to argument list
7022 if exists("s:netrwmarkfilelist")
7023
7024 " for every filename in the marked list
7025 for fname in s:netrwmarkfilelist
7026" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7027 exe "argadd ".fnameescape(fname)
7028 endfor " for every file in the marked list
7029
7030 " unmark list and refresh
7031 call s:NetrwUnmarkList(curbufnr,curdir)
7032 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7033" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7034 NetrwKeepj call winrestview(svpos)
7035 endif
7036 endif
7037
7038" call Dret("s:NetrwMarkFileArgList")
7039endfun
7040
7041" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007042" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7043" compress/decompress files using the programs
7044" in g:netrw_compress and g:netrw_uncompress,
7045" using g:netrw_compress_suffix to know which to
7046" do. By default:
7047" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007048" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007049fun! s:NetrwMarkFileCompress(islocal)
7050" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007051 let svpos = winsaveview()
7052" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007053 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007054 let curbufnr = bufnr("%")
7055
Bram Moolenaarff034192013-04-24 18:51:19 +02007056 " sanity check
7057 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007058 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007059" call Dret("s:NetrwMarkFileCompress")
7060 return
7061 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007062" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007063
Bram Moolenaar446cb832008-06-24 21:56:24 +00007064 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007065
7066 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007067 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007068 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007069" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007070 if exists("g:netrw_decompress['".sfx."']")
7071 " fname has a suffix indicating that its compressed; apply associated decompression routine
7072 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007073" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007074 let exe= netrw#WinPath(exe)
7075 if a:islocal
7076 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007077 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007078 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007079 call system(exe." ".fname)
7080 if v:shell_error
7081 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007082 endif
7083 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007084 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7085 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007086 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007087
Bram Moolenaarff034192013-04-24 18:51:19 +02007088 endif
7089 unlet sfx
7090
Bram Moolenaar446cb832008-06-24 21:56:24 +00007091 if exists("exe")
7092 unlet exe
7093 elseif a:islocal
7094 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007095 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007096 if v:shell_error
7097 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7098 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007099 else
7100 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007101 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007102 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007103 endfor " for every file in the marked list
7104
Bram Moolenaar446cb832008-06-24 21:56:24 +00007105 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007106 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007107" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7108 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007109 endif
7110" call Dret("s:NetrwMarkFileCompress")
7111endfun
7112
7113" ---------------------------------------------------------------------
7114" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7115" If no marked files, then set up directory as the
7116" target. Currently does not support copying entire
7117" directories. Uses the local-buffer marked file list.
7118" Returns 1=success (used by NetrwMarkFileMove())
7119" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007120fun! s:NetrwMarkFileCopy(islocal,...)
7121" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7122
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007123 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007124 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007125 if b:netrw_curdir !~ '/$'
7126 if !exists("b:netrw_curdir")
7127 let b:netrw_curdir= curdir
7128 endif
7129 let b:netrw_curdir= b:netrw_curdir."/"
7130 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007131
Bram Moolenaarff034192013-04-24 18:51:19 +02007132 " sanity check
7133 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007134 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007135" call Dret("s:NetrwMarkFileCopy")
7136 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007137 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007138" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007139
Bram Moolenaar446cb832008-06-24 21:56:24 +00007140 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007141 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007142" call Dret("s:NetrwMarkFileCopy 0")
7143 return 0
7144 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007145" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007146
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007147 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007148 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007149" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007150 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007151 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7152" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7153 return
7154 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007155
7156 " copy marked files while within the same directory (ie. allow renaming)
7157 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7158 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7159 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007160" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007161 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007162 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7163 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007164" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007165 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007166 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007167 let oldname = a:1
7168 else
7169 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007170" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007171 let s:recursive= 1
7172 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7173 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7174 if ret == 0
7175 break
7176 endif
7177 endfor
7178 unlet s:recursive
7179 call s:NetrwUnmarkList(curbufnr,curdir)
7180" call Dret("s:NetrwMarkFileCopy ".ret)
7181 return ret
7182 endif
7183
7184 call inputsave()
7185 let newname= input("Copy ".oldname." to : ",oldname,"file")
7186 call inputrestore()
7187 if newname == ""
7188" call Dret("s:NetrwMarkFileCopy 0")
7189 return 0
7190 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007191 let args= s:ShellEscape(oldname)
7192 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007193 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007194 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7195 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007196 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007197 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007198 let args= substitute(args,'/','\\','g')
7199 let tgt = substitute(tgt, '/','\\','g')
7200 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007201 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7202 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7203 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7204 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7205" call Decho("args <".args.">",'~'.expand("<slnum>"))
7206" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007207 if isdirectory(s:NetrwFile(args))
7208" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007209 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007210" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007211 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007212 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7213 " contents to a target. One must append the source directory name to the target to get xcopy to
7214 " do the right thing.
7215 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007216" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007217 endif
7218 else
7219 let copycmd= g:netrw_localcopycmd
7220 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007221 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007222 let copycmd = substitute(copycmd,'\s.*$','','')
7223 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007224 let copycmd = netrw#WinPath(copycmd).copycmdargs
7225 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007226 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007227 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007228" call Decho("args <".args.">",'~'.expand("<slnum>"))
7229" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7230" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7231" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007232 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007233 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007234 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007235 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 +01007236 else
7237 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7238 endif
7239" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007240 return 0
7241 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007242
7243 elseif a:islocal && !s:netrwmftgt_islocal
7244 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007245" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007246 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007247
7248 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007249 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007250" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007251 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007252
7253 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007254 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007255" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007256 let curdir = getcwd()
7257 let tmpdir = s:GetTempfile("")
7258 if tmpdir !~ '/'
7259 let tmpdir= curdir."/".tmpdir
7260 endif
7261 if exists("*mkdir")
7262 call mkdir(tmpdir)
7263 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007264 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007265 if v:shell_error != 0
7266 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 +01007267" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007268 return
7269 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007270 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007271 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007272 if s:NetrwLcd(tmpdir)
7273" call Dret("s:NetrwMarkFileCopy : lcd failure")
7274 return
7275 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007276 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007277 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007278 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279 if getcwd() == tmpdir
7280 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007281 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007282 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007283 if s:NetrwLcd(curdir)
7284" call Dret("s:NetrwMarkFileCopy : lcd failure")
7285 return
7286 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007287 if delete(tmpdir,"d")
7288 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007289 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007290 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007291 if s:NetrwLcd(curdir)
7292" call Dret("s:NetrwMarkFileCopy : lcd failure")
7293 return
7294 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007295 endif
7296 endif
7297 endif
7298
7299 " -------
7300 " cleanup
7301 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007302" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007303 " remove markings from local buffer
7304 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007305" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7306" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7307" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7308" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7309" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7310" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7311 if exists("s:recursive")
7312" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7313 else
7314" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007315 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007316 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007317 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007318 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007319 else
7320 " refresh local and targets for fast browsing
7321 if !exists("s:recursive")
7322 " remove markings from local buffer
7323" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7324 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7325 endif
7326
7327 " refresh buffers
7328 if s:netrwmftgt_islocal
7329" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7330 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7331 endif
7332 if a:islocal && s:netrwmftgt != curdir
7333" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7334 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7335 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007336 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007337
Bram Moolenaar446cb832008-06-24 21:56:24 +00007338" call Dret("s:NetrwMarkFileCopy 1")
7339 return 1
7340endfun
7341
7342" ---------------------------------------------------------------------
7343" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7344" invoke vim's diff mode on the marked files.
7345" Either two or three files can be so handled.
7346" Uses the global marked file list.
7347fun! s:NetrwMarkFileDiff(islocal)
7348" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7349 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007350
Bram Moolenaarff034192013-04-24 18:51:19 +02007351 " sanity check
7352 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007353 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007354" call Dret("s:NetrwMarkFileDiff")
7355 return
7356 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007357 let curdir= s:NetrwGetCurdir(a:islocal)
7358" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007359
Bram Moolenaara6878372014-03-22 21:02:50 +01007360 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007362 for fname in s:netrwmarkfilelist
7363 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007364 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007365" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007366 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007367 diffthis
7368 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007369 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007370" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007371 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007372 diffthis
7373 else
7374 break
7375 endif
7376 endfor
7377 call s:NetrwUnmarkList(curbufnr,curdir)
7378 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007379
Bram Moolenaar446cb832008-06-24 21:56:24 +00007380" call Dret("s:NetrwMarkFileDiff")
7381endfun
7382
7383" ---------------------------------------------------------------------
7384" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7385" Uses global markfilelist
7386fun! s:NetrwMarkFileEdit(islocal)
7387" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7388
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007389 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007390 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007391
7392 " sanity check
7393 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007394 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007395" call Dret("s:NetrwMarkFileEdit")
7396 return
7397 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007398" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007399
Bram Moolenaar446cb832008-06-24 21:56:24 +00007400 if exists("s:netrwmarkfilelist_{curbufnr}")
7401 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007402 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007403 " unmark markedfile list
7404" call s:NetrwUnmarkList(curbufnr,curdir)
7405 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007406" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007407 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007408 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007409 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007410
Bram Moolenaar446cb832008-06-24 21:56:24 +00007411" call Dret("s:NetrwMarkFileEdit")
7412endfun
7413
7414" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007415" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007416fun! s:NetrwMarkFileQFEL(islocal,qfel)
7417" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7418 call s:NetrwUnmarkAll()
7419 let curbufnr= bufnr("%")
7420
7421 if !empty(a:qfel)
7422 for entry in a:qfel
7423 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007424" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007425 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007426" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007427 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7428 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7429 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7430 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007431" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007432 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7433 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007434" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007435 endif
7436 endfor
7437 echo "(use me to edit marked files)"
7438 else
7439 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7440 endif
7441
7442" call Dret("s:NetrwMarkFileQFEL")
7443endfun
7444
7445" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007446" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7447" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7448" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7449fun! s:NetrwMarkFileExe(islocal,enbloc)
7450" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007451 let svpos = winsaveview()
7452" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007453 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007454 let curbufnr = bufnr("%")
7455
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007456 if a:enbloc == 0
7457 " individually apply command to files, one at a time
7458 " sanity check
7459 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7460 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7461" call Dret("s:NetrwMarkFileExe")
7462 return
7463 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007464" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007465
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007466 if exists("s:netrwmarkfilelist_{curbufnr}")
7467 " get the command
7468 call inputsave()
7469 let cmd= input("Enter command: ","","file")
7470 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007471" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007472 if cmd == ""
7473" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7474 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007475 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007476
7477 " apply command to marked files, individually. Substitute: filename -> %
7478 " If no %, then append a space and the filename to the command
7479 for fname in s:netrwmarkfilelist_{curbufnr}
7480 if a:islocal
7481 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007482 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 endif
7484 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007485 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007486 endif
7487 if cmd =~ '%'
7488 let xcmd= substitute(cmd,'%',fname,'g')
7489 else
7490 let xcmd= cmd.' '.fname
7491 endif
7492 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007493" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007494 let ret= system(xcmd)
7495 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007496" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007497 let ret= s:RemoteSystem(xcmd)
7498 endif
7499 if v:shell_error < 0
7500 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7501 break
7502 else
7503 echo ret
7504 endif
7505 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007506
7507 " unmark marked file list
7508 call s:NetrwUnmarkList(curbufnr,curdir)
7509
7510 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007511 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007512" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7513 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007514 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007515 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007516 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007517
7518 else " apply command to global list of files, en bloc
7519
7520 call inputsave()
7521 let cmd= input("Enter command: ","","file")
7522 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007523" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007524 if cmd == ""
7525" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7526 return
7527 endif
7528 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007529 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007530 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007531 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007532 endif
7533 if a:islocal
7534 call system(cmd)
7535 if v:shell_error < 0
7536 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7537 endif
7538 else
7539 let ret= s:RemoteSystem(cmd)
7540 endif
7541 call s:NetrwUnmarkAll()
7542
7543 " refresh the listing
7544 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007545" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7546 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007547
7548 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007549
Bram Moolenaar446cb832008-06-24 21:56:24 +00007550" call Dret("s:NetrwMarkFileExe")
7551endfun
7552
7553" ---------------------------------------------------------------------
7554" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7555" as the marked file(s) (toggles suffix presence)
7556" Uses the local marked file list.
7557fun! s:NetrwMarkHideSfx(islocal)
7558" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007559 let svpos = winsaveview()
7560" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007561 let curbufnr = bufnr("%")
7562
7563 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7564 if exists("s:netrwmarkfilelist_{curbufnr}")
7565
7566 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007567" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007568 " construct suffix pattern
7569 if fname =~ '\.'
7570 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7571 else
7572 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7573 endif
7574 " determine if its in the hiding list or not
7575 let inhidelist= 0
7576 if g:netrw_list_hide != ""
7577 let itemnum = 0
7578 let hidelist= split(g:netrw_list_hide,',')
7579 for hidepat in hidelist
7580 if sfxpat == hidepat
7581 let inhidelist= 1
7582 break
7583 endif
7584 let itemnum= itemnum + 1
7585 endfor
7586 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007587" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007588 if inhidelist
7589 " remove sfxpat from list
7590 call remove(hidelist,itemnum)
7591 let g:netrw_list_hide= join(hidelist,",")
7592 elseif g:netrw_list_hide != ""
7593 " append sfxpat to non-empty list
7594 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7595 else
7596 " set hiding list to sfxpat
7597 let g:netrw_list_hide= sfxpat
7598 endif
7599 endfor
7600
7601 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007602 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007603" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7604 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007605 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007606 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007607 endif
7608
7609" call Dret("s:NetrwMarkHideSfx")
7610endfun
7611
7612" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007613" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007614" Uses the local marked-file list.
7615fun! s:NetrwMarkFileVimCmd(islocal)
7616" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007617 let svpos = winsaveview()
7618" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007619 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007620 let curbufnr = bufnr("%")
7621
Bram Moolenaarff034192013-04-24 18:51:19 +02007622 " sanity check
7623 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007624 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007625" call Dret("s:NetrwMarkFileVimCmd")
7626 return
7627 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007628" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007629
Bram Moolenaar15146672011-10-20 22:22:38 +02007630 if exists("s:netrwmarkfilelist_{curbufnr}")
7631 " get the command
7632 call inputsave()
7633 let cmd= input("Enter vim command: ","","file")
7634 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007635" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007636 if cmd == ""
7637" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7638 return
7639 endif
7640
7641 " apply command to marked files. Substitute: filename -> %
7642 " If no %, then append a space and the filename to the command
7643 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007644" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007645 if a:islocal
7646 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007647 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007648" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007649 exe cmd
7650 exe "sil! keepalt wq!"
7651 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007653 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007654 endif
7655 endfor
7656
7657 " unmark marked file list
7658 call s:NetrwUnmarkList(curbufnr,curdir)
7659
7660 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007661 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007662" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7663 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007664 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007665 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007666 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007667
Bram Moolenaar15146672011-10-20 22:22:38 +02007668" call Dret("s:NetrwMarkFileVimCmd")
7669endfun
7670
7671" ---------------------------------------------------------------------
7672" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7673" as the marked file(s) (toggles suffix presence)
7674" Uses the local marked file list.
7675fun! s:NetrwMarkHideSfx(islocal)
7676" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007677 let svpos = winsaveview()
7678" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007679 let curbufnr = bufnr("%")
7680
7681 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7682 if exists("s:netrwmarkfilelist_{curbufnr}")
7683
7684 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007685" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007686 " construct suffix pattern
7687 if fname =~ '\.'
7688 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7689 else
7690 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7691 endif
7692 " determine if its in the hiding list or not
7693 let inhidelist= 0
7694 if g:netrw_list_hide != ""
7695 let itemnum = 0
7696 let hidelist= split(g:netrw_list_hide,',')
7697 for hidepat in hidelist
7698 if sfxpat == hidepat
7699 let inhidelist= 1
7700 break
7701 endif
7702 let itemnum= itemnum + 1
7703 endfor
7704 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007705" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007706 if inhidelist
7707 " remove sfxpat from list
7708 call remove(hidelist,itemnum)
7709 let g:netrw_list_hide= join(hidelist,",")
7710 elseif g:netrw_list_hide != ""
7711 " append sfxpat to non-empty list
7712 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7713 else
7714 " set hiding list to sfxpat
7715 let g:netrw_list_hide= sfxpat
7716 endif
7717 endfor
7718
7719 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007720 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007721" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7722 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007723 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007724 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007725 endif
7726
7727" call Dret("s:NetrwMarkHideSfx")
7728endfun
7729
7730" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007731" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7732" Uses the global markfilelist
7733fun! s:NetrwMarkFileGrep(islocal)
7734" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007735 let svpos = winsaveview()
7736" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007737 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007738 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007739
7740 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007741" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007742 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007743" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007744 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007745 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007746" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007747 let netrwmarkfilelist= "*"
7748 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007749
Bram Moolenaarff034192013-04-24 18:51:19 +02007750 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007751" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007752 call inputsave()
7753 let pat= input("Enter pattern: ","")
7754 call inputrestore()
7755 let patbang = ""
7756 if pat =~ '^!'
7757 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007758 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007759 endif
7760 if pat =~ '^\i'
7761 let pat = escape(pat,'/')
7762 let pat = '/'.pat.'/'
7763 else
7764 let nonisi = pat[0]
7765 endif
7766
7767 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007768" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007769 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007770 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007771 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007772 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007773" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7774 return
7775 endtry
7776 echo "(use :cn, :cp to navigate, :Rex to return)"
7777
7778 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007779" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7780 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007781
7782 if exists("nonisi")
7783 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007784" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007785 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007786 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007787 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007788 endif
7789
7790" call Dret("s:NetrwMarkFileGrep")
7791endfun
7792
7793" ---------------------------------------------------------------------
7794" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7795" uses the global marked file list
7796" s:netrwmfloc= 0: target directory is remote
7797" = 1: target directory is local
7798fun! s:NetrwMarkFileMove(islocal)
7799" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007800 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007801 let curbufnr = bufnr("%")
7802
7803 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007804 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007805 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007806" call Dret("s:NetrwMarkFileMove")
7807 return
7808 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007809" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007810
Bram Moolenaar446cb832008-06-24 21:56:24 +00007811 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007812 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007813" call Dret("s:NetrwMarkFileCopy 0")
7814 return 0
7815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007816" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817
7818 if a:islocal && s:netrwmftgt_islocal
7819 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007820" call Decho("move from local to local",'~'.expand("<slnum>"))
7821" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007822 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007823 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7824" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7825 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007826 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007827 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007828" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007829 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007830 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007831" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007832 if g:netrw_localmovecmd =~ '\s'
7833 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7834 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7835 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007836" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007837 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007838 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007839" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007840 endif
7841 else
7842 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007844 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007845 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007846 if g:netrw_keepdir
7847 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7848 let fname= b:netrw_curdir."/".fname
7849 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007850 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007851 let fname= substitute(fname,'/','\\','g')
7852 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007854 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007855 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007856 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007857 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 +01007858 else
7859 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7860 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007861 break
7862 endif
7863 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007864
7865 elseif a:islocal && !s:netrwmftgt_islocal
7866 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007867" call Decho("move from local to remote",'~'.expand("<slnum>"))
7868" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007869 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007870 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007871" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007872 for fname in mflist
7873 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7874 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7875 endfor
7876 unlet mflist
7877
7878 elseif !a:islocal && s:netrwmftgt_islocal
7879 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007880" call Decho("move from remote to local",'~'.expand("<slnum>"))
7881" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007882 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007883 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007884" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007885 for fname in mflist
7886 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7887 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7888 endfor
7889 unlet mflist
7890
7891 elseif !a:islocal && !s:netrwmftgt_islocal
7892 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007893" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7894" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007896 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007897" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007898 for fname in mflist
7899 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7900 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7901 endfor
7902 unlet mflist
7903 endif
7904
7905 " -------
7906 " cleanup
7907 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007908" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909
7910 " remove markings from local buffer
7911 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7912
7913 " refresh buffers
7914 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007915" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007916 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007917 endif
7918 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007919" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007920 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007921 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007922 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007923" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007924 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007925 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007926
Bram Moolenaar446cb832008-06-24 21:56:24 +00007927" call Dret("s:NetrwMarkFileMove")
7928endfun
7929
7930" ---------------------------------------------------------------------
7931" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7932" using the hardcopy command. Local marked-file list only.
7933fun! s:NetrwMarkFilePrint(islocal)
7934" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7935 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007936
7937 " sanity check
7938 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007939 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007940" call Dret("s:NetrwMarkFilePrint")
7941 return
7942 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007943" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7944 let curdir= s:NetrwGetCurdir(a:islocal)
7945
Bram Moolenaar446cb832008-06-24 21:56:24 +00007946 if exists("s:netrwmarkfilelist_{curbufnr}")
7947 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007948 call s:NetrwUnmarkList(curbufnr,curdir)
7949 for fname in netrwmarkfilelist
7950 if a:islocal
7951 if g:netrw_keepdir
7952 let fname= s:ComposePath(curdir,fname)
7953 endif
7954 else
7955 let fname= curdir.fname
7956 endif
7957 1split
7958 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007959" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007960 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007961" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007962 hardcopy
7963 q
7964 endfor
7965 2match none
7966 endif
7967" call Dret("s:NetrwMarkFilePrint")
7968endfun
7969
7970" ---------------------------------------------------------------------
7971" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7972" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007973" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007974fun! s:NetrwMarkFileRegexp(islocal)
7975" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7976
7977 " get the regular expression
7978 call inputsave()
7979 let regexp= input("Enter regexp: ","","file")
7980 call inputrestore()
7981
7982 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007983 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007984" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007985 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007986" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007987 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007988 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007989 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007990 else
7991 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007992 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007993 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007994" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007995
7996 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007997 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007998 if fname =~ '^'.fnameescape(curdir)
7999" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8000 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8001 else
8002" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8003 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8004 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008005 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006
8007 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008008" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008009
8010 " convert displayed listing into a filelist
8011 let eikeep = &ei
8012 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008013 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008014 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008015" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008017 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008018 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008019 sil NetrwKeepj norm! "ap
8020 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008022 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008023 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008025 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008026 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008028 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008029 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008030 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008031 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8032 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008033 call histdel("/",-1)
8034 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008035 endif
8036 " convert regexp into the more usual glob-style format
8037 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008038" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008039 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008040 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008041 let filelist= getline(1,line("$"))
8042 q!
8043 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008044 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045 endfor
8046 unlet filelist
8047 let @a = areg
8048 let &ei = eikeep
8049 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008050 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051
8052" call Dret("s:NetrwMarkFileRegexp")
8053endfun
8054
8055" ---------------------------------------------------------------------
8056" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8057" Uses the local marked file list.
8058fun! s:NetrwMarkFileSource(islocal)
8059" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8060 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008061
8062 " sanity check
8063 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008064 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008065" call Dret("s:NetrwMarkFileSource")
8066 return
8067 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008068" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8069 let curdir= s:NetrwGetCurdir(a:islocal)
8070
Bram Moolenaar446cb832008-06-24 21:56:24 +00008071 if exists("s:netrwmarkfilelist_{curbufnr}")
8072 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008073 call s:NetrwUnmarkList(curbufnr,curdir)
8074 for fname in netrwmarkfilelist
8075 if a:islocal
8076 if g:netrw_keepdir
8077 let fname= s:ComposePath(curdir,fname)
8078 endif
8079 else
8080 let fname= curdir.fname
8081 endif
8082 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008083" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008084 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008085 endfor
8086 2match none
8087 endif
8088" call Dret("s:NetrwMarkFileSource")
8089endfun
8090
8091" ---------------------------------------------------------------------
8092" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8093" Uses the global markfilelist
8094fun! s:NetrwMarkFileTag(islocal)
8095" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008096 let svpos = winsaveview()
8097" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008098 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008099 let curbufnr = bufnr("%")
8100
Bram Moolenaarff034192013-04-24 18:51:19 +02008101 " sanity check
8102 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008103 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008104" call Dret("s:NetrwMarkFileTag")
8105 return
8106 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008107" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008108
Bram Moolenaar446cb832008-06-24 21:56:24 +00008109 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008110" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8111 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008112 call s:NetrwUnmarkAll()
8113
8114 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008115
8116" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8117 call system(g:netrw_ctags." ".netrwmarkfilelist)
8118 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008119 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8120 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008121
Bram Moolenaar446cb832008-06-24 21:56:24 +00008122 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008123 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008124 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008125 let curdir= b:netrw_curdir
8126 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008127 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008128 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008129" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008130 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008131 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008132 wq!
8133 endif
8134 2match none
8135 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008136" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8137 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138 endif
8139
8140" call Dret("s:NetrwMarkFileTag")
8141endfun
8142
8143" ---------------------------------------------------------------------
8144" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008145" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008146" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008147" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008148" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008150" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8151 let svpos = winsaveview()
8152" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008153 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008154 let hadtgt = exists("s:netrwmftgt")
8155 if !exists("w:netrw_bannercnt")
8156 let w:netrw_bannercnt= b:netrw_bannercnt
8157 endif
8158
8159 " set up target
8160 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008161" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008162 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8163 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008164" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008165 unlet s:netrwmftgt s:netrwmftgt_islocal
8166 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008167 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008168 endif
8169 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008170" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8171 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008172" call Dret("s:NetrwMarkFileTgt : removed target")
8173 return
8174 else
8175 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008176" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008177 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008178
8179 else
8180 " get word under cursor.
8181 " * If directory, use it for the target.
8182 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184 let curword= s:NetrwGetWord()
8185 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008186 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008187 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008189 elseif !a:islocal && tgtdir =~ '/$'
8190 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008192 else
8193 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008194" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008195 endif
8196 endif
8197 if a:islocal
8198 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8199 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008200" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008201 endif
8202 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008203 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008204 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8205 endif
8206 let s:netrwmftgt_islocal= a:islocal
8207
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008208 " need to do refresh so that the banner will be updated
8209 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008210 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008211" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008212 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008213 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008214" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008215 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008216 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8217 else
8218 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8219 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008220" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8221 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008222 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008223 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008224 endif
8225
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008226" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8227" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008228" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8229endfun
8230
8231" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008232" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8233fun! s:NetrwGetCurdir(islocal)
8234" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8235
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008236 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008237 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8238" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8239 elseif !exists("b:netrw_curdir")
8240 let b:netrw_curdir= getcwd()
8241" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8242 endif
8243
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008244" 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 +01008245 if b:netrw_curdir !~ '\<\a\{3,}://'
8246 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008247" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008248 if g:netrw_keepdir == 0
8249 call s:NetrwLcd(curdir)
8250 endif
8251 endif
8252
8253" call Dret("s:NetrwGetCurdir <".curdir.">")
8254 return b:netrw_curdir
8255endfun
8256
8257" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008258" s:NetrwOpenFile: query user for a filename and open it {{{2
8259fun! s:NetrwOpenFile(islocal)
8260" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008261 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008262 call inputsave()
8263 let fname= input("Enter filename: ")
8264 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008265" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8266
8267 " determine if Lexplore is in use
8268 if exists("t:netrw_lexbufnr")
8269 " check if t:netrw_lexbufnr refers to a netrw window
8270" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8271 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8272 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8273" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8274 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8275 exe "NetrwKeepj e ".fnameescape(fname)
8276 let @@= ykeep
8277" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8278 endif
8279 endif
8280
8281 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008282 if fname !~ '[/\\]'
8283 if exists("b:netrw_curdir")
8284 if exists("g:netrw_quiet")
8285 let netrw_quiet_keep = g:netrw_quiet
8286 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008287 let g:netrw_quiet = 1
8288 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008289 let s:rexposn_{bufnr("%")}= winsaveview()
8290" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008291 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008292 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008293 else
8294 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8295 endif
8296 if exists("netrw_quiet_keep")
8297 let g:netrw_quiet= netrw_quiet_keep
8298 else
8299 unlet g:netrw_quiet
8300 endif
8301 endif
8302 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008303 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008304 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008305 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008306" call Dret("s:NetrwOpenFile")
8307endfun
8308
8309" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008310" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8311" For the mapping to this function be made via
8312" netrwPlugin, you'll need to have had
8313" g:netrw_usetab set to non-zero.
8314fun! netrw#Shrink()
8315" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8316 let curwin = winnr()
8317 let wiwkeep = &wiw
8318 set wiw=1
8319
8320 if &ft == "netrw"
8321 if winwidth(0) > g:netrw_wiw
8322 let t:netrw_winwidth= winwidth(0)
8323 exe "vert resize ".g:netrw_wiw
8324 wincmd l
8325 if winnr() == curwin
8326 wincmd h
8327 endif
8328" call Decho("vert resize 0",'~'.expand("<slnum>"))
8329 else
8330 exe "vert resize ".t:netrw_winwidth
8331" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8332 endif
8333
8334 elseif exists("t:netrw_lexbufnr")
8335 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8336 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8337 let t:netrw_winwidth= winwidth(0)
8338 exe "vert resize ".g:netrw_wiw
8339 wincmd l
8340 if winnr() == curwin
8341 wincmd h
8342 endif
8343" call Decho("vert resize 0",'~'.expand("<slnum>"))
8344 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8345 exe "vert resize ".t:netrw_winwidth
8346" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8347 else
8348 call netrw#Lexplore(0,0)
8349 endif
8350
8351 else
8352 call netrw#Lexplore(0,0)
8353 endif
8354 let wiw= wiwkeep
8355
8356" call Dret("netrw#Shrink")
8357endfun
8358
8359" ---------------------------------------------------------------------
8360" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8361fun! s:NetSortSequence(islocal)
8362" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8363
8364 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008365 let svpos= winsaveview()
8366" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008367 call inputsave()
8368 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8369 call inputrestore()
8370
8371 " refresh the listing
8372 let g:netrw_sort_sequence= newsortseq
8373 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008374" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8375 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008376 let @@= ykeep
8377
8378" call Dret("NetSortSequence")
8379endfun
8380
8381" ---------------------------------------------------------------------
8382" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8383" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008384" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008385fun! s:NetrwUnmarkList(curbufnr,curdir)
8386" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8387
8388 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008389 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008390 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8391 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8392 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8393 call remove(s:netrwmarkfilelist,idx) " remove from global list
8394 endfor
8395 if s:netrwmarkfilelist == []
8396 unlet s:netrwmarkfilelist
8397 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008398
Bram Moolenaar446cb832008-06-24 21:56:24 +00008399 " getting rid of the local marked-file lists is easy
8400 unlet s:netrwmarkfilelist_{a:curbufnr}
8401 endif
8402 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8403 unlet s:netrwmarkfilemtch_{a:curbufnr}
8404 endif
8405 2match none
8406" call Dret("s:NetrwUnmarkList")
8407endfun
8408
8409" ---------------------------------------------------------------------
8410" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8411fun! s:NetrwUnmarkAll()
8412" call Dfunc("s:NetrwUnmarkAll()")
8413 if exists("s:netrwmarkfilelist")
8414 unlet s:netrwmarkfilelist
8415 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008416 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008417 2match none
8418" call Dret("s:NetrwUnmarkAll")
8419endfun
8420
8421" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008422" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008423fun! s:NetrwUnmarkAll2()
8424" call Dfunc("s:NetrwUnmarkAll2()")
8425 redir => netrwmarkfilelist_let
8426 let
8427 redir END
8428 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008429 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008430 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8431 for flist in netrwmarkfilelist_list
8432 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8433 unlet s:netrwmarkfilelist_{curbufnr}
8434 unlet s:netrwmarkfilemtch_{curbufnr}
8435 endfor
8436" call Dret("s:NetrwUnmarkAll2")
8437endfun
8438
8439" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008440" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8441"
8442" Marked files are in two types of lists:
8443" s:netrwmarkfilelist -- holds complete paths to all marked files
8444" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8445"
8446" Marked files suitable for use with 2match are in:
8447" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008448fun! s:NetrwUnMarkFile(islocal)
8449" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008450 let svpos = winsaveview()
8451" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008452 let curbufnr = bufnr("%")
8453
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008454 " unmark marked file list
8455 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8456 if exists("s:netrwmarkfilelist")
8457" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008458 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459 endif
8460
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008461 let ibuf= 1
8462 while ibuf < bufnr("$")
8463 if exists("s:netrwmarkfilelist_".ibuf)
8464 unlet s:netrwmarkfilelist_{ibuf}
8465 unlet s:netrwmarkfilemtch_{ibuf}
8466 endif
8467 let ibuf = ibuf + 1
8468 endwhile
8469 2match none
8470
Bram Moolenaar446cb832008-06-24 21:56:24 +00008471" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008472"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8473call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008474" call Dret("s:NetrwUnMarkFile")
8475endfun
8476
8477" ---------------------------------------------------------------------
8478" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8479fun! s:NetrwMenu(domenu)
8480
8481 if !exists("g:NetrwMenuPriority")
8482 let g:NetrwMenuPriority= 80
8483 endif
8484
Bram Moolenaaradc21822011-04-01 18:03:16 +02008485 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008486" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8487
8488 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008489" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008490 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008491 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8495 if g:netrw_dirhistmax > 0
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8497 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8500 else
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8502 endif
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8517 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 +01008518 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 +02008519 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8548 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>'
8549 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>'
8550 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>'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8552 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>'
8553 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>'
8554 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 +01008555 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 +02008556 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008558 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008559 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8560 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008561
8562 elseif !a:domenu
8563 let s:netrwcnt = 0
8564 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008565 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008566 exe curwin."wincmd w"
8567
8568 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008569" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008570 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008571" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008572 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008573 endif
8574 endif
8575" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008576 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008577 endif
8578
8579endfun
8580
8581" ---------------------------------------------------------------------
8582" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8583" Used by the O maps (as <SID>NetrwObtain())
8584fun! s:NetrwObtain(islocal)
8585" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8586
Bram Moolenaar97d62492012-11-15 21:28:22 +01008587 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008588 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008589 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008590 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008591 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8592 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008593 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008594 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008595 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008596
8597" call Dret("NetrwObtain")
8598endfun
8599
8600" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8602" If there's only one window, then the window will first be split.
8603" Returns:
8604" choice = 0 : didn't have to choose
8605" choice = 1 : saved modified file in window first
8606" choice = 2 : didn't save modified file, opened window
8607" choice = 3 : cancel open
8608fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008609" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008610
Bram Moolenaar97d62492012-11-15 21:28:22 +01008611 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008613 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008614" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615
8616 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008617 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008618 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008619" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8620" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8621 let curword = s:NetrwGetWord()
8622 let choice = 0
8623 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8624" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008625 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008626" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008627 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008628" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008629" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008630" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631
Bram Moolenaar8d043172014-01-23 14:24:41 +01008632 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008633 if lastwinnr == 1
8634 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008635" 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 +02008636 " g:netrw_preview=0: preview window shown in a horizontally split window
8637 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008638 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008639 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008640 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008641" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008642 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008644 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008645 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008646" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008647 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008649 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008650" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008651
8652 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008653" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008654 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008655" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008656 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008657" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008658 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008659" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008660 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008661" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008662" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008663" call Decho("COMBAK#12: mod=".&mod)
8664
8665 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8666 " whoops -- user trying to open file in the Lexplore window.
8667 " Use Lexplore's opening-file window instead.
8668" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8669" exe g:netrw_chgwin."wincmd w"
8670 wincmd p
8671 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8672 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008673
8674 " prevwinnr: the window number of the "prev" window
8675 " prevbufnr: the buffer number of the buffer in the "prev" window
8676 " bnrcnt : the qty of windows open on the "prev" buffer
8677 let prevwinnr = winnr()
8678 let prevbufnr = bufnr("%")
8679 let prevbufname = bufname("%")
8680 let prevmod = &mod
8681 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008682" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008683 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008684" 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 +01008685" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008686
8687 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008688 " and it doesn't appear in any other extant window, then ask the
8689 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008690 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008691" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008692 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008693" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008694 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008695" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008696
8697 if bnrcnt == 1 && &hidden == 0
8698 " only one copy of the modified buffer in a window, and
8699 " hidden not set, so overwriting will lose the modified file. Ask first...
8700 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008701" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008702 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008703" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008704
8705 if choice == 1
8706 " Yes -- write file & then browse
8707 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008708 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008710 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008711 exe origwin."wincmd w"
8712 let &ei = eikeep
8713 let @@ = ykeep
8714" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715 return choice
8716 endif
8717
8718 elseif choice == 2
8719 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008720" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008721 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008722
8723 else
8724 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008725" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008726 exe origwin."wincmd w"
8727 let &ei= eikeep
8728 let @@ = ykeep
8729" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008730 return choice
8731 endif
8732 endif
8733 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008734 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008735 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008736" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008737
8738 " restore b:netrw_curdir (window split/enew may have lost it)
8739 let b:netrw_curdir= curdir
8740 if a:islocal < 2
8741 if a:islocal
8742 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8743 else
8744 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8745 endif
8746 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008747 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008748" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008749 return choice
8750endfun
8751
8752" ---------------------------------------------------------------------
8753" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8754" Always assumed to be local -> remote
8755" call s:NetrwUpload(filename, target)
8756" call s:NetrwUpload(filename, target, fromdirectory)
8757fun! s:NetrwUpload(fname,tgt,...)
8758" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8759
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008760 if a:tgt =~ '^\a\{3,}://'
8761 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008762 else
8763 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8764 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008765" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008766
8767 if a:0 > 0
8768 let fromdir= a:1
8769 else
8770 let fromdir= getcwd()
8771 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008772" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008773
8774 if type(a:fname) == 1
8775 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008776" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008777 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008778" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8779 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8780" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008781 if a:tgt =~ '/$'
8782 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008784 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008785 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008786" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008787 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008788" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008789 endif
8790 q!
8791
8792 elseif type(a:fname) == 3
8793 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008794" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008795 let curdir= getcwd()
8796 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008797 if s:NetrwLcd(fromdir)
8798" call Dret("s:NetrwUpload : lcd failure")
8799 return
8800 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008801 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008802 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008803 if exists("g:netrw_port") && g:netrw_port != ""
8804 let useport= " ".g:netrw_scpport." ".g:netrw_port
8805 else
8806 let useport= ""
8807 endif
8808 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8809 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008810 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 +02008811 if s:NetrwLcd(curdir)
8812" call Dret("s:NetrwUpload : lcd failure")
8813 return
8814 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008815
8816 elseif a:tgt =~ '^ftp:'
8817 call s:NetrwMethod(a:tgt)
8818
8819 if b:netrw_method == 2
8820 " handle uploading a list of files via ftp+.netrc
8821 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008822 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008825 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008826" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008827
8828 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008829 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008830" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008831 endif
8832
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008833 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008834" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008835
Bram Moolenaaradc21822011-04-01 18:03:16 +02008836 if tgtdir == ""
8837 let tgtdir= '/'
8838 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008839 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008840" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008841
8842 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008843 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8844" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845 endfor
8846
8847 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008848 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 +00008849 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008850" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8851 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008852 endif
8853 " 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 +01008854 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008855 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8857 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8858 else
8859 bw!|q
8860 endif
8861
8862 elseif b:netrw_method == 3
8863 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8864 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008865 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008866 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008867 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008868
8869 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008870 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008871" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008872 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008873 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008874" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008875 endif
8876
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008877 if exists("g:netrw_uid") && g:netrw_uid != ""
8878 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008879 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008880" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008881 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008882 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008884" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008885 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008886 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008887" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008888 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008889 endif
8890
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008891 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008892" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008893
8894 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008895 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008896" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008897 endif
8898
8899 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008900 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008901" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008902 endif
8903
8904 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008905 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008906" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008907 endfor
8908
8909 " perform ftp:
8910 " -i : turns off interactive prompting from ftp
8911 " -n unix : DON'T use <.netrc>, even though it exists
8912 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008913 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008914 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008915 " 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 +01008916 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008917 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008918 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8919 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008920 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008921 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8922 let &debug = debugkeep
8923 let mod = 1
8924 else
8925 bw!|q
8926 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008927 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008928" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008929 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930 endif
8931 else
8932 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8933 endif
8934 endif
8935
8936" call Dret("s:NetrwUpload")
8937endfun
8938
8939" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008940" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008941fun! s:NetrwPreview(path) range
8942" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008943" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8944" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008945 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008946 NetrwKeepj call s:NetrwOptionsSave("s:")
8947 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8948 NetrwKeepj call s:NetrwOptionsSafe(1)
8949 else
8950 NetrwKeepj call s:NetrwOptionsSafe(0)
8951 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008952 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008953" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008954 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008955" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8956 if g:netrw_preview
8957 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008958 let pvhkeep = &pvh
8959 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8960 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008961" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8962 else
8963 " horizontal split
8964 let pvhkeep = &pvh
8965 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8966 let &pvh = winheight(0) - winsz
8967" 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 +02008968 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008969 " g:netrw_preview g:netrw_alto
8970 " 1 : vert 1: top -- preview window is vertically split off and on the left
8971 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8972 " 0 : 1: top -- preview window is horizontally split off and on the top
8973 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8974 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008975 " 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 +02008976 " the BufEnter event set up in netrwPlugin.vim
8977" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8978 let eikeep = &ei
8979 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008980 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008981 let &ei= eikeep
8982" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008983 if exists("pvhkeep")
8984 let &pvh= pvhkeep
8985 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008986 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008987 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008988 endif
8989 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008990 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 +00008991 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008992 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008993 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008994" call Dret("NetrwPreview")
8995endfun
8996
8997" ---------------------------------------------------------------------
8998" s:NetrwRefresh: {{{2
8999fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009000" 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 +00009001 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009002 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009003" call Decho("setl ma noro",'~'.expand("<slnum>"))
9004" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009005 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009006 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9007 if !exists("w:netrw_treetop")
9008 if exists("b:netrw_curdir")
9009 let w:netrw_treetop= b:netrw_curdir
9010 else
9011 let w:netrw_treetop= getcwd()
9012 endif
9013 endif
9014 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9015 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009016
9017 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009018 let screenposn = winsaveview()
9019" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009020
9021" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9022" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9023 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009024 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009025 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009026 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009027 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009028 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009029
9030 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009031" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9032 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009033
9034 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009035 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9036 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9037" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9038 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9039 else
9040" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9041 2match none
9042 endif
9043 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009044
Bram Moolenaar97d62492012-11-15 21:28:22 +01009045" restore
9046 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009047" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009048endfun
9049
9050" ---------------------------------------------------------------------
9051" s:NetrwRefreshDir: refreshes a directory by name {{{2
9052" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009053" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009055" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009056 if g:netrw_fastbrowse == 0
9057 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009058" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009059 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009060" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009061
9062 if tgtwin > 0
9063 " tgtwin is being displayed, so refresh it
9064 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009065" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009066 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009067 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009068 exe curwin."wincmd w"
9069
9070 elseif bufnr(a:dirname) > 0
9071 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009072" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9073 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074 endif
9075
9076 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009077" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009078 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079 endif
9080" call Dret("s:NetrwRefreshDir")
9081endfun
9082
9083" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009084" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9085" window number to do its editing in.
9086" Supports [count]C where the count, if present, is used to specify
9087" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009088fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009089" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009090 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009091" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009092 if a:1 == "" " :NetrwC win#
9093 let g:netrw_chgwin= winnr()
9094 else " :NetrwC
9095 let g:netrw_chgwin= a:1
9096 endif
9097 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009098 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009099 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009100 let g:netrw_chgwin= winnr()
9101 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009102 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009103" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009104endfun
9105
9106" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009107" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9108" What this function does is to compute a priority for the patterns
9109" in the g:netrw_sort_sequence. It applies a substitute to any
9110" "files" that satisfy each pattern, putting the priority / in
9111" front. An "*" pattern handles the default priority.
9112fun! s:NetrwSetSort()
9113" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009114 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009115 if w:netrw_liststyle == s:LONGLIST
9116 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9117 else
9118 let seqlist = g:netrw_sort_sequence
9119 endif
9120 " sanity check -- insure that * appears somewhere
9121 if seqlist == ""
9122 let seqlist= '*'
9123 elseif seqlist !~ '\*'
9124 let seqlist= seqlist.',*'
9125 endif
9126 let priority = 1
9127 while seqlist != ""
9128 if seqlist =~ ','
9129 let seq = substitute(seqlist,',.*$','','e')
9130 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9131 else
9132 let seq = seqlist
9133 let seqlist = ""
9134 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009135 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009136 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009137 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009138 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009139 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009140 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009141 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009142" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009143
9144 " sanity check
9145 if w:netrw_bannercnt > line("$")
9146 " apparently no files were left after a Hiding pattern was used
9147" call Dret("SetSort : no files left after hiding")
9148 return
9149 endif
9150 if seq == '*'
9151 let starpriority= spriority
9152 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009153 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009154 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009155 " sometimes multiple sorting patterns will match the same file or directory.
9156 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009157 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9158 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009159 endif
9160 let priority = priority + 1
9161 endwhile
9162 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009163 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9164 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165 endif
9166
9167 " Following line associated with priority -- items that satisfy a priority
9168 " pattern get prefixed by ###/ which permits easy sorting by priority.
9169 " Sometimes files can satisfy multiple priority patterns -- only the latest
9170 " priority pattern needs to be retained. So, at this point, these excess
9171 " priority prefixes need to be removed, but not directories that happen to
9172 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009173 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9174 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009175 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009176
9177" call Dret("SetSort")
9178endfun
9179
Bram Moolenaarff034192013-04-24 18:51:19 +02009180" ---------------------------------------------------------------------
9181" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9182" Implements [count]Tb (bookhist<b>)
9183" [count]Th (bookhist<h>)
9184" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009185fun! s:NetrwSetTgt(islocal,bookhist,choice)
9186" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009187
9188 if a:bookhist == 'b'
9189 " supports choosing a bookmark as a target using a qb-generated list
9190 let choice= a:choice - 1
9191 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009192 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009193 else
9194 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9195 endif
9196
9197 elseif a:bookhist == 'h'
9198 " supports choosing a history stack entry as a target using a qb-generated list
9199 let choice= (a:choice % g:netrw_dirhistmax) + 1
9200 if exists("g:netrw_dirhist_".choice)
9201 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009202 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009203 else
9204 echomsg "Sorry, history#".a:choice." not available!"
9205 endif
9206 endif
9207
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009208 " refresh the display
9209 if !exists("b:netrw_curdir")
9210 let b:netrw_curdir= getcwd()
9211 endif
9212 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9213
Bram Moolenaarff034192013-04-24 18:51:19 +02009214" call Dret("s:NetrwSetTgt")
9215endfun
9216
Bram Moolenaar446cb832008-06-24 21:56:24 +00009217" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009218" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009219fun! s:NetrwSortStyle(islocal)
9220" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009221 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009222 let svpos= winsaveview()
9223" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009224
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009225 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 +01009226 NetrwKeepj norm! 0
9227 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009228" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9229 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009230
9231" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9232endfun
9233
9234" ---------------------------------------------------------------------
9235" s:NetrwSplit: mode {{{2
9236" =0 : net and o
9237" =1 : net and t
9238" =2 : net and v
9239" =3 : local and o
9240" =4 : local and t
9241" =5 : local and v
9242fun! s:NetrwSplit(mode)
9243" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9244
Bram Moolenaar97d62492012-11-15 21:28:22 +01009245 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009246 call s:SaveWinVars()
9247
9248 if a:mode == 0
9249 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009250 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009251 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009252" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009253 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009254 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009255 NetrwKeepj call s:RestoreWinVars()
9256 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009257 unlet s:didsplit
9258
9259 elseif a:mode == 1
9260 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009261 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009262" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263 tabnew
9264 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009265 NetrwKeepj call s:RestoreWinVars()
9266 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 unlet s:didsplit
9268
9269 elseif a:mode == 2
9270 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009271 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009272 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009273" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009274 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009275 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009276 NetrwKeepj call s:RestoreWinVars()
9277 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278 unlet s:didsplit
9279
9280 elseif a:mode == 3
9281 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009282 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009283 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009284" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009285 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009287 NetrwKeepj call s:RestoreWinVars()
9288 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009289 unlet s:didsplit
9290
9291 elseif a:mode == 4
9292 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009293 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009294 let eikeep = &ei
9295 let netrw_winnr = winnr()
9296 let netrw_line = line(".")
9297 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009298 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009299 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009300 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009301 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9302 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009303 let &ei = eikeep
9304 let netrw_curdir = s:NetrwTreeDir(0)
9305" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009306 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009307 let b:netrw_curdir = netrw_curdir
9308 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009309 NetrwKeepj call s:RestoreWinVars()
9310 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009311 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009312 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009313 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9314 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009315 let &ei= eikeep
9316 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009317 unlet s:didsplit
9318
9319 elseif a:mode == 5
9320 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009321 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009322 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009323" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009324 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009325 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009326 NetrwKeepj call s:RestoreWinVars()
9327 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009328 unlet s:didsplit
9329
9330 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009331 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009332 endif
9333
Bram Moolenaar97d62492012-11-15 21:28:22 +01009334 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009335" call Dret("s:NetrwSplit")
9336endfun
9337
9338" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009339" s:NetrwTgtMenu: {{{2
9340fun! s:NetrwTgtMenu()
9341 if !exists("s:netrw_menucnt")
9342 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009343 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009344" call Dfunc("s:NetrwTgtMenu()")
9345
9346 " the following test assures that gvim is running, has menus available, and has menus enabled.
9347 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9348 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009349" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009350 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9351 endif
9352 if !exists("s:netrw_initbookhist")
9353 call s:NetrwBookHistRead()
9354 endif
9355
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009356 " try to cull duplicate entries
9357 let tgtdict={}
9358
Bram Moolenaarff034192013-04-24 18:51:19 +02009359 " target bookmarked places
9360 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009361" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009362 let cnt= 1
9363 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009364 if has_key(tgtdict,bmd)
9365 let cnt= cnt + 1
9366 continue
9367 endif
9368 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009369 let ebmd= escape(bmd,g:netrw_menu_escape)
9370 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009371" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009372 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 +02009373 let cnt= cnt + 1
9374 endfor
9375 endif
9376
9377 " target directory browsing history
9378 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009379" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009380 let histcnt = 1
9381 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009382 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009383 if exists("g:netrw_dirhist_{histcnt}")
9384 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385 if has_key(tgtdict,histentry)
9386 let histcnt = histcnt + 1
9387 continue
9388 endif
9389 let tgtdict[histentry] = histcnt
9390 let ehistentry = escape(histentry,g:netrw_menu_escape)
9391" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009392 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 +02009393 endif
9394 let histcnt = histcnt + 1
9395 endwhile
9396 endif
9397 endif
9398" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009399endfun
9400
9401" ---------------------------------------------------------------------
9402" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9403" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009404fun! s:NetrwTreeDir(islocal)
9405" 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 +02009406" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009407" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9408" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9409" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009410" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009411
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009412 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009413 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009414" 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 +01009415 let treedir= s:treedir
9416 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009417 unlet s:prevwinopen
9418" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009419 return treedir
9420 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009421 if exists("s:prevwinopen")
9422 unlet s:prevwinopen
9423 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009424" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009425
Bram Moolenaar8d043172014-01-23 14:24:41 +01009426 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9427 let b:netrw_curdir= getcwd()
9428 endif
9429 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009430" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009431" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009432
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009433 let s:treecurpos= winsaveview()
9434" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009435" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009436
9437 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009438" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9439" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009440" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009441
9442 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009443 let curline= substitute(getline('.'),"\t -->.*$",'','')
9444 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009445" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009446 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009447" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9448 elseif curline =~ '@$'
9449" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009450 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009451" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009452 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009453" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009454 let treedir= ""
9455 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009456" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009457
9458 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009459" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9460" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009461" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009462 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009463" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009464 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009465" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9466 sil! NetrwKeepj %d _
9467" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009468 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009469" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009470" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009471 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009472" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009473
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009474" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009475" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009476" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009477
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009478 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9479" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9480" let newdir = w:netrw_treetop.'/'.potentialdir
9481" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9482" let treedir = s:NetrwTreePath(newdir)
9483" let w:netrw_treetop = newdir
9484" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9485" else
9486" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009487 if a:islocal && curline =~ '@$'
9488 if isdirectory(s:NetrwFile(potentialdir))
9489 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9490 let w:netrw_treetop = treedir
9491 endif
9492 else
9493 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9494 let treedir = s:NetrwTreePath(w:netrw_treetop)
9495 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009496 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009497" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009498
9499 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009501" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009502" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009503
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009504" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009505 return treedir
9506endfun
9507
9508" ---------------------------------------------------------------------
9509" s:NetrwTreeDisplay: recursive tree display {{{2
9510fun! s:NetrwTreeDisplay(dir,depth)
9511" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9512
9513 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009514 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009515
9516 " install ../ and shortdir
9517 if a:depth == ""
9518 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009519" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009520 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009521 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009522 if a:dir == w:netrw_treetop
9523 let shortdir= a:dir
9524 else
9525 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9526 endif
9527 call setline(line("$")+1,a:depth.shortdir)
9528 else
9529 let shortdir= substitute(a:dir,'^.*/','','e')
9530 call setline(line("$")+1,a:depth.shortdir.'/')
9531 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009532" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009533 " append a / to dir if its missing one
9534 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009535
9536 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009537 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009538" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009539
Bram Moolenaar85850f32019-07-19 22:05:51 +02009540 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9541 if g:netrw_hide == 1
9542 " hide given patterns
9543 let listhide= split(g:netrw_list_hide,',')
9544" call Decho("listhide=".string(listhide))
9545 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009546 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009547 endfor
9548
9549 elseif g:netrw_hide == 2
9550 " show given patterns (only)
9551 let listhide= split(g:netrw_list_hide,',')
9552" call Decho("listhide=".string(listhide))
9553 let entries=[]
9554 for entry in w:netrw_treedict[dir]
9555 for pat in listhide
9556 if entry =~ pat
9557 call add(entries,entry)
9558 break
9559 endif
9560 endfor
9561 endfor
9562 let w:netrw_treedict[dir]= entries
9563 endif
9564 if depth != ""
9565 " always remove "." and ".." entries when there's depth
9566 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9567 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9568 endif
9569
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009570" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009571 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009572 if dir =~ '/$'
9573 let direntry= substitute(dir.entry,'[@/]$','','e')
9574 else
9575 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9576 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009577" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578 if 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>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009580 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009581 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009582" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9583 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9584 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9585" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009586 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009587 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009588" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009589 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009590 endif
9591 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009592" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009593
Bram Moolenaar446cb832008-06-24 21:56:24 +00009594" call Dret("NetrwTreeDisplay")
9595endfun
9596
9597" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009598" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9599fun! s:NetrwRefreshTreeDict(dir)
9600" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009601 if !exists("w:netrw_treedict")
9602" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9603 return
9604 endif
9605
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009606 for entry in w:netrw_treedict[a:dir]
9607 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9608" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9609
9610 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9611" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9612 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009613 let liststar = s:NetrwGlob(direntry,'*',1)
9614 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009615 let w:netrw_treedict[direntry] = liststar + listdotstar
9616" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9617
9618 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9619" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9620 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009621 let liststar = s:NetrwGlob(direntry.'/','*',1)
9622 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009623 let w:netrw_treedict[direntry]= liststar + listdotstar
9624" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9625
9626 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9627" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9628 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009629 let liststar = s:NetrwGlob(direntry.'/','*',1)
9630 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009631" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9632
9633 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009634" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009635 endif
9636 endfor
9637" call Dret("s:NetrwRefreshTreeDict")
9638endfun
9639
9640" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009641" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009642" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009643fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009644 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009645" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009646" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9647" 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>"))
9648" 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 +00009649
9650 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009651 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009652" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009654 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009655" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009656 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 +02009657" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009659 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009660" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009661 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009662 if exists("w:netrw_treetop")
9663 let s:netrw_treetop= w:netrw_treetop
9664 else
9665 let w:netrw_treetop= getcwd()
9666 let s:netrw_treetop= w:netrw_treetop
9667 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009668
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009670 " insure that we have a treedict, albeit empty
9671" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009672 let w:netrw_treedict= {}
9673 endif
9674
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009675 " update the dictionary for the current directory
9676" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009677" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009678 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009680" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009681 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009682
9683 " if past banner, record word
9684 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9685 let fname= expand("<cword>")
9686 else
9687 let fname= ""
9688 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009689" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9690" 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 +00009691
9692 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009693" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009694 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009695" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009696
9697 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9698 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009699" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009700 1d
9701 endwhile
9702
Bram Moolenaar13600302014-05-22 18:26:40 +02009703 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009704
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009705" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009706 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009707 endif
9708endfun
9709
9710" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009711" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009712" Normally, treetop is w:netrw_treetop, but a
9713" user of the function ( netrw#SetTreetop() )
9714" wipes that out prior to calling this function
9715fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009716" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9717 if line(".") < w:netrw_bannercnt + 2
9718 let treedir= a:treetop
9719 if treedir !~ '/$'
9720 let treedir= treedir.'/'
9721 endif
9722" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9723 return treedir
9724 endif
9725
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009726 let svpos = winsaveview()
9727" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009728 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009729" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009730 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009731" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9732 let curline= getline('.')
9733" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9734 if curline =~ '/$'
9735" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9736 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9737" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9738 elseif curline =~ '@\s\+-->'
9739" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9740 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9741 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9742" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009743 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009744" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009745 let treedir= ""
9746 endif
9747 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009748" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9749" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009750 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9751 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9752 let treedir= dirname.treedir
9753 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009754" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009755 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009756" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009757 if a:treetop =~ '/$'
9758 let treedir= a:treetop.treedir
9759 else
9760 let treedir= a:treetop.'/'.treedir
9761 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009762" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009763 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009764" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009765" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9766 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009767" call Dret("s:NetrwTreePath <".treedir.">")
9768 return treedir
9769endfun
9770
9771" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009772" s:NetrwWideListing: {{{2
9773fun! s:NetrwWideListing()
9774
9775 if w:netrw_liststyle == s:WIDELIST
9776" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9777 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009778 " cpf: characters per filename
9779 " fpl: filenames per line
9780 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009781 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009782 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009783" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009784 let b:netrw_cpf= 0
9785 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009786 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009787 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9788 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009789 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009790 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009791" call Dret("NetrwWideListing")
9792 return
9793 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009794 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009795 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009796" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009797
9798 " determine qty files per line (fpl)
9799 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9800 if w:netrw_fpl <= 0
9801 let w:netrw_fpl= 1
9802 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009803" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009804
9805 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009806 " fpc: files per column of wide listing
9807 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009808 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009809 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9810 let newcolstart = w:netrw_bannercnt + fpc
9811 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009812" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009813 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009814" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009815 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009816 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009817 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009818 while line("$") >= newcolstart
9819 if newcolend > line("$") | let newcolend= line("$") | endif
9820 let newcolqty= newcolend - newcolstart
9821 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009822 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009823 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009824 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009825 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009826 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009827 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009828 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009829 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009830 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009831 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009832" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009833 if @* != keepregstar | sil! let @* = keepregstar | endif
9834 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009835 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009836 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9837 NetrwKeepj call histdel("/",-1)
9838 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9839 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009840" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009841 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009842 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009843" 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 +00009844" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009845 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009846 else
9847 if hasmapto("w","n")
9848 sil! nunmap <buffer> w
9849 endif
9850 if hasmapto("b","n")
9851 sil! nunmap <buffer> b
9852 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009853 endif
9854
9855endfun
9856
9857" ---------------------------------------------------------------------
9858" s:PerformListing: {{{2
9859fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009860" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9861" 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 +02009862" 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>"))
9863 sil! NetrwKeepj %d _
9864" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009865
Bram Moolenaar15146672011-10-20 22:22:38 +02009866 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009867" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009868 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009869
Bram Moolenaar85850f32019-07-19 22:05:51 +02009870 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009871 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009872" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009873
9874" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009875" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009876" endif " Decho
9877
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009878" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009879 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9880 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009881" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9882 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009883 endif
9884
9885 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009886 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009887
9888 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009889 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009890" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009891 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009892 if exists("g:netrw_pchk")
9893 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9894 " failure detections.
9895 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009896 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009897 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9898 endif
9899 if exists("g:netrw_pchk")
9900 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9901 else
9902 let curdir= b:netrw_curdir
9903 endif
9904 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9905 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9906 else
9907 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009908 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009909 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009910 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009911 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009912" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009913 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009914 let w:netrw_bannercnt= 1
9915 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009916" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9917" 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 +00009918
Bram Moolenaar85850f32019-07-19 22:05:51 +02009919 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009920 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009921 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009922 let sortby= sortby." reversed"
9923 endif
9924
9925 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009926 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009927" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009928 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009929" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009930 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009931 NetrwKeepj put ='\" Sorted by '.sortby
9932 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009933 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9934 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009935" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009936 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009937 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009938 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9939 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009940 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009941" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009942" 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 +00009943 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009944
Bram Moolenaar85850f32019-07-19 22:05:51 +02009945 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009946 if g:netrw_banner
9947 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009949 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009950 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009951 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009952 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009953 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009954 endif
9955 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009956 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009957" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009958 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009959 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009960 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009961
9962 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009963 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009964" 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 +01009965 if g:netrw_list_hide != "" && g:netrw_hide
9966 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009967 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009968 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009969 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009970 endif
9971 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009972 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009973 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009974
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009975" 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 +01009976 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009977" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009978 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009979" 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 +01009980 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009981 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009982" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009983" 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 +00009984 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009985
9986 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009987 if g:netrw_banner
9988 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009989 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009990" 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 +01009991" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009992" 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 +01009993 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009994
Bram Moolenaar446cb832008-06-24 21:56:24 +00009995 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009997 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009998 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009999 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010000 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010001 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010002" 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 +010010003" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10004 return
10005 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010006 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010007
10008 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010009 if !exists("w:netrw_bannercnt")
10010 let w:netrw_bannercnt= 0
10011 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010012" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10013" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10014" 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 +010010015
Bram Moolenaar5c736222010-01-06 20:54:52 +010010016 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010017" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010018" 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 +000010019 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010020 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010021 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010022 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010023" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010024
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010025 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010026 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010027" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010028 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010029
Bram Moolenaar5c736222010-01-06 20:54:52 +010010030 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010031" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010032 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010033 " name: sort by name of file
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 else
10036 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010037 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010038 endif
10039 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010040
Bram Moolenaar446cb832008-06-24 21:56:24 +000010041 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010042" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010043 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10044 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010045
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010046 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010047 " exten: sort by extension
10048 " The histdel(...,-1) calls remove the last search from the search history
10049" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010050 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10051 NetrwKeepj call histdel("/",-1)
10052 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10053 NetrwKeepj call histdel("/",-1)
10054 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10055 NetrwKeepj call histdel("/",-1)
10056 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10057" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010058 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010059 " normal direction sorting
10060 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10061 else
10062 " reverse direction sorting
10063 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10064 endif
10065 endif
10066 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10067 NetrwKeepj call histdel("/",-1)
10068
Bram Moolenaar446cb832008-06-24 21:56:24 +000010069 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010070 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010071" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010072 if g:netrw_sort_direction =~# 'n'
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 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010076" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010077 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010078 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010079" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010080 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10081 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010082 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010083 endif
10084
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010085 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010086" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010087 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010088 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010089 call histdel("/",-1)
10090 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010091 endif
10092 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010093" 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 +000010094
10095 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010096" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10097" 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 +010010098 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099" 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 +010010100 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010101" 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 +000010102
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010103 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010104 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010105" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010106 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010107 endif
10108
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010109 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010110 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010111" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10112 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010113 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010114" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10115 else
10116" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10117" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10118" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10119" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010120 endif
10121
10122 " record previous current directory
10123 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010124" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010125
10126 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010127" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10128" 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 +010010129 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130" 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 +020010131 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010132" 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 +000010133
10134 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010135" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010136 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010137" 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 +010010138 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010139" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010140 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10141 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010142" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010143" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010144
Bram Moolenaar8d043172014-01-23 14:24:41 +010010145 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010146" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10147" 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 +010010148" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10149 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010150 unlet s:treecurpos
10151 endif
10152
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010153" 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>"))
10154" 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 +000010155" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10156endfun
10157
10158" ---------------------------------------------------------------------
10159" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010160fun! s:SetupNetrwStatusLine(statline)
10161" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10162
10163 if !exists("s:netrw_setup_statline")
10164 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010165" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010166
10167 if !exists("s:netrw_users_stl")
10168 let s:netrw_users_stl= &stl
10169 endif
10170 if !exists("s:netrw_users_ls")
10171 let s:netrw_users_ls= &laststatus
10172 endif
10173
10174 " set up User9 highlighting as needed
10175 let keepa= @a
10176 redir @a
10177 try
10178 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010179 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010180 if &bg == "dark"
10181 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10182 else
10183 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10184 endif
10185 endtry
10186 redir END
10187 let @a= keepa
10188 endif
10189
10190 " set up status line (may use User9 highlighting)
10191 " insure that windows have a statusline
10192 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010193 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010194 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010195" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010196 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010197
10198" call Dret("SetupNetrwStatusLine : stl=".&stl)
10199endfun
10200
Bram Moolenaar85850f32019-07-19 22:05:51 +020010201" =========================================
10202" Remote Directory Browsing Support: {{{1
10203" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010204
10205" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010206" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10207" This function assumes that a long listing will be received. Size, time,
10208" and reverse sorts will be requested of the server but not otherwise
10209" enforced here.
10210fun! s:NetrwRemoteFtpCmd(path,listcmd)
10211" 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 +010010212" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010213 " sanity check: {{{3
10214 if !exists("w:netrw_method")
10215 if exists("b:netrw_method")
10216 let w:netrw_method= b:netrw_method
10217 else
10218 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10219" call Dret("NetrwRemoteFtpCmd")
10220 return
10221 endif
10222 endif
10223
10224 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10225 let ffkeep= &ff
10226 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010227" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010228
10229 " clear off any older non-banner lines " {{{3
10230 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010231" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10232 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010233
10234 ".........................................
10235 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10236 " ftp + <.netrc>: Method #2
10237 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010238 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010239 endif
10240 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010241 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010242" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010243 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010244 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010245" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010246 if exists("g:netrw_port") && g:netrw_port != ""
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)." ".s:ShellEscape(g:netrw_port,1),'~'.expand("<slnum>"))
10248 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 +010010249 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010250" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10251 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 +010010252 endif
10253
10254 ".........................................
10255 elseif w:netrw_method == 3 " {{{3
10256 " ftp + machine,id,passwd,filename: Method #3
10257 setl ff=unix
10258 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010259 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010260 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010261 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010262 endif
10263
10264 " handle userid and password
10265 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010266" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010267 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10268 call NetUserPass("ftp:".host)
10269 endif
10270 if exists("g:netrw_uid") && g:netrw_uid != ""
10271 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010272 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010273 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010274 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010275 endif
10276 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010277 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010278 endif
10279 endif
10280
10281 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010282 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010283 endif
10284 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010285 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010286" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010287 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010288 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010289
10290 " perform ftp:
10291 " -i : turns off interactive prompting from ftp
10292 " -n unix : DON'T use <.netrc>, even though it exists
10293 " -n win32: quit being obnoxious about password
10294 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010295" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010296 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010297" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010298" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10299" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010300 endif
10301
10302 ".........................................
10303 elseif w:netrw_method == 9 " {{{3
10304 " sftp username@machine: Method #9
10305 " s:netrw_sftp_cmd
10306 setl ff=unix
10307
10308 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010309 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010310" call Dret("NetrwRemoteFtpCmd")
10311 return
10312
10313 ".........................................
10314 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010315 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010316 endif
10317
10318 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010319 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010320 sil! NetrwKeepj %s/\r$//e
10321 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010322 endif
10323 if a:listcmd == "dir"
10324 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010325 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10326 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10327 NetrwKeepj call histdel("/",-1)
10328 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010329 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 +010010330 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10331 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010332 endif
10333 endif
10334
10335 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10336 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010337 exe 'NetrwKeepj '.w:netrw_bannercnt
10338 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010339 endif
10340 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010341 exe 'NetrwKeepj '.w:netrw_bannercnt
10342 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010343 endif
10344
10345 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010346 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010347" call Dret("NetrwRemoteFtpCmd")
10348endfun
10349
10350" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010351" s:NetrwRemoteListing: {{{2
10352fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010353" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010354
Bram Moolenaara6878372014-03-22 21:02:50 +010010355 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10356 let w:netrw_bannercnt= s:bannercnt
10357 endif
10358 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010359 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010360 endif
10361
Bram Moolenaar446cb832008-06-24 21:56:24 +000010362 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010363
Bram Moolenaar446cb832008-06-24 21:56:24 +000010364 " sanity check:
10365 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010366" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010367 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010368" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010369 if !exists("g:netrw_quiet")
10370 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10371 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010372 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010373" call Dret("s:NetrwRemoteListing -1")
10374 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010375 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010376
Bram Moolenaar8d043172014-01-23 14:24:41 +010010377 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010378" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010379 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010380 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010381 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 +000010382 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010383 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 +000010384 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010385 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010386
Bram Moolenaar85850f32019-07-19 22:05:51 +020010387 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010388" call Dret("s:NetrwRemoteListing -1")
10389 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010390 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010391" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010392
Bram Moolenaar446cb832008-06-24 21:56:24 +000010393 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010394" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010395 let w:netrw_method= b:netrw_method
10396 endif
10397
Bram Moolenaar13600302014-05-22 18:26:40 +020010398 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010399 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010400" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010401 let s:method = "ftp"
10402 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010403 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010404 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010405 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010406 let listcmd= g:netrw_ftp_sizelist_cmd
10407 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010408" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010409 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010410" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010411
Bram Moolenaara6878372014-03-22 21:02:50 +010010412 " report on missing file or directory messages
10413 if search('[Nn]o such file or directory\|Failed to change directory')
10414 let mesg= getline(".")
10415 if exists("w:netrw_bannercnt")
10416 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010417 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010418 setl noma
10419 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010420 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010421 call netrw#ErrorMsg(s:WARNING,mesg,96)
10422" call Dret("s:NetrwRemoteListing : -1")
10423 return -1
10424 endif
10425
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010426 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 +000010427 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010428" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010429 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010430
10431 " cleanup
10432 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010433 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10434 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010435 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010436 sil! NetrwKeepj %s/\r$//e
10437 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010438
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010439 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010440 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010441 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010442 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010443" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010444 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010445" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010446 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010448 exe "sil! NetrwKeepj ".line1
10449 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010450
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010451" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010452 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010453" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010454 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10455 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010456 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010457" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010458 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10459 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10460 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10461 NetrwKeepj call histdel("/",-1)
10462 NetrwKeepj call histdel("/",-1)
10463 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010464 endif
10465 endif
10466
Bram Moolenaar13600302014-05-22 18:26:40 +020010467 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010468 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010469" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010471" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010472 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010473" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10474 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010475 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010476 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10477 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10478 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10479 NetrwKeepj call histdel("/",-1)
10480 NetrwKeepj call histdel("/",-1)
10481 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010482 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010483 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10484 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485 endif
10486 else
10487 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010488" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010489 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010490 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010491" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10492 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10493" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010494 endif
10495 endif
10496
10497 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010498 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010499" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010500 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10501 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010502 endif
10503 endif
10504
10505 if w:netrw_liststyle == s:LONGLIST
10506 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010507" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010508
10509 if s:method == "ftp"
10510 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010511 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010512 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010513 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010515 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010516 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010517 sil! NetrwKeepj 1
10518 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010519 let line2= line(".")
10520 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010521 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010522 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 endif
10524 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010525 exe "sil! NetrwKeepj ".line1
10526 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010527 endif
10528
10529 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010530" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010531 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 +000010532 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010533" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010534 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010535 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010536 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10537 NetrwKeepj call histdel("/",-1)
10538 NetrwKeepj call histdel("/",-1)
10539 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010540 endif
10541 endif
10542
10543" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010544" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010545" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010546
10547" call Dret("s:NetrwRemoteListing 0")
10548 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010549endfun
10550
Bram Moolenaar446cb832008-06-24 21:56:24 +000010551" ---------------------------------------------------------------------
10552" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10553fun! s:NetrwRemoteRm(usrhost,path) range
10554" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010555" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010556 let svpos= winsaveview()
10557" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010558
10559 let all= 0
10560 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10561 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010562" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010563 for fname in s:netrwmarkfilelist_{bufnr("%")}
10564 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010565 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010566 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010567 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010568 let all= 1
10569 endif
10570 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010571 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010572
10573 else
10574 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010575" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010576
10577 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010578 let keepsol = &l:sol
10579 setl nosol
10580 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581
10582 " remove multiple files and directories
10583 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010584 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010585 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010586 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010587 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010588 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589 let all= 1
10590 endif
10591 let ctr= ctr + 1
10592 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010593 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010594 endif
10595
10596 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010597" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010598 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010599" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10600 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601
10602" call Dret("s:NetrwRemoteRm")
10603endfun
10604
10605" ---------------------------------------------------------------------
10606" s:NetrwRemoteRmFile: {{{2
10607fun! s:NetrwRemoteRmFile(path,rmfile,all)
10608" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10609
10610 let all= a:all
10611 let ok = ""
10612
10613 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10614 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010615" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010616 if !all
10617 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010618" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010619 call inputsave()
10620 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10621 call inputrestore()
10622 echohl NONE
10623 if ok == ""
10624 let ok="no"
10625 endif
10626 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010627 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010628 let all= 1
10629 endif
10630 endif
10631
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010632 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010633" 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 +000010634 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010635" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010636 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010637 if path =~ '^\a\{3,}://'
10638 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010639 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010640 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010641 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10642 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010643" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010644 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010645" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010646 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010647 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010648 let ok="q"
10649 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010650 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010651" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10652" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10653" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010654 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010655 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010656 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010657 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010658 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010659" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010661 if v:shell_error != 0
10662 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010663 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 +010010664 else
10665 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10666 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010667 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010669 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010670" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010671 endif
10672 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010673 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010674" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 endif
10676
10677 else
10678 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010679" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010680 if !all
10681 call inputsave()
10682 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10683 call inputrestore()
10684 if ok == ""
10685 let ok="no"
10686 endif
10687 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010688 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010689 let all= 1
10690 endif
10691 endif
10692
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010693 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010694 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010695 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010696 else
10697 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010698 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10699" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010700 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010701" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010702
10703 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010704" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10705 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10706" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010707 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010708" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010709
10710 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010711 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010712 endif
10713 endif
10714 endif
10715
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010716 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010717" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010718 endif
10719 endif
10720
10721" call Dret("s:NetrwRemoteRmFile ".ok)
10722 return ok
10723endfun
10724
10725" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010726" s:NetrwRemoteRename: rename a remote file or directory {{{2
10727fun! s:NetrwRemoteRename(usrhost,path) range
10728" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10729
10730 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010731 let svpos = winsaveview()
10732" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010733 let ctr = a:firstline
10734 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10735
10736 " rename files given by the markfilelist
10737 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10738 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010739" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010740 if exists("subfrom")
10741 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010742" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010743 else
10744 call inputsave()
10745 let newname= input("Moving ".oldname." to : ",oldname)
10746 call inputrestore()
10747 if newname =~ '^s/'
10748 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10749 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10750 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010751" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010752 endif
10753 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010754
Bram Moolenaar446cb832008-06-24 21:56:24 +000010755 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010756 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010757 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010758 let oldname= s:ShellEscape(a:path.oldname)
10759 let newname= s:ShellEscape(a:path.newname)
10760" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010761 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010762 endif
10763
10764 endfor
10765 call s:NetrwUnMarkFile(1)
10766
10767 else
10768
10769 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010770 let keepsol= &l:sol
10771 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010772 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010773 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010774
10775 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010776" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010777
10778 call inputsave()
10779 let newname= input("Moving ".oldname." to : ",oldname)
10780 call inputrestore()
10781
10782 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10783 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10784 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010785 let oldname= s:ShellEscape(a:path.oldname)
10786 let newname= s:ShellEscape(a:path.newname)
10787" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010788 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010789 endif
10790
10791 let ctr= ctr + 1
10792 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010793 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010794 endif
10795
10796 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010797 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010798" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10799 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010800
10801" call Dret("NetrwRemoteRename")
10802endfun
10803
Bram Moolenaar85850f32019-07-19 22:05:51 +020010804" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010805" Local Directory Browsing Support: {{{1
10806" ==========================================
10807
10808" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010809" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010810" Should accept: file://localhost/etc/fstab
10811" file:///etc/fstab
10812" file:///c:/WINDOWS/clock.avi
10813" file:///c|/WINDOWS/clock.avi
10814" file://localhost/c:/WINDOWS/clock.avi
10815" file://localhost/c|/WINDOWS/clock.avi
10816" file://c:/foo.txt
10817" file:///c:/foo.txt
10818" 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 +020010819fun! netrw#FileUrlEdit(fname)
10820" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010821 let fname = a:fname
10822 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010823" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010824 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010825" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010826 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010827 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010829" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010830 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010831" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010832 endif
10833 endif
10834 let fname2396 = netrw#RFC2396(fname)
10835 let fname2396e= fnameescape(fname2396)
10836 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010837 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010838" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010839 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010840" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010841 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10842 endif
10843 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010844
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010845" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10846" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010847 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010848 exe 'NetrwKeepj keepalt edit '.plainfname
10849 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10850
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010851" 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 +020010852" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010853 exe "sil doau BufReadPost ".fname2396e
10854endfun
10855
10856" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010857" netrw#LocalBrowseCheck: {{{2
10858fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010859 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010860 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10861 "
10862 " unfortunate interaction -- split window debugging can't be used here, must use
10863 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10864 " another call to LocalBrowseCheck() when attempts to write
10865 " to the DBG buffer are made.
10866 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010867 " The &ft == "netrw" test was installed because the BufEnter event
10868 " would hit when re-entering netrw windows, creating unexpected
10869 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010870" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010871" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010872" 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 +010010873 " getting E930: Cannot use :redir inside execute
10874"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010875" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10876" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010877
Bram Moolenaar97d62492012-11-15 21:28:22 +010010878 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010879 if isdirectory(s:NetrwFile(a:dirname))
10880" 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 +010010881
Bram Moolenaar97d62492012-11-15 21:28:22 +010010882 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010883" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10884" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010885 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010886
Bram Moolenaar446cb832008-06-24 21:56:24 +000010887 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010888" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010889 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010890
Bram Moolenaar5c736222010-01-06 20:54:52 +010010891 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010892" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010893 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010894 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010895 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010896" 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 +010010897" call Dret("netrw#LocalBrowseCheck")
10898 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010899 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010900
Bram Moolenaar85850f32019-07-19 22:05:51 +020010901 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010902 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10903 " AND IF the listing style is not a tree listing
10904 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010905" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010906 let ibuf = 1
10907 let buflast = bufnr("$")
10908 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10910 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010911 endif
10912 let ibuf= ibuf + 1
10913 endwhile
10914 endif
10915 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010916" 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>"))
10917" 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 +000010918 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010919" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010920endfun
10921
10922" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010923" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010924" performed any shell command. The idea is to cause all local-browsing
10925" buffers to be refreshed after a user has executed some shell command,
10926" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010927fun! s:LocalBrowseRefresh()
10928" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010929" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10930" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010931
Bram Moolenaar446cb832008-06-24 21:56:24 +000010932 " determine which buffers currently reside in a tab
10933 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010934" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010935 return
10936 endif
10937 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010938" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010939 return
10940 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010941 if !empty(getcmdwintype())
10942 " cannot move away from cmdline window, see :h E11
10943 return
10944 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010945 if exists("s:netrw_events") && s:netrw_events == 1
10946 " s:LocalFastBrowser gets called (indirectly) from a
10947 let s:netrw_events= 2
10948" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10949 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010950 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010951 let itab = 1
10952 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010953 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010954 while itab <= tabpagenr("$")
10955 let buftablist = buftablist + tabpagebuflist()
10956 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010957 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010958 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010959" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10960" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010961 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10962 " | refresh any netrw window
10963 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010964 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 let ibl = 0
10966 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010967" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010968 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10969 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010970 " (ibuf not shown in a current window AND
10971 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010972" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10973 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010974 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010975" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010976 continue
10977 elseif index(tabpagebuflist(),ibuf) != -1
10978 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010979" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010980 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010981 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010982 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10983 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10984 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10985 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010986" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010987 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10988 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10989 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010990 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010991 endif
10992 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010993" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010994 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010995" call Decho("restore window: win_gotoid(".curwinid.")")
10996 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010997 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010998
Bram Moolenaara6878372014-03-22 21:02:50 +010010999" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011000endfun
11001
11002" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011003" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11004"
11005" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011006" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011007" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11008" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011009" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011010"
11011" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11012" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011013" (re-using a buffer may not be as accurate)
11014"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011015" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011016" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11017" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11018" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11019" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011020fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011021" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11022" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11023" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11024" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011025
11026 " initialize browselist, a list of buffer numbers that the local browser has used
11027 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011028" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011029 let s:netrw_browselist= []
11030 endif
11031
11032 " append current buffer to fastbrowse list
11033 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011034" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011035 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011036" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011037 endif
11038
11039 " enable autocmd events to handle refreshing/removing local browser buffers
11040 " If local browse buffer is currently showing: refresh it
11041 " If local browse buffer is currently hidden : wipe it
11042 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11043 " =1 : medium speed, re-use directory listing for remote only
11044 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011045 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11046 let s:netrw_events= 1
11047 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011048 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011049 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011050" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011051 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011052 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011053" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011054 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011055 endif
11056 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011057
11058 " user must have changed fastbrowse to its fast setting, so remove
11059 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011060 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011061" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011062 unlet s:netrw_events
11063 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011064 au!
11065 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011066 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011067 endif
11068
Bram Moolenaar85850f32019-07-19 22:05:51 +020011069" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011070endfun
11071
11072" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011073" s:LocalListing: does the job of "ls" for local directories {{{2
11074fun! s:LocalListing()
11075" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011076" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11077" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11078" 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 +010011079
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011080" 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
11081" 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
11082" 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 +010011083
11084 " get the list of files contained in the current directory
11085 let dirname = b:netrw_curdir
11086 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011087 let filelist = s:NetrwGlob(dirname,"*",0)
11088 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011089" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011090
Nir Lichtman1e34b952024-05-08 19:19:34 +020011091 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011092" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011093 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11094 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011095" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011096 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011097" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011098 endif
11099
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011100" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011101" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011102" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011103
11104 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11105 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11106 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011107" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11108" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011109 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011110" 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 +010011111
11112 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011113" call Decho(" ",'~'.expand("<slnum>"))
11114" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011115
11116 if getftype(filename) == "link"
11117 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011118" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011119 let pfile= filename."@"
11120
11121 elseif getftype(filename) == "socket"
11122 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011123" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011124 let pfile= filename."="
11125
11126 elseif getftype(filename) == "fifo"
11127 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011128" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011129 let pfile= filename."|"
11130
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011131 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011132 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011133" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011134 let pfile= filename."/"
11135
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011136 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011137 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011138 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11139 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011141 let pfile= filename."*"
11142 else
11143 " normal file
11144 let pfile= filename
11145 endif
11146 elseif executable(filename)
11147 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011148" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011149 let pfile= filename."*"
11150 else
11151 " normal file
11152 let pfile= filename
11153 endif
11154
11155 else
11156 " normal file
11157 let pfile= filename
11158 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011159" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011160
11161 if pfile =~ '//$'
11162 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011163" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011164 endif
11165 let pfile= strpart(pfile,dirnamelen)
11166 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011167" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11168" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011169
11170 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011171 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11172 let sz = getfsize(filename)
11173 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11174 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011175
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011176 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011177 let sz= s:NetrwHumanReadable(sz)
11178 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011179 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011180 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011181" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011182 endif
11183
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011184 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011185 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011186 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011187" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011188" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011189 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011190 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011191" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011192 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011193 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011194
11195 elseif g:netrw_sort_by =~ "^s"
11196 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011197" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011198" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011199 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011200 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011201" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011202 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011203 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011204
11205 else
11206 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011207" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011208" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011209 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011210 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011211" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011212 endfor
11213
11214 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011215 sil! NetrwKeepj g/^$/d
11216 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011217 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011218" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011219 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11220
11221" call Dret("s:LocalListing")
11222endfun
11223
11224" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011225" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11226fun! s:NetrwLocalExecute(cmd)
11227" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11228 let ykeep= @@
11229 " sanity check
11230 if !executable(a:cmd)
11231 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11232 let @@= ykeep
11233" call Dret("s:NetrwLocalExecute")
11234 return
11235 endif
11236
11237 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011238" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011239 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011240" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011241
11242 " strip any ansi escape sequences off
11243 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11244
11245 " show user the result(s)
11246 echomsg result
11247 let @@= ykeep
11248
11249" call Dret("s:NetrwLocalExecute")
11250endfun
11251
11252" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011253" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011254fun! s:NetrwLocalRename(path) range
11255" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11256
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011257 if !exists("w:netrw_bannercnt")
11258 let w:netrw_bannercnt= b:netrw_bannercnt
11259 endif
11260
Bram Moolenaar97d62492012-11-15 21:28:22 +010011261 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011262 let ykeep = @@
11263 let ctr = a:firstline
11264 let svpos = winsaveview()
11265 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011266" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011267
11268 " rename files given by the markfilelist
11269 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11270 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011271" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011272 if exists("subfrom")
11273 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011274" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011275 else
11276 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011277 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011278 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011279 if newname =~ ''
11280 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11281 let newname = substitute(newname,'^.*','','')
11282 elseif newname =~ ''
11283 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11284 let newname = substitute(newname,'[^/]*','','')
11285 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011286 if newname =~ '^s/'
11287 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11288 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011289" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011290 let newname = substitute(oldname,subfrom,subto,'')
11291 endif
11292 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011293 if !all && filereadable(newname)
11294 call inputsave()
11295 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11296 call inputrestore()
11297 if response == "all"
11298 let all= 1
11299 elseif response != "y" && response != "yes"
11300 " refresh the directory
11301" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11302 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11303" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11304 NetrwKeepj call winrestview(svpos)
11305 let @@= ykeep
11306" call Dret("NetrwLocalRename")
11307 return
11308 endif
11309 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011310 call rename(oldname,newname)
11311 endfor
11312 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011313
Bram Moolenaar97d62492012-11-15 21:28:22 +010011314 else
11315
11316 " attempt to rename files/directories
11317 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011318 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011319
11320 " sanity checks
11321 if line(".") < w:netrw_bannercnt
11322 let ctr= ctr + 1
11323 continue
11324 endif
11325 let curword= s:NetrwGetWord()
11326 if curword == "./" || curword == "../"
11327 let ctr= ctr + 1
11328 continue
11329 endif
11330
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011331 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011332 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011333" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011334
11335 call inputsave()
11336 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11337 call inputrestore()
11338
11339 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011340" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011341
11342 let ctr= ctr + 1
11343 endwhile
11344 endif
11345
11346 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011347" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011348 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011349" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11350 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011351 let @@= ykeep
11352
11353" call Dret("NetrwLocalRename")
11354endfun
11355
11356" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011357" s:NetrwLocalRm: {{{2
11358fun! s:NetrwLocalRm(path) range
11359" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011360" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011361
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011362 if !exists("w:netrw_bannercnt")
11363 let w:netrw_bannercnt= b:netrw_bannercnt
11364 endif
11365
Bram Moolenaar446cb832008-06-24 21:56:24 +000011366 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011367 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011368 let ret = 0
11369 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011370 let svpos = winsaveview()
11371" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011372
11373 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11374 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011375" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011376 for fname in s:netrwmarkfilelist_{bufnr("%")}
11377 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011378 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011379 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011380 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011381 let all= 1
11382 endif
11383 endfor
11384 call s:NetrwUnMarkFile(1)
11385
11386 else
11387 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011388" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011389
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011390 let keepsol= &l:sol
11391 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011392 let ctr = a:firstline
11393 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011394 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011395
11396 " sanity checks
11397 if line(".") < w:netrw_bannercnt
11398 let ctr= ctr + 1
11399 continue
11400 endif
11401 let curword= s:NetrwGetWord()
11402 if curword == "./" || curword == "../"
11403 let ctr= ctr + 1
11404 continue
11405 endif
11406 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011407 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011408 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011409 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011410 let all= 1
11411 endif
11412 let ctr= ctr + 1
11413 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011414 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011415 endif
11416
11417 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011418" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011419 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011420 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011421" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11422 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011423 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011424 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011425
11426" call Dret("s:NetrwLocalRm")
11427endfun
11428
11429" ---------------------------------------------------------------------
11430" s:NetrwLocalRmFile: remove file fname given the path {{{2
11431" Give confirmation prompt unless all==1
11432fun! s:NetrwLocalRmFile(path,fname,all)
11433" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011434
Bram Moolenaar446cb832008-06-24 21:56:24 +000011435 let all= a:all
11436 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011437 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011438 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11439" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011440
11441 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11442 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011443" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011444 if !all
11445 echohl Statement
11446 call inputsave()
11447 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11448 call inputrestore()
11449 echohl NONE
11450 if ok == ""
11451 let ok="no"
11452 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011453" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011454 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011455" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011456 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011457 let all= 1
11458 endif
11459 endif
11460
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011461 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011462 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011463" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011464 endif
11465
11466 else
11467 " attempt to remove directory
11468 if !all
11469 echohl Statement
11470 call inputsave()
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011471 let ok= input("Confirm *recursive* deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011472 call inputrestore()
11473 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11474 if ok == ""
11475 let ok="no"
11476 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011477 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011478 let all= 1
11479 endif
11480 endif
11481 let rmfile= substitute(rmfile,'[\/]$','','e')
11482
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011483 if all || ok =~# 'y\%[es]' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011484 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011485 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011486 endif
11487 endif
11488 endif
11489
11490" call Dret("s:NetrwLocalRmFile ".ok)
11491 return ok
11492endfun
11493
Bram Moolenaar85850f32019-07-19 22:05:51 +020011494" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011495" Support Functions: {{{1
11496
Bram Moolenaar488c6512005-08-11 20:09:58 +000011497" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011498" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11499" 0: marked file list of current buffer
11500" 1: marked file target
11501fun! netrw#Access(ilist)
11502 if a:ilist == 0
11503 if exists("s:netrwmarkfilelist_".bufnr('%'))
11504 return s:netrwmarkfilelist_{bufnr('%')}
11505 else
11506 return "no-list-buf#".bufnr('%')
11507 endif
11508 elseif a:ilist == 1
11509 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011510 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011511endfun
11512
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011513" ---------------------------------------------------------------------
11514" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11515fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011516 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011517endfun
11518
Bram Moolenaara6878372014-03-22 21:02:50 +010011519" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011520" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11521" I expect this function to be used in
11522" :PChkAssert netrw#Expose("netrwmarkfilelist")
11523" for example.
11524fun! netrw#Expose(varname)
11525" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011526 if exists("s:".a:varname)
11527 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011528" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011529 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011530" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011531 if type(retval) == 3
11532 let retval = copy(retval)
11533 let i = 0
11534 while i < len(retval)
11535 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11536 let i = i + 1
11537 endwhile
11538 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011539" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011540 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011541 else
11542" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011543 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011544 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011545" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011546 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011547 endif
11548
11549" call Dret("netrw#Expose ".string(retval))
11550 return retval
11551endfun
11552
11553" ---------------------------------------------------------------------
11554" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11555fun! netrw#Modify(varname,newvalue)
11556" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11557 exe "let s:".a:varname."= ".string(a:newvalue)
11558" call Dret("netrw#Modify")
11559endfun
11560
11561" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011562" netrw#RFC2396: converts %xx into characters {{{2
11563fun! netrw#RFC2396(fname)
11564" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011565 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011566" call Dret("netrw#RFC2396 ".fname)
11567 return fname
11568endfun
11569
11570" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011571" netrw#UserMaps: supports user-specified maps {{{2
11572" see :help function()
11573"
11574" g:Netrw_UserMaps is a List with members such as:
11575" [[keymap sequence, function reference],...]
11576"
11577" The referenced function may return a string,
11578" refresh : refresh the display
11579" -other- : this string will be executed
11580" or it may return a List of strings.
11581"
11582" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011583" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011584" Related functions:
11585" netrw#Expose(varname) -- see s:varname variables
11586" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11587" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11588fun! netrw#UserMaps(islocal)
11589" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11590" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11591
11592 " set up usermaplist
11593 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11594" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11595 for umap in g:Netrw_UserMaps
11596" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11597" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11598 " if umap[0] is a string and umap[1] is a string holding a function name
11599 if type(umap[0]) == 1 && type(umap[1]) == 1
11600" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11601 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11602 else
11603 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11604 endif
11605 endfor
11606 endif
11607" call Dret("netrw#UserMaps")
11608endfun
11609
11610" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011611" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11612fun! netrw#WinPath(path)
11613" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011614 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011615 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011616 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011617 " remove trailing slash (Win95)
11618 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11619 " remove escaped spaces
11620 let path = substitute(path, '\ ', ' ', 'g')
11621 " convert slashes to backslashes
11622 let path = substitute(path, '/', '\', 'g')
11623 else
11624 let path= a:path
11625 endif
11626" call Dret("netrw#WinPath <".path.">")
11627 return path
11628endfun
11629
11630" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011631" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11632" cb : bl2mf=0 add marked files to buffer list
11633" cB : bl2mf=1 use bufferlist to mark files
11634" (mnemonic: cb = copy (marked files) to buffer list)
11635fun! s:NetrwBadd(islocal,bl2mf)
11636" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11637 if a:bl2mf
11638 " cB: add buffer list to marked files
11639 redir => bufl
11640 ls
11641 redir END
11642 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11643 for fname in bufl
11644 call s:NetrwMarkFile(a:islocal,fname)
11645 endfor
11646 else
11647 " cb: add marked files to buffer list
11648 for fname in s:netrwmarkfilelist_{bufnr("%")}
11649" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11650 exe "badd ".fnameescape(fname)
11651 endfor
11652 let curbufnr = bufnr("%")
11653 let curdir = s:NetrwGetCurdir(a:islocal)
11654 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11655 endif
11656" call Dret("s:NetrwBadd")
11657endfun
11658
11659" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011660" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11661fun! s:ComposePath(base,subdir)
11662" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11663
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011664 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011665" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011666 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011667 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011668 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011669 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011670 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011671 endif
11672
Bram Moolenaar85850f32019-07-19 22:05:51 +020011673 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011674 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011675" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011676 let ret= a:subdir
11677
Nir Lichtman1e34b952024-05-08 19:19:34 +020011678 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011679" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011680 if a:base =~ '[/\\]$'
11681 let ret= a:base.a:subdir
11682 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011683 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011684 endif
11685
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011686 elseif a:base =~ '^\a\{3,}://'
11687" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011688 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11689 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11690 if a:subdir == '../'
11691 if curpath =~ '[^/]/[^/]\+/$'
11692 let curpath= substitute(curpath,'[^/]\+/$','','')
11693 else
11694 let curpath=""
11695 endif
11696 let ret= urlbase.curpath
11697 else
11698 let ret= urlbase.curpath.a:subdir
11699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011700" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11701" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11702" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011703
11704 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011705" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011706 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11707 if a:base =~ '^//'
11708 " keeping initial '//' for the benefit of network share listing support
11709 let ret= '/'.ret
11710 endif
11711 let ret= simplify(ret)
11712 endif
11713
11714" call Dret("s:ComposePath ".ret)
11715 return ret
11716endfun
11717
11718" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011719" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11720" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11721fun! s:DeleteBookmark(fname)
11722" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11723 call s:MergeBookmarks()
11724
11725 if exists("g:netrw_bookmarklist")
11726 let indx= index(g:netrw_bookmarklist,a:fname)
11727 if indx == -1
11728 let indx= 0
11729 while indx < len(g:netrw_bookmarklist)
11730 if g:netrw_bookmarklist[indx] =~ a:fname
11731 call remove(g:netrw_bookmarklist,indx)
11732 let indx= indx - 1
11733 endif
11734 let indx= indx + 1
11735 endwhile
11736 else
11737 " remove exact match
11738 call remove(g:netrw_bookmarklist,indx)
11739 endif
11740 endif
11741
11742" call Dret("s:DeleteBookmark")
11743endfun
11744
11745" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011746" s:FileReadable: o/s independent filereadable {{{2
11747fun! s:FileReadable(fname)
11748" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11749
11750 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011751 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011752 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011753 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011754 endif
11755
11756" call Dret("s:FileReadable ".ret)
11757 return ret
11758endfun
11759
11760" ---------------------------------------------------------------------
11761" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11762" Places correct suffix on end of temporary filename,
11763" using the suffix provided with fname
11764fun! s:GetTempfile(fname)
11765" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11766
11767 if !exists("b:netrw_tmpfile")
11768 " get a brand new temporary filename
11769 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011770" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011771
Bram Moolenaarc236c162008-07-13 17:41:49 +000011772 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011773" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011774
Bram Moolenaar9964e462007-05-05 17:54:07 +000011775 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011776 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11777" 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 +010011778 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011779" call Dret("s:GetTempfile getcwd<".getcwd().">")
11780 return ""
11781 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011782
Bram Moolenaar9964e462007-05-05 17:54:07 +000011783 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011784 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011785" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011786
Bram Moolenaar9964e462007-05-05 17:54:07 +000011787 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011788 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011789 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011790 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011791 if !exists("+shellslash") || !&ssl
11792 let tmpfile = substitute(tmpfile,'/','\','g')
11793 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011794 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011795 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011796 endif
11797 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011798" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011799 else
11800 " re-use temporary filename
11801 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011802" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011803 endif
11804
11805 " use fname's suffix for the temporary file
11806 if a:fname != ""
11807 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011808" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011809 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011810 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011811 elseif a:fname =~ '.txz$'
11812 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011813 else
11814 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011816" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011817 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011818" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011819 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011820" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011821 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11822 endif
11823 endif
11824
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011825" 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 +000011826" call Dret("s:GetTempfile <".tmpfile.">")
11827 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011828endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011829
11830" ---------------------------------------------------------------------
11831" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011832" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011833fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011834" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011835 if s:user == ""
11836 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11837 else
11838 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11839 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011840 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011841 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011842 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011843 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011844 else
11845 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11846 endif
11847" call Dret("s:MakeSshCmd <".sshcmd.">")
11848 return sshcmd
11849endfun
11850
11851" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011852" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11853fun! s:MakeBookmark(fname)
11854" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11855
11856 if !exists("g:netrw_bookmarklist")
11857 let g:netrw_bookmarklist= []
11858 endif
11859
11860 if index(g:netrw_bookmarklist,a:fname) == -1
11861 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011862 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011863 call add(g:netrw_bookmarklist,a:fname.'/')
11864 elseif a:fname !~ '/'
11865 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11866 else
11867 call add(g:netrw_bookmarklist,a:fname)
11868 endif
11869 call sort(g:netrw_bookmarklist)
11870 endif
11871
11872" call Dret("s:MakeBookmark")
11873endfun
11874
11875" ---------------------------------------------------------------------
11876" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11877fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011878" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011879 " get bookmarks from .netrwbook file
11880 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011881 if filereadable(s:NetrwFile(savefile))
11882" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011883 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011884" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011885 NetrwKeepj call delete(savefile)
11886 endif
11887" call Dret("s:MergeBookmarks")
11888endfun
11889
11890" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011891" s:NetrwBMShow: {{{2
11892fun! s:NetrwBMShow()
11893" call Dfunc("s:NetrwBMShow()")
11894 redir => bmshowraw
11895 menu
11896 redir END
11897 let bmshowlist = split(bmshowraw,'\n')
11898 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011899 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011900 if bmshowfuncs != []
11901 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011902 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011903 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011904 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011905 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011906 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011907" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11908endfun
11909
11910" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011911" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011912fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011913 if !exists("w:netrw_liststyle")
11914 let w:netrw_liststyle= g:netrw_liststyle
11915 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011916" 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 +020011917
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011918" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11919
Bram Moolenaaradc21822011-04-01 18:03:16 +020011920 if &ft != "netrw"
11921 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11922 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011923" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011924
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011925 elseif g:netrw_cursor == 8
11926 if w:netrw_liststyle == s:WIDELIST
11927 setl cursorline
11928 setl cursorcolumn
11929 else
11930 setl cursorline
11931 endif
11932 elseif g:netrw_cursor == 7
11933 setl cursorline
11934 elseif g:netrw_cursor == 6
11935 if w:netrw_liststyle == s:WIDELIST
11936 setl cursorline
11937 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011938 elseif g:netrw_cursor == 4
11939 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011940" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011941 setl cursorline
11942 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011943
11944 elseif g:netrw_cursor == 3
11945 " thin-long-tree: cursorline, user's cursorcolumn
11946 " wide : cursorline, cursorcolumn
11947 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011948" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011949 setl cursorline
11950 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011951 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011952" 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 +020011953 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011954 endif
11955
11956 elseif g:netrw_cursor == 2
11957 " thin-long-tree: cursorline, user's cursorcolumn
11958 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011959" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011960 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011961
11962 elseif g:netrw_cursor == 1
11963 " thin-long-tree: user's cursorline, user's cursorcolumn
11964 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011965 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011966" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011967 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011968 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011969" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011970 endif
11971
11972 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011973 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011974" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011975 let &l:cursorline = s:netrw_usercul
11976 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011977 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011978
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011979" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011980" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011981endfun
11982
11983" ---------------------------------------------------------------------
11984" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11985fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011986" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011987 if exists("s:netrw_usercul")
11988 let &l:cursorline = s:netrw_usercul
11989 endif
11990 if exists("s:netrw_usercuc")
11991 let &l:cursorcolumn = s:netrw_usercuc
11992 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011993" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011994" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11995endfun
11996
11997" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011998" s:NetrwDelete: Deletes a file. {{{2
11999" Uses Steve Hall's idea to insure that Windows paths stay
12000" acceptable. No effect on Unix paths.
12001" Examples of use: let result= s:NetrwDelete(path)
12002fun! s:NetrwDelete(path)
12003" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12004
Bram Moolenaar5c736222010-01-06 20:54:52 +010012005 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012006 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012007 if exists("+shellslash")
12008 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012009 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012010 let result = delete(path)
12011 let &shellslash = sskeep
12012 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012013" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012014 let result= delete(path)
12015 endif
12016 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012017" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012018 let result= delete(path)
12019 endif
12020 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012021 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012022 endif
12023
12024" call Dret("s:NetrwDelete ".result)
12025 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012026endfun
12027
12028" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012029" s:NetrwBufRemover: removes a buffer that: {{{2s
12030" has buffer-id > 1
12031" is unlisted
12032" is unnamed
12033" does not appear in any window
12034fun! s:NetrwBufRemover(bufid)
12035" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12036" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12037" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12038" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12039" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12040
yasuda4dbb2662023-10-04 20:50:35 +020012041 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012042" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012043 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012044 endif
12045
12046" call Dret("s:NetrwBufRemover")
12047endfun
12048
12049" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012050" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012051fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012052" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012053" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012054
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012055 " Clean out the last buffer:
12056 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12057 " If so, delete it.
12058 call s:NetrwBufRemover(bufnr("$"))
12059
Bram Moolenaar446cb832008-06-24 21:56:24 +000012060 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012061" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012062 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12063 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12064 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12065 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12066 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12067 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12068 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12069 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12070 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12071 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12072 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12073 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12074 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12075 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12076 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12077 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12078
Bram Moolenaar85850f32019-07-19 22:05:51 +020012079 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012080" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012081 " when tree listing uses file TreeListing... a new buffer is made.
12082 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012083 " COMBAK: this causes a problem, see P43
12084" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012085 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012086 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012087 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012088" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012089 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012090
Bram Moolenaar446cb832008-06-24 21:56:24 +000012091 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012092" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012093 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12094 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12095 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12096 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12097 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12098 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12099 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12100 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12101 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12102 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12103 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12104 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12105 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12106 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12107 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12108 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12109
Bram Moolenaar5c736222010-01-06 20:54:52 +010012110 if a:0 > 0
12111 let b:netrw_curdir= a:1
12112 if b:netrw_curdir =~ '/$'
12113 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012114 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012115 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012116 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012117 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12118 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012119 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012120 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012121 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012122 endif
12123 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012124 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12125 let &l:bexpr = "netrw#BalloonHelp()"
12126 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012127
Bram Moolenaar8d043172014-01-23 14:24:41 +010012128" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012129endfun
12130
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012131" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012132" s:NetrwExe: executes a string using "!" {{{2
12133fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012134" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012135 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012136" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012137 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12138 set shell& shellcmdflag& shellxquote& shellxescape&
12139 set shellquote& shellpipe& shellredir& shellslash&
12140 exe a:cmd
12141 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12142 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012143" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012144 exe a:cmd
12145 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012146 if v:shell_error
12147 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12148 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012149" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012150endfun
12151
12152" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012153" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12154fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012155 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012156" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012157 let curbuf = bufnr("%")
12158 let curwin = winnr()
12159 let iwin = 1
12160 while iwin <= winnr("$")
12161 exe iwin."wincmd w"
12162 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12163 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12164 let winvars= w:
12165 break
12166 endif
12167 let iwin= iwin + 1
12168 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012169 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012170 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012171" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012172 for k in keys(winvars)
12173 let w:{k}= winvars[k]
12174 endfor
12175 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012176" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012177 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012178endfun
12179
Bram Moolenaara6878372014-03-22 21:02:50 +010012180" ---------------------------------------------------------------------
12181" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012182" Returns: 0=success
12183" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012184fun! s:NetrwLcd(newdir)
12185" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012186" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012187
Bram Moolenaar85850f32019-07-19 22:05:51 +020012188 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012189 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012190 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012191 catch /^Vim\%((\a\+)\)\=:E344/
12192 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12193 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012194 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012195 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12196 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012197 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012198 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12199 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012200 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012201 endif
12202 endif
12203 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012204 let err472= 1
12205 endtry
12206
12207 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012208 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12209 if exists("w:netrw_prvdir")
12210 let a:newdir= w:netrw_prvdir
12211 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012212 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012213" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012214 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012215" 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 +010012216 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012217 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012218" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12219 return -1
12220 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012221
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012222" call Decho("getcwd <".getcwd().">")
12223" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012224" call Dret("s:NetrwLcd 0")
12225 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012226endfun
12227
Bram Moolenaar9964e462007-05-05 17:54:07 +000012228" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012229" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12230" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12231fun! s:NetrwSaveWordPosn()
12232" call Dfunc("NetrwSaveWordPosn()")
12233 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12234" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12235endfun
12236
12237" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012238" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12239" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12240fun! s:NetrwHumanReadable(sz)
12241" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12242
12243 if g:netrw_sizestyle == 'h'
12244 if a:sz >= 1000000000
12245 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12246 elseif a:sz >= 10000000
12247 let sz = printf("%d",a:sz/1000000)."m"
12248 elseif a:sz >= 1000000
12249 let sz = printf("%.1f",a:sz/1000000.0)."m"
12250 elseif a:sz >= 10000
12251 let sz = printf("%d",a:sz/1000)."k"
12252 elseif a:sz >= 1000
12253 let sz = printf("%.1f",a:sz/1000.0)."k"
12254 else
12255 let sz= a:sz
12256 endif
12257
12258 elseif g:netrw_sizestyle == 'H'
12259 if a:sz >= 1073741824
12260 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12261 elseif a:sz >= 10485760
12262 let sz = printf("%d",a:sz/1048576)."M"
12263 elseif a:sz >= 1048576
12264 let sz = printf("%.1f",a:sz/1048576.0)."M"
12265 elseif a:sz >= 10240
12266 let sz = printf("%d",a:sz/1024)."K"
12267 elseif a:sz >= 1024
12268 let sz = printf("%.1f",a:sz/1024.0)."K"
12269 else
12270 let sz= a:sz
12271 endif
12272
12273 else
12274 let sz= a:sz
12275 endif
12276
12277" call Dret("s:NetrwHumanReadable ".sz)
12278 return sz
12279endfun
12280
12281" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012282" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12283" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12284fun! s:NetrwRestoreWordPosn()
12285" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012286 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012287" call Dret("NetrwRestoreWordPosn")
12288endfun
12289
12290" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012291" s:RestoreBufVars: {{{2
12292fun! s:RestoreBufVars()
12293" call Dfunc("s:RestoreBufVars()")
12294
12295 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12296 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12297 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12298 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12299 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12300 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12301
12302" call Dret("s:RestoreBufVars")
12303endfun
12304
12305" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012306" s:RemotePathAnalysis: {{{2
12307fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012308" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012309
Bram Moolenaara6878372014-03-22 21:02:50 +010012310 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012311 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012312 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012313 let s:user = substitute(a:dirname,dirpat,'\3','')
12314 let s:machine = substitute(a:dirname,dirpat,'\4','')
12315 let s:port = substitute(a:dirname,dirpat,'\5','')
12316 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012317 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012318 if s:machine =~ '@'
12319 let dirpat = '^\(.*\)@\(.\{-}\)$'
12320 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12321 let s:machine = substitute(s:machine,dirpat,'\2','')
12322 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012323
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012324" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12325" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12326" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12327" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12328" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12329" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012330
12331" call Dret("s:RemotePathAnalysis")
12332endfun
12333
12334" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012335" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12336" Returns status
12337" Runs system() on
12338" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012339" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012340fun! s:RemoteSystem(cmd)
12341" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12342 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012343 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 +000012344 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012345 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012346 else
12347 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12348 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12349 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012350 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012351 else
12352 let cmd= cmd.' '
12353 endif
12354 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012355" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012356 let ret= system(cmd)
12357 endif
12358" call Dret("s:RemoteSystem ".ret)
12359 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012360endfun
12361
12362" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012363" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012364fun! s:RestoreWinVars()
12365" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012366 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012367 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12368 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12369 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12370 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12371 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12372 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12373 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12374 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12375 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12376 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12377 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12378 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012379 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12380 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012381 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12382 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12383 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12384" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012385endfun
12386
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012387" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012388" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12389"
12390" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12391" is true) and a command, :Rexplore, which call this function.
12392"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012393" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012394"
12395" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012396fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012397 if exists("s:netrwdrag")
12398 return
12399 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012400" 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 +010012401" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12402" 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 +010012403
12404 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012405 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012406" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012407 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012408 unlet w:netrw_rexfile
12409" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012410 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012411" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012412" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12413" 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 +020012414 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012415
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012416 " ---------------------------
12417 " :Rex issued while in a file
12418 " ---------------------------
12419
Bram Moolenaara6878372014-03-22 21:02:50 +010012420 " record current file so :Rex can return to it from netrw
12421 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012422" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012423
12424 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012425" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012426 return
12427 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012428" 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 +020012429 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012430 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012431 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012432 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012433 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012434 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012435 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012436 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012437 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012438" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12439 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012440" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12441 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012442 if exists("s:rexposn_".bufnr('%'))
12443 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012444 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012445 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012446" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012447 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012448
Bram Moolenaar85850f32019-07-19 22:05:51 +020012449 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12450 if exists("s:explore_match")
12451 exe "2match netrwMarkFile /".s:explore_match."/"
12452 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012453 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012454
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012455" 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 +010012456" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012457endfun
12458
12459" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012460" s:SaveBufVars: save selected b: variables to s: variables {{{2
12461" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012462fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012463" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012464
12465 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12466 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12467 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12468 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12469 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12470 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12471
12472" call Dret("s:SaveBufVars")
12473endfun
12474
12475" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012476" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12477fun! s:SavePosn(posndict)
12478" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12479
Bram Moolenaar85850f32019-07-19 22:05:51 +020012480 if !exists("a:posndict[bufnr('%')]")
12481 let a:posndict[bufnr("%")]= []
12482 endif
12483" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12484 call add(a:posndict[bufnr("%")],winsaveview())
12485" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012486
12487" call Dret("s:SavePosn posndict")
12488 return a:posndict
12489endfun
12490
12491" ---------------------------------------------------------------------
12492" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12493fun! s:RestorePosn(posndict)
12494" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012495 if exists("a:posndict")
12496 if has_key(a:posndict,bufnr("%"))
12497" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12498 let posnlen= len(a:posndict[bufnr("%")])
12499 if posnlen > 0
12500 let posnlen= posnlen - 1
12501" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12502 call winrestview(a:posndict[bufnr("%")][posnlen])
12503 call remove(a:posndict[bufnr("%")],posnlen)
12504" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12505 endif
12506 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012507 endif
12508" call Dret("s:RestorePosn")
12509endfun
12510
12511" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012512" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012513fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012514" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012515 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12516 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12517 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12518 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12519 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12520 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12521 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12522 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12523 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12524 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12525 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12526 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12527 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12528 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12529 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12530 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12531 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12532 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12533" call Dret("s:SaveWinVars")
12534endfun
12535
12536" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012537" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012538" To allow separate windows to have their own activities, such as
12539" Explore **/pattern, several variables have been made window-oriented.
12540" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012541" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012542" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012543fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012544" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012545 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12546 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12547 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12548 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12549 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12550 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12551 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12552 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12553 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12554 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12555" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012556endfun
12557
12558" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012559" s:SetRexDir: set directory for :Rexplore {{{2
12560fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012561" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012562 let w:netrw_rexdir = a:dirname
12563 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012564 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012565" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12566" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012567" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012568" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012569" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012570endfun
12571
12572" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012573" s:ShowLink: used to modify thin and tree listings to show links {{{2
12574fun! s:ShowLink()
12575" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012576" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12577" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012578 if exists("b:netrw_curdir")
12579 norm! $?\a
12580 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12581 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012582" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12583" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12584" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12585 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012586 let dirlen = strlen(b:netrw_curdir)
12587 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012588" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012589 endif
12590 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012591" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12592" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012593 setl noro ma
12594 call setline(".",modline)
12595 setl ro noma nomod
12596 endif
12597" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12598endfun
12599
12600" ---------------------------------------------------------------------
12601" s:ShowStyle: {{{2
12602fun! s:ShowStyle()
12603 if !exists("w:netrw_liststyle")
12604 let liststyle= g:netrw_liststyle
12605 else
12606 let liststyle= w:netrw_liststyle
12607 endif
12608 if liststyle == s:THINLIST
12609 return s:THINLIST.":thin"
12610 elseif liststyle == s:LONGLIST
12611 return s:LONGLIST.":long"
12612 elseif liststyle == s:WIDELIST
12613 return s:WIDELIST.":wide"
12614 elseif liststyle == s:TREELIST
12615 return s:TREELIST.":tree"
12616 else
12617 return 'n/a'
12618 endif
12619endfun
12620
12621" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012622" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12623" Solution from Nicolai Weibull, vim docs (:help strlen()),
12624" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012625fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012626" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12627
12628 if v:version >= 703 && exists("*strdisplaywidth")
12629 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012630
Bram Moolenaar8d043172014-01-23 14:24:41 +010012631 elseif type(g:Align_xstrlen) == 1
12632 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12633 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012634
Bram Moolenaar8d043172014-01-23 14:24:41 +010012635 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012636 " number of codepoints (Latin a + combining circumflex is two codepoints)
12637 " (comment from TM, solution from NW)
12638 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012639
Bram Moolenaar8d043172014-01-23 14:24:41 +010012640 elseif g:Align_xstrlen == 2
12641 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012642 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12643 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012644 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012645
Bram Moolenaar8d043172014-01-23 14:24:41 +010012646 elseif g:Align_xstrlen == 3
12647 " virtual length (counting, for instance, tabs as anything between 1 and
12648 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012649 " preceded by lam, one otherwise, etc.)
12650 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012651 let modkeep= &l:mod
12652 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012653 call setline(line("."),a:x)
12654 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012655 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012656 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012657 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012658
Bram Moolenaar446cb832008-06-24 21:56:24 +000012659 else
12660 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012661 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012662 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012663" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012664 return ret
12665endfun
12666
12667" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012668" s:ShellEscape: shellescape(), or special windows handling {{{2
12669fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012670 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012671 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12672 endif
12673 let f = a:0 > 0 ? a:1 : 0
12674 return shellescape(a:s, f)
12675endfun
12676
12677" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012678" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012679fun! s:TreeListMove(dir)
12680" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012681 let curline = getline('.')
12682 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12683 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12684 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12685 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12686 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12687 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12688" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12689" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12690" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12691" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12692" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12693 " COMBAK : need to handle when on a directory
12694 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012695 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012696 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012697 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012698 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012699" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012700 elseif a:dir == '[]' && nxtline != ''
12701 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012702" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012703 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12704 if nl != 0
12705 NetrwKeepj norm! k
12706 else
12707 NetrwKeepj norm! G
12708 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012709" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012710 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012711 endif
12712
12713" call Dret("s:TreeListMove")
12714endfun
12715
12716" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012717" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12718" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12719" can't be called except via emenu. But due to locale, that menu line may not be called
12720" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12721fun! s:UpdateBuffersMenu()
12722" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012723 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012724 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012725 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012726 catch /^Vim\%((\a\+)\)\=:E/
12727 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012728 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012729 endtry
12730 endif
12731" call Dret("s:UpdateBuffersMenu")
12732endfun
12733
12734" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012735" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012736" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012737fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012738" call Dfunc("s:UseBufWinVars()")
12739 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012740 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12741 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12742 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12743 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12744 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12745 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12746 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12747 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12748 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 +000012749" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012750endfun
12751
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012752" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012753" s:UserMaps: supports user-defined UserMaps {{{2
12754" * calls a user-supplied funcref(islocal,curdir)
12755" * interprets result
12756" See netrw#UserMaps()
12757fun! s:UserMaps(islocal,funcname)
12758" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12759
12760 if !exists("b:netrw_curdir")
12761 let b:netrw_curdir= getcwd()
12762 endif
12763 let Funcref = function(a:funcname)
12764 let result = Funcref(a:islocal)
12765
12766 if type(result) == 1
12767 " if result from user's funcref is a string...
12768" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12769 if result == "refresh"
12770" call Decho("refreshing display",'~'.expand("<slnum>"))
12771 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12772 elseif result != ""
12773" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12774 exe result
12775 endif
12776
12777 elseif type(result) == 3
12778 " if result from user's funcref is a List...
12779" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12780 for action in result
12781 if action == "refresh"
12782" call Decho("refreshing display",'~'.expand("<slnum>"))
12783 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12784 elseif action != ""
12785" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12786 exe action
12787 endif
12788 endfor
12789 endif
12790
12791" call Dret("s:UserMaps")
12792endfun
12793
Bram Moolenaar85850f32019-07-19 22:05:51 +020012794" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012795" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012796" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012797let &cpo= s:keepcpo
12798unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012799
Bram Moolenaar85850f32019-07-19 22:05:51 +020012800" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012801" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012802" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012803" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012804" doing autoload/netrw.vim version v172g ~57
12805" varname<g:netrw_dirhistcnt> value=0 ~1
12806" varname<s:THINLIST> value=0 ~1
12807" varname<s:LONGLIST> value=1 ~1
12808" varname<s:WIDELIST> value=2 ~1
12809" varname<s:TREELIST> value=3 ~1
12810" varname<s:MAXLIST> value=4 ~1
12811" varname<g:netrw_use_errorwindow> value=2 ~1
12812" varname<g:netrw_http_xcmd> value=-q -O ~1
12813" varname<g:netrw_http_put_cmd> value=curl -T ~1
12814" varname<g:netrw_keepj> value=keepj ~1
12815" varname<g:netrw_rcp_cmd> value=rcp ~1
12816" varname<g:netrw_rsync_cmd> value=rsync ~1
12817" varname<g:netrw_rsync_sep> value=/ ~1
12818" varname<g:netrw_scp_cmd> value=scp -q ~1
12819" varname<g:netrw_sftp_cmd> value=sftp ~1
12820" varname<g:netrw_ssh_cmd> value=ssh ~1
12821" varname<g:netrw_alto> value=0 ~1
12822" varname<g:netrw_altv> value=1 ~1
12823" varname<g:netrw_banner> value=1 ~1
12824" varname<g:netrw_browse_split> value=0 ~1
12825" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12826" varname<g:netrw_chgwin> value=-1 ~1
12827" varname<g:netrw_clipboard> value=1 ~1
12828" varname<g:netrw_compress> value=gzip ~1
12829" varname<g:netrw_ctags> value=ctags ~1
12830" varname<g:netrw_cursor> value=2 ~1
12831" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12832" varname<g:netrw_cygdrive> value=/cygdrive ~1
12833" varname<s:didstarstar> value=0 ~1
12834" varname<g:netrw_dirhistcnt> value=0 ~1
12835" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12836" varname<g:netrw_dirhistmax> value=10 ~1
12837" varname<g:netrw_errorlvl> value=0 ~1
12838" varname<g:netrw_fastbrowse> value=1 ~1
12839" 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
12840" varname<g:netrw_ftpmode> value=binary ~1
12841" varname<g:netrw_hide> value=1 ~1
12842" varname<g:netrw_keepdir> value=1 ~1
12843" varname<g:netrw_list_hide> value= ~1
12844" varname<g:netrw_localmkdir> value=mkdir ~1
12845" varname<g:netrw_remote_mkdir> value=mkdir ~1
12846" varname<g:netrw_liststyle> value=0 ~1
12847" varname<g:netrw_markfileesc> value=*./[\~ ~1
12848" varname<g:netrw_maxfilenamelen> value=32 ~1
12849" varname<g:netrw_menu> value=1 ~1
12850" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12851" varname<g:netrw_mousemaps> value=1 ~1
12852" varname<g:netrw_retmap> value=0 ~1
12853" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12854" varname<g:netrw_preview> value=0 ~1