blob: 0b2a5e59f93df14ebec353045c2f0473c4029199 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01003" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00004" Version: 173a
5" Last Change:
6" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
Bram Moolenaar29634562020-01-09 21:46:04 +01007" Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM>
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00008" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000010" Permission is hereby granted to use and distribute this code,
11" with or without modifications, provided that this copyright
12" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000013" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000014" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000015" expressed or implied. By using this plugin, you agree that
16" in no event will the copyright holder be liable for any damages
17" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010018"
19" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
20" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
21"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020022"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000023"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000024" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000025" (James 1:22 RSV)
26" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000027" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000028if &cp || exists("g:loaded_netrw")
29 finish
30endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020031
32" Check that vim has patches that netrw requires.
33" Patches needed for v7.4: 1557, and 213.
34" (netrw will benefit from vim's having patch#656, too)
35let s:needspatches=[1557,213]
36if exists("s:needspatches")
37 for ptch in s:needspatches
38 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
39 if !exists("s:needpatch{ptch}")
40 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
41 endif
42 let s:needpatch{ptch}= 1
43 finish
44 endif
45 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020046endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020047
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010048let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000049if !exists("s:NOTE")
50 let s:NOTE = 0
51 let s:WARNING = 1
52 let s:ERROR = 2
53endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000054
Bram Moolenaar1afcace2005-11-25 19:54:28 +000055let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010056setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020057"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010058"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010059"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000060
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000061" ======================
62" Netrw Variables: {{{1
63" ======================
64
Bram Moolenaar071d4272004-06-13 20:20:40 +000065" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020066" netrw#ErrorMsg: {{{2
67" 0=note = s:NOTE
68" 1=warning = s:WARNING
69" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010070" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
71" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
72" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010073" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020074fun! netrw#ErrorMsg(level,msg,errnum)
75" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
76
77 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020078" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020079 return
80 endif
81
82 if a:level == 1
83 let level= "**warning** (netrw) "
84 elseif a:level == 2
85 let level= "**error** (netrw) "
86 else
87 let level= "**note** (netrw) "
88 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010089" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020090
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020091 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
92 " use popup window
93 if type(a:msg) == 3
94 let msg = [level]+a:msg
95 else
96 let msg= level.a:msg
97 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020098 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020099 let s:popuperr_text= ""
100 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200101 " (default) netrw creates a one-line window to show error/warning
102 " messages (reliably displayed)
103
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100104 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200105 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100106" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200107
108 " getting messages out reliably is just plain difficult!
109 " This attempt splits the current window, creating a one line window.
110 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100111" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200112 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100113" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200114 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100115 if type(a:msg) == 3
116 for msg in a:msg
117 NetrwKeepj call setline(line("$")+1,level.msg)
118 endfor
119 else
120 NetrwKeepj call setline(line("$")+1,level.a:msg)
121 endif
122 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200123 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100124" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200125 bo 1split
126 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200127 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200128 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100129 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100130" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200131 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100132 if type(a:msg) == 3
133 for msg in a:msg
134 NetrwKeepj call setline(line("$")+1,level.msg)
135 endfor
136 else
137 NetrwKeepj call setline(line("$"),level.a:msg)
138 endif
139 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200140 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100141" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200142 if &fo !~ '[ta]'
143 syn clear
144 syn match netrwMesgNote "^\*\*note\*\*"
145 syn match netrwMesgWarning "^\*\*warning\*\*"
146 syn match netrwMesgError "^\*\*error\*\*"
147 hi link netrwMesgWarning WarningMsg
148 hi link netrwMesgError Error
149 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100150" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200151 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200152
153 else
154 " (optional) netrw will show messages using echomsg. Even if the
155 " message doesn't appear, at least it'll be recallable via :messages
156" redraw!
157 if a:level == s:WARNING
158 echohl WarningMsg
159 elseif a:level == s:ERROR
160 echohl Error
161 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100162
163 if type(a:msg) == 3
164 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100165 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100166 endfor
167 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100168 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100169 endif
170
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100171" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200172 echohl None
173 endif
174
175" call Dret("netrw#ErrorMsg")
176endfun
177
178" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100179" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100180" Loosely, varname = value.
181fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100182" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100183 if !exists(a:varname)
184 if type(a:value) == 0
185 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200186 elseif type(a:value) == 1 && a:value =~ '^[{[]'
187 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100188 elseif type(a:value) == 1
189 exe "let ".a:varname."="."'".a:value."'"
190 else
191 exe "let ".a:varname."=".a:value
192 endif
193 endif
194endfun
195
196" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000197" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200198call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000199if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100200 call s:NetrwInit("s:THINLIST",0)
201 call s:NetrwInit("s:LONGLIST",1)
202 call s:NetrwInit("s:WIDELIST",2)
203 call s:NetrwInit("s:TREELIST",3)
204 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000205endif
206
207" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200208" Default option values: {{{2
209let g:netrw_localcopycmdopt = ""
210let g:netrw_localcopydircmdopt = ""
211let g:netrw_localmkdiropt = ""
212let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200213
214" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000215" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200216if (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")
217 call s:NetrwInit("g:netrw_use_errorwindow",2)
218else
219 call s:NetrwInit("g:netrw_use_errorwindow",1)
220endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200221
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000222if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100223 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000224 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100225 elseif executable("curl")
226 let g:netrw_dav_cmd = "curl"
227 else
228 let g:netrw_dav_cmd = ""
229 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000230endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000231if !exists("g:netrw_fetch_cmd")
232 if executable("fetch")
233 let g:netrw_fetch_cmd = "fetch -o"
234 else
235 let g:netrw_fetch_cmd = ""
236 endif
237endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100238if !exists("g:netrw_file_cmd")
239 if executable("elinks")
240 call s:NetrwInit("g:netrw_file_cmd","elinks")
241 elseif executable("links")
242 call s:NetrwInit("g:netrw_file_cmd","links")
243 endif
244endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000245if !exists("g:netrw_ftp_cmd")
246 let g:netrw_ftp_cmd = "ftp"
247endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200248let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200249if !exists("g:netrw_ftp_options")
250 let g:netrw_ftp_options= "-i -n"
251endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000252if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100253 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100254 let g:netrw_http_cmd = "wget"
255 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100256 elseif executable("curl")
257 let g:netrw_http_cmd = "curl"
258 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200259 elseif executable("elinks")
260 let g:netrw_http_cmd = "elinks"
261 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000262 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100263 let g:netrw_http_cmd = "fetch"
264 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200265 elseif executable("links")
266 let g:netrw_http_cmd = "links"
267 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000268 else
269 let g:netrw_http_cmd = ""
270 endif
271endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100272call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100273call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100274call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
275call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200276call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200277if !exists("g:netrw_scp_cmd")
278 if executable("scp")
279 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
280 elseif executable("pscp")
281 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
282 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
283 else
284 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
285 endif
286 else
287 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
288 endif
289endif
290
Bram Moolenaar5c736222010-01-06 20:54:52 +0100291call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
292call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000293
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000294if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000295 \ && exists("g:netrw_use_nt_rcp")
296 \ && g:netrw_use_nt_rcp
297 \ && executable( $SystemRoot .'/system32/rcp.exe')
298 let s:netrw_has_nt_rcp = 1
299 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000300else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000301 let s:netrw_has_nt_rcp = 0
302 let s:netrw_rcpmode = ''
303endif
304
305" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000306" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000307" Cygwin Detection ------- {{{3
308if !exists("g:netrw_cygwin")
309 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100310 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000311 let g:netrw_cygwin= 1
312 else
313 let g:netrw_cygwin= 0
314 endif
315 else
316 let g:netrw_cygwin= 0
317 endif
318endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000319" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100320call s:NetrwInit("g:netrw_alto" , &sb)
321call s:NetrwInit("g:netrw_altv" , &spr)
322call s:NetrwInit("g:netrw_banner" , 1)
323call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200324call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100325call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200326call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100327call s:NetrwInit("g:netrw_compress" , "gzip")
328call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200329if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
330 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
331 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000332endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200333call s:NetrwInit("g:netrw_cursor" , 2)
334let s:netrw_usercul = &cursorline
335let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200336"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100337call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000338" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200339call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200340call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200341call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100342call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200343call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100344call s:NetrwInit("g:netrw_fastbrowse" , 1)
345call 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 +0000346if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000347 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
348 let g:netrw_ftp_list_cmd = "ls -lF"
349 let g:netrw_ftp_timelist_cmd = "ls -tlF"
350 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000351 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000352 let g:netrw_ftp_list_cmd = "dir"
353 let g:netrw_ftp_timelist_cmd = "dir"
354 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000355 endif
356endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100357call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000358" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100359call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000360if !exists("g:netrw_ignorenetrc")
361 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
362 let g:netrw_ignorenetrc= 1
363 else
364 let g:netrw_ignorenetrc= 0
365 endif
366endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100367call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000368if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000369 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000370 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200371 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000372 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
373 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100374 if exists("g:netrw_list_cmd_options")
375 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
376 else
377 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
378 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000379 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200380 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100381 if exists("g:netrw_list_cmd_options")
382 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
383 else
384 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
385 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000386 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100387" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000388 let g:netrw_list_cmd= ""
389 endif
390endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100391call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000392" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200393if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200394 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200395 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
396endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100397if !exists("g:netrw_localcmdshell")
398 let g:netrw_localcmdshell= ""
399endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000400if !exists("g:netrw_localcopycmd")
401 if has("win32") || has("win95") || has("win64") || has("win16")
402 if g:netrw_cygwin
403 let g:netrw_localcopycmd= "cp"
404 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000405 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200406 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000407 endif
408 elseif has("unix") || has("macunix")
409 let g:netrw_localcopycmd= "cp"
410 else
411 let g:netrw_localcopycmd= ""
412 endif
413endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100414if !exists("g:netrw_localcopydircmd")
415 if has("win32") || has("win95") || has("win64") || has("win16")
416 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200417 let g:netrw_localcopydircmd = "cp"
418 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100419 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000420 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200421 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100422 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200423 elseif has("unix")
424 let g:netrw_localcopydircmd = "cp"
425 let g:netrw_localcopydircmdopt= " -R"
426 elseif has("macunix")
427 let g:netrw_localcopydircmd = "cp"
428 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100429 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200430 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100431 endif
432endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200433if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100434 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200435 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
436endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200437if has("win32") || has("win95") || has("win64") || has("win16")
438 if g:netrw_cygwin
439 call s:NetrwInit("g:netrw_localmkdir","mkdir")
440 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000441 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200442 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200443 endif
444else
445 call s:NetrwInit("g:netrw_localmkdir","mkdir")
446endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200447call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200448if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200449 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200450 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
451endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000452if !exists("g:netrw_localmovecmd")
453 if has("win32") || has("win95") || has("win64") || has("win16")
454 if g:netrw_cygwin
455 let g:netrw_localmovecmd= "mv"
456 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000457 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200458 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000459 endif
460 elseif has("unix") || has("macunix")
461 let g:netrw_localmovecmd= "mv"
462 else
463 let g:netrw_localmovecmd= ""
464 endif
465endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100466" following serves as an example for how to insert a version&patch specific test
467"if v:version < 704 || (v:version == 704 && !has("patch1107"))
468"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100469call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
470" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000471if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000472 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000473endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000474if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000475 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
476endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000477" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100478call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
479call s:NetrwInit("g:netrw_maxfilenamelen", 32)
480call s:NetrwInit("g:netrw_menu" , 1)
481call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200482call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100483call s:NetrwInit("g:netrw_retmap" , 0)
484if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
485 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
486elseif has("win32") || has("win95") || has("win64") || has("win16")
487 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
488else
489 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000490endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100491call s:NetrwInit("g:netrw_preview" , 0)
492call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100493call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100494call s:NetrwInit("g:netrw_sshport" , "-p")
495call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
496call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
497call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100498call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
499" Default values - q-s ---------- {{{3
500call s:NetrwInit("g:netrw_quickhelp",0)
501let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100502 \ "(create new) %:file d:directory",
503 \ "(windows split&open) o:horz v:vert p:preview",
504 \ "i:style qf:file info O:obtain r:reverse",
505 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
506 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
507 \ "(history) qb:list u:go up U:go down",
508 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100509" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
510call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100511if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
512 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
513else
514 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
515endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100516call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
517call s:NetrwInit("g:netrw_sort_options" , "")
518call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000519if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100520 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200521 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100522 else
523 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000524 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000525endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100526call s:NetrwInit("g:netrw_special_syntax" , 0)
527call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200528call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100529call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100530call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000531" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100532call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200533if !exists("g:netrw_xstrlen")
534 if exists("g:Align_xstrlen")
535 let g:netrw_xstrlen= g:Align_xstrlen
536 elseif exists("g:drawit_xstrlen")
537 let g:netrw_xstrlen= g:drawit_xstrlen
538 elseif &enc == "latin1" || !has("multi_byte")
539 let g:netrw_xstrlen= 0
540 else
541 let g:netrw_xstrlen= 1
542 endif
543endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100544call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100545call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200546call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100547call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200548if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000549" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000550" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100551call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200552if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200553 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200554else
Bram Moolenaarff034192013-04-24 18:51:19 +0200555 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200556endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200557call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100558call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
559call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100560if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100561 let s:treedepthstring= "│ "
562else
563 let s:treedepthstring= "| "
564endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200565call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000566
567" BufEnter event ignored by decho when following variable is true
568" Has a side effect that doau BufReadPost doesn't work, so
569" files read by network transfer aren't appropriately highlighted.
570"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571
Bram Moolenaaradc21822011-04-01 18:03:16 +0200572" ======================
573" Netrw Initialization: {{{1
574" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200575if 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 +0100576" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100577 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200578" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100579 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100580 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
581 au VimEnter * let s:initbeval= &beval
582"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100583" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
584" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
585" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
586" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
587" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
588" 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 +0200589endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200590au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200591
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200592if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100593 com! -nargs=* NetrwKeepj keepj <args>
594else
595 let g:netrw_keepj= ""
596 com! -nargs=* NetrwKeepj <args>
597endif
598
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000599" ==============================
600" Netrw Utility Functions: {{{1
601" ==============================
602
Bram Moolenaaradc21822011-04-01 18:03:16 +0200603" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100604" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100605if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100606" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100607 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100608 if &ft != "netrw"
609 return ""
610 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200611 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
612 " popup error window is still showing
613 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
614 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
615 " text under mouse hasn't changed; only close window when it changes
616 call popup_close(s:popuperr_id)
617 unlet s:popuperr_text
618 else
619 let s:popuperr_text= v:beval_text
620 endif
621 let mesg= ""
622 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 +0100623 let mesg= ""
624 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
625 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
626 elseif getline(v:beval_lnum) =~ '^"\s*/'
627 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
628 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100629 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100630 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
631 let mesg = "S: edit sorting sequence"
632 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
633 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
634 elseif v:beval_text == "Quick" || v:beval_text == "Help"
635 let mesg = "Help: press <F1>"
636 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
637 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
638 else
639 let mesg= ""
640 endif
641 return mesg
642 endfun
643"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100644" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
645" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
646" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
647" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
648" 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 +0200649endif
650
Bram Moolenaar071d4272004-06-13 20:20:40 +0000651" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200652" netrw#Explore: launch the local browser in the directory of the current file {{{2
653" indx: == -1: Nexplore
654" == -2: Pexplore
655" == +: this is overloaded:
656" * If Nexplore/Pexplore is in use, then this refers to the
657" indx'th item in the w:netrw_explore_list[] of items which
658" matched the */pattern **/pattern *//pattern **//pattern
659" * If Hexplore or Vexplore, then this will override
660" g:netrw_winsize to specify the qty of rows or columns the
661" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100662" 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 +0200663" dosplit==1: the window will be split before running the local browser
664" style == 0: Explore style == 1: Explore!
665" == 2: Hexplore style == 3: Hexplore!
666" == 4: Vexplore style == 5: Vexplore!
667" == 6: Texplore
668fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100669" 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 +0100670" 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 +0200671 if !exists("b:netrw_curdir")
672 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100673" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200674 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100675
676 " record current file for Rexplore's benefit
677 if &ft != "netrw"
678 let w:netrw_rexfile= expand("%:p")
679 endif
680
681 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200682 let curdir = simplify(b:netrw_curdir)
683 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200684 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
685 let curdir= substitute(curdir,'\','/','g')
686 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100687" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100688
689 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
690 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
691 " try Explore again.
692 if a:0 > 0
693" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100694 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
695 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
696 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
697 \ '~'.expand("<slnum>"))
698 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
699" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100700 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
701" call Dret("netrw#Explore : returning from retry")
702 return
703" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100704" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100705 endif
706 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200707
708 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200709 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100710" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100711 sil! let keepregstar = @*
712 sil! let keepregplus = @+
713 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200714 sil! let keepregslash= @/
715
Bram Moolenaar8d043172014-01-23 14:24:41 +0100716 " if dosplit
717 " -or- file has been modified AND file not hidden when abandoned
718 " -or- Texplore used
719 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100720" 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 +0200721 call s:SaveWinVars()
722 let winsz= g:netrw_winsize
723 if a:indx > 0
724 let winsz= a:indx
725 endif
726
727 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100728" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200729 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200730 if winsz == 0|let winsz= ""|endif
731 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100732" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200733
734 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100735" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200736 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200737 if winsz == 0|let winsz= ""|endif
738 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100739" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200740
741 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100742" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200743 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200744 if winsz == 0|let winsz= ""|endif
745 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100746" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200747
748 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100749" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200750 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200751 if winsz == 0|let winsz= ""|endif
752 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100753" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200754
755 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100756" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200757 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200758 if winsz == 0|let winsz= ""|endif
759 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100760" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200761
762 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100763" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200764 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200765 if winsz == 0|let winsz= ""|endif
766 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100767" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200768
769 elseif a:style == 6 " Texplore
770 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100771" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200772 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100773" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200774 call s:RestoreBufVars()
775 endif
776 call s:RestoreWinVars()
777" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100778" 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 +0200779 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100780 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200781
782 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100785" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100787" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100789" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200790 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
791 if dirname !~ '/$'
792 let dirname= dirname."/"
793 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100796" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200797 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100798" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200799 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100800" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200801 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100802" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200803 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100804" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200805 let dirname= a:1
806 endif
807 else
808 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100809" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200810 call s:NetrwClearExplore()
811" call Dret("netrw#Explore : cleared list")
812 return
813 endif
814
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100815" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200816 if dirname =~ '\.\./\=$'
817 let dirname= simplify(fnamemodify(dirname,':p:h'))
818 elseif dirname =~ '\.\.' || dirname == '.'
819 let dirname= simplify(fnamemodify(dirname,':p'))
820 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100821" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200822
823 if dirname =~ '^\*//'
824 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100825" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200826 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
827 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100828" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200829 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
830
831 elseif dirname =~ '^\*\*//'
832 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100833" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200834 let pattern= substitute(dirname,'^\*\*//','','')
835 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100836" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200837
838 elseif dirname =~ '/\*\*/'
839 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100840" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200841 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
842 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
843 let b:netrw_curdir = prefixdir
844 else
845 let b:netrw_curdir= getcwd().'/'.prefixdir
846 endif
847 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
848 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100849" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
850" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200851
852 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200853 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200854 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100855" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200856
857 elseif dirname=~ '^\*\*/'
858 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
859 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100860" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200861
862 else
863 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100864" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200865 endif
866
867 if starpat == 0 && a:indx >= 0
868 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100869" 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 +0200870 if dirname == ""
871 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100872" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200873 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200874 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200875 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200876 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200877 if dirname == ""
878 let dirname= getcwd()
879 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100880 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100881 " depending on whether backslashes have been converted to forward slashes by earlier code).
882 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200883 let dirname= b:netrw_curdir."/".dirname
884 endif
885 elseif dirname !~ '^/'
886 let dirname= b:netrw_curdir."/".dirname
887 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100888" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200889 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100890" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
891" 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 +0200892 endif
893 if exists("w:netrw_bannercnt")
894 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
895 " If one wants to return the same place in the netrw window, use :Rex instead.
896 exe w:netrw_bannercnt
897 endif
898
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100899" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200900 " ---------------------------------------------------------------------
901 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
902" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100903" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200904" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100905" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200906" endif
907 " ---------------------------------------------------------------------
908
909 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
910 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
911 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
912 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
913 elseif a:indx <= 0
914 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100915" 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 +0200916 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100917" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200918 let s:didstarstar= 1
919 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
920 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
921 endif
922
923 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100924" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200925 if !exists("w:netrw_explore_indx")
926 let w:netrw_explore_indx= 0
927 endif
928
929 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100930" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200931
932 if indx == -1
933 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100934" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200935 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100936 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 +0200937 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100938" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100939 if @* != keepregstar | sil! let @* = keepregstar | endif
940 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100941 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200942 sil! let @/ = keepregslash
943" call Dret("netrw#Explore")
944 return
945 endif
946 let indx= w:netrw_explore_indx
947 if indx < 0 | let indx= 0 | endif
948 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
949 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100950" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200951 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
952 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100953" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200954 endwhile
955 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100956" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200957
958 elseif indx == -2
959 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100960" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200961 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100962 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 +0200963 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100964" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100965 if @* != keepregstar | sil! let @* = keepregstar | endif
966 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100967 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200968 sil! let @/ = keepregslash
969" call Dret("netrw#Explore")
970 return
971 endif
972 let indx= w:netrw_explore_indx
973 if indx < 0 | let indx= 0 | endif
974 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
975 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100976" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200977 while indx >= 0 && curfile == w:netrw_explore_list[indx]
978 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100979" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200980 endwhile
981 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100982" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200983
984 else
985 " Explore -- initialize
986 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100987" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100988 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200989 let w:netrw_explore_indx= 0
990 if !exists("b:netrw_curdir")
991 let b:netrw_curdir= getcwd()
992 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100993" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200994
995 " switch on starpat to build the w:netrw_explore_list of files
996 if starpat == 1
997 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100998" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
999" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001000 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001001 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001002 catch /^Vim\%((\a\+)\)\=:E480/
1003 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1004" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1005 return
1006 endtry
1007 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1008 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1009
1010 elseif starpat == 2
1011 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001012" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1013" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001014 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001015 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001016 catch /^Vim\%((\a\+)\)\=:E480/
1017 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1018 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001019 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001020" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001021 if @* != keepregstar | sil! let @* = keepregstar | endif
1022 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001023 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001024 sil! let @/ = keepregslash
1025" call Dret("netrw#Explore : no files matched pattern")
1026 return
1027 endtry
1028 let s:netrw_curdir = b:netrw_curdir
1029 let w:netrw_explore_list = getqflist()
1030 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1031 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1032
1033 elseif starpat == 3
1034 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001035" 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 +02001036 let filepat= substitute(dirname,'^\*/','','')
1037 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001038" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1039" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001040 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1041 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1042
1043 elseif starpat == 4
1044 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001045" 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 +02001046 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1047 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1048 endif " switch on starpat to build w:netrw_explore_list
1049
1050 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001051" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1052" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001053
1054 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001055 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001056 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001057" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001058 if @* != keepregstar | sil! let @* = keepregstar | endif
1059 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001060 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001061 sil! let @/ = keepregslash
1062" call Dret("netrw#Explore : no files matched")
1063 return
1064 endif
1065 endif " if indx ... endif
1066
1067 " NetrwStatusLine support - for exploring support
1068 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001069" 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 +02001070
1071 " wrap the indx around, but issue a note
1072 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001073" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001074 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1075 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001076 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001077 endif
1078
1079 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001080" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001081 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001082" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001083
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001084" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001085 call netrw#LocalBrowseCheck(newdir)
1086 if !exists("w:netrw_liststyle")
1087 let w:netrw_liststyle= g:netrw_liststyle
1088 endif
1089 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001090 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001091 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001092 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001093 endif
1094 let w:netrw_explore_mtchcnt = indx + 1
1095 let w:netrw_explore_bufnr = bufnr("%")
1096 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001097 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001098" 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 +02001099
1100 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001101" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001102 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001103 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 +02001104 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001105 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001106" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001107 if @* != keepregstar | sil! let @* = keepregstar | endif
1108 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001109 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001110 sil! let @/ = keepregslash
1111" call Dret("netrw#Explore : missing +path_extra")
1112 return
1113 endif
1114
1115 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001116" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001117 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1118 sil! unlet w:netrw_treedict
1119 sil! unlet w:netrw_treetop
1120 endif
1121 let newdir= dirname
1122 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001123 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001124 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001125 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001126 endif
1127 endif
1128
1129 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001130" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1131" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001132 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001133" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001134 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001135 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001136" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001137 let s:explore_prvdir = b:netrw_curdir
1138 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001139 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001140 if b:netrw_curdir !~ '/$'
1141 let dirlen= dirlen + 1
1142 endif
1143 let prvfname= ""
1144 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001145" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001146 if fname =~ '^'.b:netrw_curdir
1147 if s:explore_match == ""
1148 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1149 else
1150 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1151 endif
1152 elseif fname !~ '^/' && fname != prvfname
1153 if s:explore_match == ""
1154 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1155 else
1156 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1157 endif
1158 endif
1159 let prvfname= fname
1160 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001161" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001162 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1163 exe "2match netrwMarkFile /".s:explore_match."/"
1164 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001165 endif
1166 echo "<s-up>==Pexplore <s-down>==Nexplore"
1167 else
1168 2match none
1169 if exists("s:explore_match") | unlet s:explore_match | endif
1170 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001171" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001172 endif
1173
Bram Moolenaara6878372014-03-22 21:02:50 +01001174 " since Explore may be used to initialize netrw's browser,
1175 " there's no danger of a late FocusGained event on initialization.
1176 " Consequently, set s:netrw_events to 2.
1177 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001178 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001179" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001180 if @* != keepregstar | sil! let @* = keepregstar | endif
1181 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001182 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001183 sil! let @/ = keepregslash
1184" call Dret("netrw#Explore : @/<".@/.">")
1185endfun
1186
1187" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001188" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001189" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1190" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1191" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1192" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1193" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001194fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001195" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001196 let curwin= winnr()
1197
Bram Moolenaara6878372014-03-22 21:02:50 +01001198 if a:0 > 0 && a:1 != ""
1199 " if a netrw window is already on the left-side of the tab
1200 " and a directory has been specified, explore with that
1201 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001202" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001203 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001204" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001205 exe "1wincmd w"
1206 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001207" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001208 exe "Explore ".fnameescape(a1)
1209 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001210 let s:lexplore_win= curwin
1211 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001212 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001213" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001214 unlet t:netrw_lexposn
1215 endif
1216" call Dret("netrw#Lexplore")
1217 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001218 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001219 exe curwin."wincmd w"
1220 else
1221 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001222" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001223 endif
1224
Bram Moolenaar8d043172014-01-23 14:24:41 +01001225 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001226 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001227 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001228" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001229 else
1230 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001231" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001232 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001233" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001234
1235 if lexwinnr > 0
1236 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001237" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001238 exe lexwinnr."wincmd w"
1239 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001240 let t:netrw_lexposn = winsaveview()
1241" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001242" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001243 close
1244 if lexwinnr < curwin
1245 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001246 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001247 if lexwinnr != curwin
1248 exe curwin."wincmd w"
1249 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001250 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001251" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001252
1253 else
1254 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001255" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001256 exe "1wincmd w"
1257 let keep_altv = g:netrw_altv
1258 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001259 if a:count != 0
1260 let netrw_winsize = g:netrw_winsize
1261 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001262 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001263 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001264" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001265 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 +02001266" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001267 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001268" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001269 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001270 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001271 elseif curfile =~ '^\a\{3,}://'
1272" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001273 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001274 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001275" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001276 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001277 endif
1278 if a:count != 0
1279 let g:netrw_winsize = netrw_winsize
1280 endif
1281 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001282 let g:netrw_altv = keep_altv
1283 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001284 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1285 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001286 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001287 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001288" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1289" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001290 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001291" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001292" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1293 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001294 unlet t:netrw_lexposn
1295 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001296 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001297
1298 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001299 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001300 if a:rightside
1301 let g:netrw_chgwin= 1
1302 else
1303 let g:netrw_chgwin= 2
1304 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001305" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001306 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001307
Bram Moolenaar8d043172014-01-23 14:24:41 +01001308" call Dret("netrw#Lexplore")
1309endfun
1310
1311" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001312" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001313" supports :NetrwClean -- remove netrw from first directory on runtimepath
1314" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001315fun! netrw#Clean(sys)
1316" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001317
1318 if a:sys
1319 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1320 else
1321 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1322 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001323" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001324 let diddel= 0
1325 let diddir= ""
1326
1327 if choice == 1
1328 for dir in split(&rtp,',')
1329 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001330" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001331 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1332 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1333 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1334 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1335 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1336 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 +00001337 let diddir= dir
1338 let diddel= diddel + 1
1339 if !a:sys|break|endif
1340 endif
1341 endfor
1342 endif
1343
1344 echohl WarningMsg
1345 if diddel == 0
1346 echomsg "netrw is either not installed or not removable"
1347 elseif diddel == 1
1348 echomsg "removed one copy of netrw from <".diddir.">"
1349 else
1350 echomsg "removed ".diddel." copies of netrw"
1351 endif
1352 echohl None
1353
Bram Moolenaara6878372014-03-22 21:02:50 +01001354" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001355endfun
1356
Bram Moolenaar5c736222010-01-06 20:54:52 +01001357" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001358" netrw#MakeTgt: make a target out of the directory name provided {{{2
1359fun! netrw#MakeTgt(dname)
1360" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1361 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001362 let svpos = winsaveview()
1363" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001364 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1365" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001366 if s:netrwmftgt_islocal
1367 let netrwmftgt= simplify(a:dname)
1368 else
1369 let netrwmftgt= a:dname
1370 endif
1371 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1372 " re-selected target, so just clear it
1373 unlet s:netrwmftgt s:netrwmftgt_islocal
1374 else
1375 let s:netrwmftgt= netrwmftgt
1376 endif
1377 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001378 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001379 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001380" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1381 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001382" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001383endfun
1384
Bram Moolenaara6878372014-03-22 21:02:50 +01001385" ---------------------------------------------------------------------
1386" netrw#Obtain: {{{2
1387" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001388" islocal=0 obtain from remote source
1389" =1 obtain from local source
1390" fname : a filename or a list of filenames
1391" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001392fun! netrw#Obtain(islocal,fname,...)
1393" 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 +02001394 " NetrwStatusLine support - for obtaining support
1395
1396 if type(a:fname) == 1
1397 let fnamelist= [ a:fname ]
1398 elseif type(a:fname) == 3
1399 let fnamelist= a:fname
1400 else
1401 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 +01001402" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001403 return
1404 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001405" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001406 if a:0 > 0
1407 let tgtdir= a:1
1408 else
1409 let tgtdir= getcwd()
1410 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001411" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001412
1413 if exists("b:netrw_islocal") && b:netrw_islocal
1414 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001415" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001416 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1417 let topath= s:ComposePath(tgtdir,"")
1418 if (has("win32") || has("win95") || has("win64") || has("win16"))
1419 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001420" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001421 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001422" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001423 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001424 if v:shell_error != 0
1425 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 +01001426" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001427 return
1428 endif
1429 endfor
1430 else
1431 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001432" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1433 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1434" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001435 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001436 if v:shell_error != 0
1437 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 +01001438" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001439 return
1440 endif
1441 endif
1442 elseif !exists("b:netrw_curdir")
1443 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1444 else
1445 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1446 endif
1447
1448 else
1449 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001450" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001451 if type(a:fname) == 1
1452 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1453 endif
1454 call s:NetrwMethod(b:netrw_curdir)
1455
1456 if b:netrw_method == 4
1457 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001458" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001459 if exists("g:netrw_port") && g:netrw_port != ""
1460 let useport= " ".g:netrw_scpport." ".g:netrw_port
1461 else
1462 let useport= ""
1463 endif
1464 if b:netrw_fname =~ '/'
1465 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1466 else
1467 let path= ""
1468 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001469 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001470 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 +02001471
1472 elseif b:netrw_method == 2
1473 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001474" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001475 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001476 let tmpbufnr= bufnr("%")
1477 setl ff=unix
1478 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001479 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001480" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001481 endif
1482
1483 if exists("b:netrw_fname") && b:netrw_fname != ""
1484 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001485" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001486 endif
1487
1488 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001489 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001490" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001491 endif
1492 for fname in fnamelist
1493 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001494" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001495 endfor
1496 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001497 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 +02001498 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001499 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001500 endif
1501 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1502 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1503 let debugkeep= &debug
1504 setl debug=msg
1505 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1506 let &debug= debugkeep
1507 endif
1508
1509 elseif b:netrw_method == 3
1510 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001511" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001512 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001513 let tmpbufnr= bufnr("%")
1514 setl ff=unix
1515
1516 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001517 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001518" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001519 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001520 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001521" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001522 endif
1523
1524 if exists("g:netrw_uid") && g:netrw_uid != ""
1525 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001526 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001527" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001528 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001529 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001530 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001531" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001532 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001533 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001534" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001535 endif
1536 endif
1537
1538 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001539 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001540" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001541 endif
1542
1543 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001544 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001545" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001546 endif
1547
1548 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001549 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001550" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001551 endif
1552
1553 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001554 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001555" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001556 endif
1557 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001558 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001559 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001560" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001561
1562 " perform ftp:
1563 " -i : turns off interactive prompting from ftp
1564 " -n unix : DON'T use <.netrc>, even though it exists
1565 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001566 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1567 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001568 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001569 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1570 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001571" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001572 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001573 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001574 endif
1575 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001576
1577 elseif b:netrw_method == 9
1578 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001579" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001580 if a:fname =~ '/'
1581 let localfile= substitute(a:fname,'^.*/','','')
1582 else
1583 let localfile= a:fname
1584 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001585 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 +02001586
Bram Moolenaarff034192013-04-24 18:51:19 +02001587 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001588 " probably a badly formed url; protocol not recognized
1589" call Dret("netrw#Obtain : unsupported method")
1590 return
1591
1592 else
1593 " protocol recognized but not supported for Obtain (yet?)
1594 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001595 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001596 endif
1597" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001598 return
1599 endif
1600
1601 " restore status line
1602 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001603 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001604 endif
1605
1606 endif
1607
1608 " cleanup
1609 if exists("tmpbufnr")
1610 if bufnr("%") != tmpbufnr
1611 exe tmpbufnr."bw!"
1612 else
1613 q!
1614 endif
1615 endif
1616
Bram Moolenaara6878372014-03-22 21:02:50 +01001617" call Dret("netrw#Obtain")
1618endfun
1619
1620" ---------------------------------------------------------------------
1621" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1622fun! netrw#Nread(mode,fname)
1623" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001624 let svpos= winsaveview()
1625" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001626 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001627" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1628 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001629
1630 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1631 if exists("w:netrw_bannercnt")
1632 " start with cursor just after the banner
1633 exe w:netrw_bannercnt
1634 endif
1635 endif
1636" call Dret("netrw#Nread")
1637endfun
1638
1639" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001640" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1641" Options get restored by s:NetrwOptionsRestore()
1642"
1643" Option handling:
1644" * save user's options (s:NetrwOptionsSave)
1645" * set netrw-safe options (s:NetrwOptionsSafe)
1646" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1647" * restore user's options (s:netrwOPtionsRestore)
1648" - restore a user option when != safe option (s:NetrwRestoreSetting)
1649" vt: (variable type) normally its either "w:" or "s:"
1650fun! s:NetrwOptionsSave(vt)
1651" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1652" 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 +02001653" 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>"))
1654" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001655
1656 if !exists("{a:vt}netrw_optionsave")
1657 let {a:vt}netrw_optionsave= 1
1658 else
1659" call Dret("s:NetrwOptionsSave : options already saved")
1660 return
1661 endif
1662" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1663
1664 " Save current settings and current directory
1665" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1666 let s:yykeep = @@
1667 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1668 let {a:vt}netrw_aikeep = &l:ai
1669 let {a:vt}netrw_awkeep = &l:aw
1670 let {a:vt}netrw_bhkeep = &l:bh
1671 let {a:vt}netrw_blkeep = &l:bl
1672 let {a:vt}netrw_btkeep = &l:bt
1673 let {a:vt}netrw_bombkeep = &l:bomb
1674 let {a:vt}netrw_cedit = &cedit
1675 let {a:vt}netrw_cikeep = &l:ci
1676 let {a:vt}netrw_cinkeep = &l:cin
1677 let {a:vt}netrw_cinokeep = &l:cino
1678 let {a:vt}netrw_comkeep = &l:com
1679 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001680 let {a:vt}netrw_cuckeep = &l:cuc
1681 let {a:vt}netrw_culkeep = &l:cul
1682" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001683 let {a:vt}netrw_diffkeep = &l:diff
1684 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001685 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1686 let {a:vt}netrw_ffkeep = &l:ff
1687 endif
1688 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1689 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001690 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001691 let {a:vt}netrw_hidkeep = &l:hidden
1692 let {a:vt}netrw_imkeep = &l:im
1693 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001694 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001695 let {a:vt}netrw_lskeep = &l:ls
1696 let {a:vt}netrw_makeep = &l:ma
1697 let {a:vt}netrw_magickeep = &l:magic
1698 let {a:vt}netrw_modkeep = &l:mod
1699 let {a:vt}netrw_nukeep = &l:nu
1700 let {a:vt}netrw_rnukeep = &l:rnu
1701 let {a:vt}netrw_repkeep = &l:report
1702 let {a:vt}netrw_rokeep = &l:ro
1703 let {a:vt}netrw_selkeep = &l:sel
1704 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001705 if !g:netrw_use_noswf
1706 let {a:vt}netrw_swfkeep = &l:swf
1707 endif
1708 let {a:vt}netrw_tskeep = &l:ts
1709 let {a:vt}netrw_twkeep = &l:tw " textwidth
1710 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1711 let {a:vt}netrw_wrapkeep = &l:wrap
1712 let {a:vt}netrw_writekeep = &l:write
1713
1714 " save a few selected netrw-related variables
1715" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1716 if g:netrw_keepdir
1717 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001718" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001719 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001720 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001721 sil! let {a:vt}netrw_starkeep = @*
1722 sil! let {a:vt}netrw_pluskeep = @+
1723 endif
1724 sil! let {a:vt}netrw_slashkeep= @/
1725
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001726" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001727" 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>"))
1728" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1729endfun
1730
1731" ---------------------------------------------------------------------
1732" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1733" Use s:NetrwSaveOptions() to save user settings
1734" Use s:NetrwOptionsRestore() to restore user settings
1735fun! s:NetrwOptionsSafe(islocal)
1736" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1737" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1738" 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>"))
1739 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1740 call s:NetrwSetSafeSetting("&l:ai",0)
1741 call s:NetrwSetSafeSetting("&l:aw",0)
1742 call s:NetrwSetSafeSetting("&l:bl",0)
1743 call s:NetrwSetSafeSetting("&l:bomb",0)
1744 if a:islocal
1745 call s:NetrwSetSafeSetting("&l:bt","nofile")
1746 else
1747 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1748 endif
1749 call s:NetrwSetSafeSetting("&l:ci",0)
1750 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001751 if g:netrw_fastbrowse > a:islocal
1752 call s:NetrwSetSafeSetting("&l:bh","hide")
1753 else
1754 call s:NetrwSetSafeSetting("&l:bh","delete")
1755 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001756 call s:NetrwSetSafeSetting("&l:cino","")
1757 call s:NetrwSetSafeSetting("&l:com","")
1758 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1759 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1760 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001761 if &go =~ 'a' | set go-=a | endif
1762 if &go =~ 'A' | set go-=A | endif
1763 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001764 call s:NetrwSetSafeSetting("&l:hid",0)
1765 call s:NetrwSetSafeSetting("&l:im",0)
1766 setl isk+=@ isk+=* isk+=/
1767 call s:NetrwSetSafeSetting("&l:magic",1)
1768 if g:netrw_use_noswf
1769 call s:NetrwSetSafeSetting("swf",0)
1770 endif
1771 call s:NetrwSetSafeSetting("&l:report",10000)
1772 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1773 call s:NetrwSetSafeSetting("&l:spell",0)
1774 call s:NetrwSetSafeSetting("&l:tw",0)
1775 call s:NetrwSetSafeSetting("&l:wig","")
1776 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001777
1778 " set up cuc and cul based on g:netrw_cursor and listing style
1779 " COMBAK -- cuc cul related
1780 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001781
1782 " allow the user to override safe options
1783" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1784 if &ft == "netrw"
1785" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1786 keepalt NetrwKeepj doau FileType netrw
1787 endif
1788
1789" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1790" 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>"))
1791" call Dret("s:NetrwOptionsSafe")
1792endfun
1793
1794" ---------------------------------------------------------------------
1795" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1796fun! s:NetrwOptionsRestore(vt)
1797" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001798" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001799" 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 +01001800 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001801" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01001802 if filereadable(expand("%"))
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001803" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001804 filetype detect
1805" 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>"))
1806 else
1807 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001808 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001809" 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 +02001810" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001811 return
1812 endif
1813 unlet {a:vt}netrw_optionsave
1814
1815 if exists("+acd")
1816 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001817" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001818 let curdir = getcwd()
1819 let &l:acd = {a:vt}netrw_acdkeep
1820 unlet {a:vt}netrw_acdkeep
1821 if &l:acd
1822 call s:NetrwLcd(curdir)
1823 endif
1824 endif
1825 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001826" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001827 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1828 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1829 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1830 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1831 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001832" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001833 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1834 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1835 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1836 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1837 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001838" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001839 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1840 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1841 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1842 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1843 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001844 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001845" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1846 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1847 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001848 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001849 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1850" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1851 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1852 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1853" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1854 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1855" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1856 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1857 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001858 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001859 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1860 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1861" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1862 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1863 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1864 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1865 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1866" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001867 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001868 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1869 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1870 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001871 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001872" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001873 call s:NetrwRestoreSetting("s:yykeep","@@")
1874 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1875 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1876 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1877 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1878
Bram Moolenaara6878372014-03-22 21:02:50 +01001879 if exists("{a:vt}netrw_swfkeep")
1880 if &directory == ""
1881 " user hasn't specified a swapfile directory;
1882 " netrw will temporarily set the swapfile directory
1883 " to the current directory as returned by getcwd().
1884 let &l:directory= getcwd()
1885 sil! let &l:swf = {a:vt}netrw_swfkeep
1886 setl directory=
1887 unlet {a:vt}netrw_swfkeep
1888 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001889 if !g:netrw_use_noswf
1890 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1891 sil! let &l:swf= {a:vt}netrw_swfkeep
1892 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001893 unlet {a:vt}netrw_swfkeep
1894 endif
1895 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001896 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001897 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1898 if exists("{a:vt}netrw_dirkeep")
1899 call s:NetrwLcd(dirkeep)
1900 unlet {a:vt}netrw_dirkeep
1901 endif
1902 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001903 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001904" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001905 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1906 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001907 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001908 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001909
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001910" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1911" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1912" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1913" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1914" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001915 " Moved the filetype detect here from NetrwGetFile() because remote files
1916 " were having their filetype detect-generated settings overwritten by
1917 " NetrwOptionRestore.
1918 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001919" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1920 filetype detect
1921" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001922 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001923" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001924" 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 +02001925" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001926endfun
1927
1928" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001929" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1930" but only when the options' value and the safe setting differ
1931" Doing this means that netrw will not come up as having changed a
1932" setting last when it really didn't actually change it.
1933"
1934" Called from s:NetrwOptionsSafe
1935" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1936fun! s:NetrwSetSafeSetting(setting,safesetting)
1937" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001938
Bram Moolenaar85850f32019-07-19 22:05:51 +02001939 if a:setting =~ '^&'
1940" call Decho("fyi: a:setting starts with &")
1941 exe "let settingval= ".a:setting
1942" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001943
Bram Moolenaar85850f32019-07-19 22:05:51 +02001944 if settingval != a:safesetting
1945" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1946 if type(a:safesetting) == 0
1947 exe "let ".a:setting."=".a:safesetting
1948 elseif type(a:safesetting) == 1
1949 exe "let ".a:setting."= '".a:safesetting."'"
1950 else
1951 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1952 endif
1953 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001954 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001955
Bram Moolenaar85850f32019-07-19 22:05:51 +02001956" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001957endfun
1958
1959" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001960" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1961" but only if the setting value differs from the associated keepvar.
1962" Doing this means that netrw will not come up as having changed a
1963" setting last when it really didn't actually change it.
1964"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001965" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001966" keepvars are set up by s:NetrwOptionsSave
1967fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001968""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001969
Bram Moolenaar85850f32019-07-19 22:05:51 +02001970 " typically called from s:NetrwOptionsRestore
1971 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1972 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001973 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001974 if exists(a:keepvar)
1975 exe "let keepvarval= ".a:keepvar
1976 exe "let setting= ".a:setting
1977
1978"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1979"" call Decho("fyi: keepvarval=".keepvarval)
1980"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1981
1982 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001983"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001984 if type(a:setting) == 0
1985 exe "let ".a:setting."= ".keepvarval
1986 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001987 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001988 else
1989 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1990 endif
1991 endif
1992
1993 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001994 endif
1995
Bram Moolenaar85850f32019-07-19 22:05:51 +02001996"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001997endfun
1998
1999" ---------------------------------------------------------------------
2000" NetrwStatusLine: {{{2
2001fun! NetrwStatusLine()
2002
2003" vvv NetrwStatusLine() debugging vvv
2004" let g:stlmsg=""
2005" if !exists("w:netrw_explore_bufnr")
2006" let g:stlmsg="!X<explore_bufnr>"
2007" elseif w:netrw_explore_bufnr != bufnr("%")
2008" let g:stlmsg="explore_bufnr!=".bufnr("%")
2009" endif
2010" if !exists("w:netrw_explore_line")
2011" let g:stlmsg=" !X<explore_line>"
2012" elseif w:netrw_explore_line != line(".")
2013" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2014" endif
2015" if !exists("w:netrw_explore_list")
2016" let g:stlmsg=" !X<explore_list>"
2017" endif
2018" ^^^ NetrwStatusLine() debugging ^^^
2019
2020 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")
2021 " restore user's status line
2022 let &stl = s:netrw_users_stl
2023 let &laststatus = s:netrw_users_ls
2024 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2025 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2026 return ""
2027 else
2028 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2029 endif
2030endfun
2031
Bram Moolenaar85850f32019-07-19 22:05:51 +02002032" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002033" Netrw Transfer Functions: {{{1
2034" ===============================
2035
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002037" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002038" mode: =0 read remote file and insert before current line
2039" =1 read remote file and insert after current line
2040" =2 replace with remote file
2041" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002042fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002043" 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 +00002044
Bram Moolenaar5c736222010-01-06 20:54:52 +01002045 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002046 call s:NetrwOptionsSave("w:")
2047 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002048 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002049 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2050 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2051 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002052" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002053
Bram Moolenaar5c736222010-01-06 20:54:52 +01002054 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002055 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002056 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002057 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002058 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002059 elseif a:mode == 2 " replace with remote file
2060 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002061 elseif a:mode == 3 " skip read of file (leave as temporary)
2062 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002063 else
2064 exe a:mode
2065 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002066 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002067 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002068" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002069
Bram Moolenaar5c736222010-01-06 20:54:52 +01002070 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002071 let tmpfile= s:GetTempfile("")
2072 if tmpfile == ""
2073" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002074 return
2075 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002076
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002078
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002079 " attempt to repeat with previous host-file-etc
2080 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002081" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002082 let choice = b:netrw_lastfile
2083 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002084
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002085 else
2086 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002087" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002088
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002089 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002090 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002091 echomsg 'NetRead Usage:'
2092 echomsg ':Nread machine:path uses rcp'
2093 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2094 echomsg ':Nread "machine id password path" uses ftp'
2095 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2096 echomsg ':Nread fetch://machine/path uses fetch'
2097 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2098 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002099 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002100 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002101 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2102 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2103 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2104 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002105 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002106 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002107
Bram Moolenaar9964e462007-05-05 17:54:07 +00002108 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002109 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002110" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002111 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002113 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 else
2115 " case "... ... ..."
2116 let choice = strpart(choice,1,strlen(choice)-1)
2117 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002118
Bram Moolenaar9964e462007-05-05 17:54:07 +00002119 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002120 let wholechoice = wholechoice . " " . choice
2121 let ichoice = ichoice + 1
2122 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002123 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002124 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002125 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002126" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002127 return
2128 endif
2129 let choice= a:{ichoice}
2130 endwhile
2131 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2132 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002133 endif
2134 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002136" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002137 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002138
Bram Moolenaar5c736222010-01-06 20:54:52 +01002139 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002140 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002141 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002142" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002143 return
2144 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002145 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002146
Bram Moolenaar8d043172014-01-23 14:24:41 +01002147 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002148" 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 +02002149 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002150" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002151 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002152" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002153 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002154 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002155
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002157 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002158 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002159 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2160 echo "(netrw) Processing your read request..."
2161 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002162
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002163 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002164 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002165 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002166" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002167 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002168 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002169 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002170 " ER: the tmpfile is full path: rcp sees C:\... as host C
2171 if s:netrw_has_nt_rcp == 1
2172 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2173 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2174 else
2175 " Any way needed it machine contains a '.'
2176 let uid_machine = g:netrw_machine .'.'. $USERNAME
2177 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002178 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002179 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2180 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2181 else
2182 let uid_machine = g:netrw_machine
2183 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002184 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002185 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 +00002186 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002187 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002188
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002189 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002190 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002191 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002192" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002193 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002194 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002195 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002196 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002197 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002198" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002199 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002200 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002201" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002202 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002203 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002205 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002206 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 +00002207 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002208 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002209 endif
2210 " 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 +00002211 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002212 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002213 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002214 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002215 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002216 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002217 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002218 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002219 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2220 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002221 q!
2222 endif
2223 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002224 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002226
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002227 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002228 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2230 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002231" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002232 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002233 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002234 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002235 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002237 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002238" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002239 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002242 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002243
Bram Moolenaar97d62492012-11-15 21:28:22 +01002244 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002245 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002246 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002247" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002248 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002249 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002250 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002251" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002252 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002253 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002255 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002256 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002257
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002258 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002259 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002260" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002261 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002262 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002263 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002264" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002265 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002266 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002267" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002268
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002269 " perform ftp:
2270 " -i : turns off interactive prompting from ftp
2271 " -n unix : DON'T use <.netrc>, even though it exists
2272 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002273 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002274 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002275 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2276 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002277" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002278 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002279 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002280 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002281 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002282 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002283 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002285
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002287 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002288 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002289" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002290 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002291 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002292 else
2293 let useport= ""
2294 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002295 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2296 " This is workaround to avoid mis-handle windows local-path:
2297 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2298 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2299 else
2300 let tmpfile_get = tmpfile
2301 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002302 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 +00002303 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002304 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002305
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002306 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002307 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002308 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002309" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002310 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002311 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002312 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002313 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002314" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002315 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002316 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002317
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002318 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2319 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002320" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002321 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002322 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 +00002323 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002324 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 +00002325 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002326 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002327
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002328 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002329 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002330" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002331 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2332 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002333" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2334" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2335 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 +00002336 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002337" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002338 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002339 endif
2340 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002341" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002342 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002343
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002344 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002345 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002346 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002347" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002348
Bram Moolenaar5c736222010-01-06 20:54:52 +01002349 if !executable(g:netrw_dav_cmd)
2350 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2351" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2352 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002353 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002354 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002355 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 +01002356 else
2357 " Construct execution string (four lines) which will be passed through filter
2358 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2359 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002360 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002361 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002362 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002363 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002364 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002365 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002366 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002367 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002368 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002369 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2370 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002371
Bram Moolenaar5c736222010-01-06 20:54:52 +01002372 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002373 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002374 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002375 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002376 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002377 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002378 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002379
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002381 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002382 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002383" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002384 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 +00002385 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002387
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002388 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002389 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002390 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002391 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002392" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002394 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002395 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002396 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002397" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002398 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002399 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002400 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002401 let netrw_option= "http"
2402 else
2403 let netrw_option= "ftp"
2404 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002405" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002406
Bram Moolenaar446cb832008-06-24 21:56:24 +00002407 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002408 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 +00002409 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002410 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 +00002411 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002412
Bram Moolenaar446cb832008-06-24 21:56:24 +00002413 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002414 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002415" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002416 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002417
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002418 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002419 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002420 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002421" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2422 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 +00002423 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002424 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002425
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002426 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002427 " NetRead: (file) NetRead Method #10 {{{3
2428 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002429" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2430 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002431 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2432 let b:netrw_lastfile = choice
2433
2434 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002435 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002436 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002437 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002438 endif
2439 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002440
Bram Moolenaar5c736222010-01-06 20:54:52 +01002441 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002443" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002444 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445 unlet b:netrw_fname
2446 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002447 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 +01002448" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002449 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002450 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002451 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002452
Bram Moolenaar9964e462007-05-05 17:54:07 +00002453" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002454endfun
2455
2456" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002457" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002458fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002459" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002460
Bram Moolenaar5c736222010-01-06 20:54:52 +01002461 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002462 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002463 call s:NetrwOptionsSave("w:")
2464 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002465
Bram Moolenaar5c736222010-01-06 20:54:52 +01002466 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002467 let tmpfile= s:GetTempfile("")
2468 if tmpfile == ""
2469" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002470 return
2471 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002472
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002473 if a:0 == 0
2474 let ichoice = 0
2475 else
2476 let ichoice = 1
2477 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002478
Bram Moolenaar9964e462007-05-05 17:54:07 +00002479 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002480" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002481 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002482 " For binary writes, always write entire file.
2483 " (line numbers don't really make sense for that).
2484 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002485" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002486 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002487 elseif g:netrw_cygwin
2488 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002489 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002490" 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 +01002491 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002492 else
2493 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002494" 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 +01002495 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002496 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002497
Bram Moolenaar9964e462007-05-05 17:54:07 +00002498 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002499 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002500 " on the temporary file's name. Deletion of the temporary file during
2501 " cleanup then causes an error message.
2502 0file!
2503 endif
2504
Bram Moolenaar5c736222010-01-06 20:54:52 +01002505 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002506 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002507
Bram Moolenaar9964e462007-05-05 17:54:07 +00002508 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002509 " attempt to repeat with previous host-file-etc
2510 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002511" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002512 let choice = b:netrw_lastfile
2513 let ichoice= ichoice + 1
2514 else
2515 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002516
Bram Moolenaar8d043172014-01-23 14:24:41 +01002517 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002518 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002519 echomsg 'NetWrite Usage:"'
2520 echomsg ':Nwrite machine:path uses rcp'
2521 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2522 echomsg ':Nwrite "machine id password path" uses ftp'
2523 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2524 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2525 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2526 echomsg ':Nwrite rcp://machine/path uses rcp'
2527 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2528 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2529 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002530 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002531 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002532
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002533 elseif match(choice,"^\"") != -1
2534 if match(choice,"\"$") != -1
2535 " case "..."
2536 let choice=strpart(choice,1,strlen(choice)-2)
2537 else
2538 " case "... ... ..."
2539 let choice = strpart(choice,1,strlen(choice)-1)
2540 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002541
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002542 while match(choice,"\"$") == -1
2543 let wholechoice= wholechoice . " " . choice
2544 let ichoice = ichoice + 1
2545 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002546 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002547 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002548 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002549" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002550 return
2551 endif
2552 let choice= a:{ichoice}
2553 endwhile
2554 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2555 endif
2556 endif
2557 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002558 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002559" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002560
Bram Moolenaar9964e462007-05-05 17:54:07 +00002561 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002562 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002563 if !exists("b:netrw_method") || b:netrw_method < 0
2564" call Dfunc("netrw#NetWrite : unsupported method")
2565 return
2566 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002567
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002568 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002569 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002570 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002571 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2572 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002573" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002574 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002575
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002576 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002577 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002578 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002579" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002580 if s:netrw_has_nt_rcp == 1
2581 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2582 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2583 else
2584 let uid_machine = g:netrw_machine .'.'. $USERNAME
2585 endif
2586 else
2587 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2588 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2589 else
2590 let uid_machine = g:netrw_machine
2591 endif
2592 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002593 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 +00002594 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002595
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002596 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002597 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002598 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002599" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002600 let netrw_fname = b:netrw_fname
2601
2602 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2603 let bhkeep = &l:bh
2604 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002605 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002607
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002608" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002609 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002610 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002612 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002613 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002614" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002615 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002616 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002619 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 +00002620 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002621" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2622 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 endif
2624 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2625 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002626 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002627 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002628 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002629 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002631
2632 " remove enew buffer (quietly)
2633 let filtbuf= bufnr("%")
2634 exe curbuf."b!"
2635 let &l:bh = bhkeep
2636 exe filtbuf."bw!"
2637
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002639
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002640 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002641 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002642 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002643 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002644" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002645 let netrw_fname = b:netrw_fname
2646 let bhkeep = &l:bh
2647
2648 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2649 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002650 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002651 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002652 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002653
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002654 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002655 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002656" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002657 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002658 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002660 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002661 if exists("g:netrw_uid") && g:netrw_uid != ""
2662 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002663 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002664" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002665 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002666 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002667 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002668" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002669 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002670 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002672 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002673 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002674 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002676 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002677 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002678" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002679 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002680 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002681" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002682 " save choice/id/password for future use
2683 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002684
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002685 " perform ftp:
2686 " -i : turns off interactive prompting from ftp
2687 " -n unix : DON'T use <.netrc>, even though it exists
2688 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002689 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002690 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002691 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2692 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002693 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002694 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002695 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002696 let mod=1
2697 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002698
2699 " remove enew buffer (quietly)
2700 let filtbuf= bufnr("%")
2701 exe curbuf."b!"
2702 let &l:bh= bhkeep
2703 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002704
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002705 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002706 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002707 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002708" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002709 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002710 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002711 else
2712 let useport= ""
2713 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002714 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 +00002715 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002716
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002717 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002718 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002719 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002720" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002721 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2722 if executable(curl)
2723 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002724 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 +01002725 elseif !exists("g:netrw_quiet")
Bram Moolenaar85850f32019-07-19 22:05:51 +02002726 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002727 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002728
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002729 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002730 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002731 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002732" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002733
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002734 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002735 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2736 let bhkeep = &l:bh
2737
2738 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2739 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002740 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002741 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002742
Bram Moolenaarff034192013-04-24 18:51:19 +02002743 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002744 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002745 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002746 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002747 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002748 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002749 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002750 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002751 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002752 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002753
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002754 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002755 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002756 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002757
2758 " remove enew buffer (quietly)
2759 let filtbuf= bufnr("%")
2760 exe curbuf."b!"
2761 let &l:bh = bhkeep
2762 exe filtbuf."bw!"
2763
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002764 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002765
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002766 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002767 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002768 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002769" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002770 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 +00002771 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002772
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002773 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002774 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002775 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002776" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002777 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2779 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2780 else
2781 let uid_machine = g:netrw_machine
2782 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002783
2784 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2785 let bhkeep = &l:bh
2786 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002787 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002788 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002789
Bram Moolenaarff034192013-04-24 18:51:19 +02002790 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002791 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002792" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002793 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002794 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002795 let filtbuf= bufnr("%")
2796 exe curbuf."b!"
2797 let &l:bh = bhkeep
2798 exe filtbuf."bw!"
2799 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002800
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002801 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002802 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002803 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002804 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002805 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002807 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002808
Bram Moolenaar5c736222010-01-06 20:54:52 +01002809 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002810" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002811 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002812" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002813 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002814 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002815 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002816
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002817 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002818 " restore modifiability; usually equivalent to set nomod
2819 let &mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002820" 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 +02002821 elseif !exists("leavemod")
2822 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002823" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002824 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002825" 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 +00002826 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002827
Bram Moolenaar9964e462007-05-05 17:54:07 +00002828" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002829endfun
2830
2831" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002832" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002833" uses NetRead to get a copy of the file into a temporarily file,
2834" then sources that file,
2835" then removes that file.
2836fun! netrw#NetSource(...)
2837" call Dfunc("netrw#NetSource() a:0=".a:0)
2838 if a:0 > 0 && a:1 == '?'
2839 " give help
2840 echomsg 'NetSource Usage:'
2841 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2842 echomsg ':Nsource fetch://machine/path uses fetch'
2843 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002844 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002845 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2846 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2847 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2848 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2849 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002850 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002851 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002852 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002853 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002854" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002855 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002856" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002857 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002858" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002859 if delete(s:netrw_tmpfile)
2860 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2861 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002862 unlet s:netrw_tmpfile
2863 else
2864 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2865 endif
2866 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002867 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002868 endif
2869" call Dret("netrw#NetSource")
2870endfun
2871
Bram Moolenaar8d043172014-01-23 14:24:41 +01002872" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002873" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2874" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002875fun! netrw#SetTreetop(iscmd,...)
2876" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2877" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002878
Bram Moolenaar85850f32019-07-19 22:05:51 +02002879 " iscmd==0: netrw#SetTreetop called using gn mapping
2880 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2881" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002882 " clear out the current tree
2883 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002884" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002885 let inittreetop= w:netrw_treetop
2886 unlet w:netrw_treetop
2887 endif
2888 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002889" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002890 unlet w:netrw_treedict
2891 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002892" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002893
Bram Moolenaar85850f32019-07-19 22:05:51 +02002894 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002895 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002897 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002898 if isdirectory(s:NetrwFile(a:1))
2899" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002900 let treedir = a:1
2901 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002902 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002903 let treedir = b:netrw_curdir."/".a:1
2904 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002905" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002906 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002907 " normally the cursor is left in the message window.
2908 " However, here this results in the directory being listed in the message window, which is not wanted.
2909 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002910 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002911 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002912 let treedir = "."
2913 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002914 endif
2915 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002916" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002917
2918 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002919 let islocal= expand("%") !~ '^\a\{3,}://'
2920" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002921
2922 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002923 if islocal
2924 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2925 else
2926 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2927 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002928
Bram Moolenaara6878372014-03-22 21:02:50 +01002929" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002930endfun
2931
Bram Moolenaar9964e462007-05-05 17:54:07 +00002932" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002933" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002934" readcmd == %r : replace buffer with newly read file
2935" == 0r : read file at top of buffer
2936" == r : read file after current line
2937" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002938fun! s:NetrwGetFile(readcmd, tfile, method)
2939" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002940
2941 " readcmd=='t': simply do nothing
2942 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002943" 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 +01002944" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002945 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002946 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002947
Bram Moolenaar9964e462007-05-05 17:54:07 +00002948 " get name of remote filename (ie. url and all)
2949 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002950" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002951
Bram Moolenaar9964e462007-05-05 17:54:07 +00002952 if exists("*NetReadFixup")
2953 " for the use of NetReadFixup (not otherwise used internally)
2954 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002955 endif
2956
Bram Moolenaar9964e462007-05-05 17:54:07 +00002957 if a:readcmd[0] == '%'
2958 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002959" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002960
2961 " rename the current buffer to the temp file (ie. tfile)
2962 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002963 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002964 else
2965 let tfile= a:tfile
2966 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002967 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002968
2969 " edit temporary file (ie. read the temporary file in)
2970 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002971" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002972 call zip#Browse(tfile)
2973 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002974" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002975 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002976 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002978 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002979 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002981 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002982 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002983" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002984 call tar#Browse(tfile)
2985 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002986" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002987 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002988 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002989" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002990 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002991 endif
2992
2993 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002994 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002995
Bram Moolenaar71badf92023-04-22 22:40:14 +01002996 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002997 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002998 " Note that isk must not include a "/" for scripts.vim
2999 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01003000" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
3001" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003002" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003003" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3004 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003005 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003006 filetype detect
3007" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3008 let &isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003009" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003010 let line1 = 1
3011 let line2 = line("$")
3012
Bram Moolenaar8d043172014-01-23 14:24:41 +01003013 elseif !&ma
3014 " 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 +01003015 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003016" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003017 return
3018
Bram Moolenaar9964e462007-05-05 17:54:07 +00003019 elseif s:FileReadable(a:tfile)
3020 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003021" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003022 let curline = line(".")
3023 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003024" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003025 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003026 let line1= curline + 1
3027 let line2= line("$") - lastline + 1
3028
3029 else
3030 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003031" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3032" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003033 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003034" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003035 return
3036 endif
3037
3038 " User-provided (ie. optional) fix-it-up command
3039 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003040" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003041 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003042" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003043" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003044 endif
3045
Bram Moolenaaradc21822011-04-01 18:03:16 +02003046 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003047 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003048 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003049 endif
3050
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003051" 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 +00003052
3053 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003054" redraw!
3055
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003056" 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 +00003057" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003058endfun
3059
Bram Moolenaar9964e462007-05-05 17:54:07 +00003060" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003061" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003062" Input:
3063" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3064" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003065" b:netrw_method= 1: rcp
3066" 2: ftp + <.netrc>
3067" 3: ftp + machine, id, password, and [path]filename
3068" 4: scp
3069" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003070" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003071" 7: rsync
3072" 8: fetch
3073" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003074" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003075" g:netrw_machine= hostname
3076" b:netrw_fname = filename
3077" g:netrw_port = optional port number (for ftp)
3078" g:netrw_choice = copy of input url (choice)
3079fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003080" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003081
Bram Moolenaar251e1912011-06-19 05:09:16 +02003082 " sanity check: choice should have at least three slashes in it
3083 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3084 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3085 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003086" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003087 return
3088 endif
3089
Bram Moolenaar5c736222010-01-06 20:54:52 +01003090 " record current g:netrw_machine, if any
3091 " curmachine used if protocol == ftp and no .netrc
3092 if exists("g:netrw_machine")
3093 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003094" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003095 else
3096 let curmachine= "N O T A HOST"
3097 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003098 if exists("g:netrw_port")
3099 let netrw_port= g:netrw_port
3100 endif
3101
3102 " insure that netrw_ftp_cmd starts off every method determination
3103 " with the current g:netrw_ftp_cmd
3104 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003105
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003106 " initialization
3107 let b:netrw_method = 0
3108 let g:netrw_machine = ""
3109 let b:netrw_fname = ""
3110 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003111 let g:netrw_choice = a:choice
3112
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003113 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003114 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003115 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3116 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003117 " rcpurm : rcp://[user@]host/filename Use rcp
3118 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003119 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003120 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003121 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003122 " rsyncurm : rsync://host[:port]/path Use rsync
3123 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3124 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003125 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3127 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003128 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3129 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003131 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003132 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003133 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003135 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003136 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003137 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003138
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003139" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003140 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003141 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003142 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003143" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003144 let b:netrw_method = 1
3145 let userid = substitute(a:choice,rcpurm,'\1',"")
3146 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3147 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003148 if userid != ""
3149 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003151
Bram Moolenaaradc21822011-04-01 18:03:16 +02003152 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003153 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003154" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003155 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003156 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3157 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3158 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003159
Bram Moolenaar15146672011-10-20 22:22:38 +02003160 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003161 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003162" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003163 let b:netrw_method = 5
3164 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3165 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003166 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003167
Bram Moolenaaradc21822011-04-01 18:03:16 +02003168 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003169 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003170" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003171 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003172 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003173 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3174 else
3175 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3176 endif
3177 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003178
Bram Moolenaaradc21822011-04-01 18:03:16 +02003179 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003180 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003181" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003182 let b:netrw_method = 7
3183 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3184 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003185
Bram Moolenaaradc21822011-04-01 18:03:16 +02003186 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003187 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003188" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003189 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003190 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3191 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3192 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003193" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003194 if userid != ""
3195 let g:netrw_uid= userid
3196 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003197
Bram Moolenaaradc21822011-04-01 18:03:16 +02003198 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003199 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003200 call NetUserPass("ftp:".g:netrw_machine)
3201 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003202 " if there's a change in hostname, require password re-entry
3203 unlet s:netrw_passwd
3204 endif
3205 if exists("netrw_port")
3206 unlet netrw_port
3207 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003208 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003209
Bram Moolenaar446cb832008-06-24 21:56:24 +00003210 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003211 let b:netrw_method = 3
3212 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003213 let host= substitute(g:netrw_machine,'\..*$','','')
3214 if exists("s:netrw_hup[host]")
3215 call NetUserPass("ftp:".host)
3216
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003217 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003218" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3219" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003220 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003221 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003222" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003223 endif
3224 let b:netrw_method= 2
3225 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003226" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003227 let b:netrw_method= 2
3228 else
3229 if !exists("g:netrw_uid") || g:netrw_uid == ""
3230 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003231 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003232 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003233 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003234 endif
3235 let b:netrw_method= 3
3236 endif
3237 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003238
Bram Moolenaaradc21822011-04-01 18:03:16 +02003239 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003240 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003241" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003242 let b:netrw_method = 8
3243 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3244 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3245 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3246 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003247
Bram Moolenaaradc21822011-04-01 18:03:16 +02003248 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003249 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003250" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003252 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3253 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003254 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003255 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003256 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003257
Bram Moolenaaradc21822011-04-01 18:03:16 +02003258 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003259 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003260" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003261 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003262 let b:netrw_method = 3
3263 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3264 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003265
Bram Moolenaar9964e462007-05-05 17:54:07 +00003266 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003267 let b:netrw_method = 2
3268 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3269 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3270 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003271
Bram Moolenaaradc21822011-04-01 18:03:16 +02003272 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003273 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003274" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003275 let b:netrw_method = 9
3276 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3277 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003278
Bram Moolenaaradc21822011-04-01 18:03:16 +02003279 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003280 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003281" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003282 let b:netrw_method = 1
3283 let userid = substitute(a:choice,rcphf,'\2',"")
3284 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3285 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003286" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3287" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3288" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3289" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003290 if userid != ""
3291 let g:netrw_uid= userid
3292 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003293
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003294 " Method#10: file://user@hostname/...path-to-file {{{3
3295 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003296" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003297 let b:netrw_method = 10
3298 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003299" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003300
Bram Moolenaaradc21822011-04-01 18:03:16 +02003301 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003302 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003303 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003304 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003305 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003306 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003308 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003309
Bram Moolenaar81695252004-12-29 20:58:21 +00003310 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003311 " remove any leading [:#] from port number
3312 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3313 elseif exists("netrw_port")
3314 " retain port number as implicit for subsequent ftp operations
3315 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003316 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003317
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003318" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3319" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3320" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3321" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003322" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003323" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003324" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003325" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003326" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003327" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003328" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003329" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331
3332" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003333" NetReadFixup: this sort of function is typically written by the user {{{2
3334" to handle extra junk that their system's ftp dumps
3335" into the transfer. This function is provided as an
3336" example and as a fix for a Windows 95 problem: in my
3337" experience, win95's ftp always dumped four blank lines
3338" at the end of the transfer.
3339if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3340 fun! NetReadFixup(method, line1, line2)
3341" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003342
3343 " sanity checks -- attempt to convert inputs to integers
3344 let method = a:method + 0
3345 let line1 = a:line1 + 0
3346 let line2 = a:line2 + 0
3347 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3348" call Dret("NetReadFixup")
3349 return
3350 endif
3351
Bram Moolenaar9964e462007-05-05 17:54:07 +00003352 if method == 3 " ftp (no <.netrc>)
3353 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003354 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003355 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003356 call histdel("/",-1)
3357 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003358 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003359
Bram Moolenaar9964e462007-05-05 17:54:07 +00003360" call Dret("NetReadFixup")
3361 endfun
3362endif
3363
3364" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003365" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003366" Usage: :call NetUserPass() -- will prompt for userid and password
3367" :call NetUserPass("uid") -- will prompt for password
3368" :call NetUserPass("uid","password") -- sets global userid and password
3369" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3370" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371fun! NetUserPass(...)
3372
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003373" call Dfunc("NetUserPass() a:0=".a:0)
3374
3375 if !exists('s:netrw_hup')
3376 let s:netrw_hup= {}
3377 endif
3378
Bram Moolenaar071d4272004-06-13 20:20:40 +00003379 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003380 " case: no input arguments
3381
3382 " change host and username if not previously entered; get new password
3383 if !exists("g:netrw_machine")
3384 let g:netrw_machine= input('Enter hostname: ')
3385 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003386 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003387 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388 let g:netrw_uid= input('Enter username: ')
3389 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003390 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003391 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003392
3393 " set up hup database
3394 let host = substitute(g:netrw_machine,'\..*$','','')
3395 if !exists('s:netrw_hup[host]')
3396 let s:netrw_hup[host]= {}
3397 endif
3398 let s:netrw_hup[host].uid = g:netrw_uid
3399 let s:netrw_hup[host].passwd = s:netrw_passwd
3400
3401 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003402 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003403
3404 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003405 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003406 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003407" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003408 let host = substitute(a:1,'^ftp:','','')
3409 let host = substitute(host,'\..*','','')
3410 if exists("s:netrw_hup[host]")
3411 let g:netrw_uid = s:netrw_hup[host].uid
3412 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003413" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3414" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003415 else
3416 let g:netrw_uid = input("Enter UserId: ")
3417 let s:netrw_passwd = inputsecret("Enter Password: ")
3418 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003419
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003420 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003421 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003422" 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 +02003423 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003424 if g:netrw_machine =~ '[0-9.]\+'
3425 let host= g:netrw_machine
3426 else
3427 let host= substitute(g:netrw_machine,'\..*$','','')
3428 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003429 else
3430 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003431 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003432 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003433" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003434 if exists("g:netrw_passwd")
3435 " ask for password if one not previously entered
3436 let s:netrw_passwd= g:netrw_passwd
3437 else
3438 let s:netrw_passwd = inputsecret("Enter Password: ")
3439 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003440 endif
3441
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003442" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003443 if exists("host")
3444 if !exists('s:netrw_hup[host]')
3445 let s:netrw_hup[host]= {}
3446 endif
3447 let s:netrw_hup[host].uid = g:netrw_uid
3448 let s:netrw_hup[host].passwd = s:netrw_passwd
3449 endif
3450
3451 elseif a:0 == 2
3452 let g:netrw_uid = a:1
3453 let s:netrw_passwd = a:2
3454
3455 elseif a:0 == 3
3456 " enter hostname, user-id, and password into the hup dictionary
3457 let host = substitute(a:1,'^\a\+:','','')
3458 let host = substitute(host,'\..*$','','')
3459 if !exists('s:netrw_hup[host]')
3460 let s:netrw_hup[host]= {}
3461 endif
3462 let s:netrw_hup[host].uid = a:2
3463 let s:netrw_hup[host].passwd = a:3
3464 let g:netrw_uid = s:netrw_hup[host].uid
3465 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003466" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3467" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003468 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003469
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003470" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472
Bram Moolenaar85850f32019-07-19 22:05:51 +02003473" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003474" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003475" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003477" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003478" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3479fun! s:ExplorePatHls(pattern)
3480" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3481 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003482" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003483 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003484" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003485 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3486" call Dret("s:ExplorePatHls repat<".repat.">")
3487 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003488endfun
3489
3490" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003491" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003492" 0: (user: <mb>) bookmark current directory
3493" 1: (user: <gb>) change to the bookmarked directory
3494" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003495" 3: (browsing) records current directory history
3496" 4: (user: <u>) go up (previous) directory, using history
3497" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003498" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003499fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003500" 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 +02003501 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3502" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3503 return
3504 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003505
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003506 let ykeep = @@
3507 let curbufnr = bufnr("%")
3508
Bram Moolenaar9964e462007-05-05 17:54:07 +00003509 if a:chg == 0
3510 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003511" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003512 if exists("s:netrwmarkfilelist_{curbufnr}")
3513 call s:NetrwBookmark(0)
3514 echo "bookmarked marked files"
3515 else
3516 call s:MakeBookmark(a:curdir)
3517 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003518 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003519
KSR-Yasudaf4498252023-10-06 03:34:17 +09003520 try
3521 call s:NetrwBookHistSave()
3522 catch
3523 endtry
3524
Bram Moolenaar9964e462007-05-05 17:54:07 +00003525 elseif a:chg == 1
3526 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003527" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003528 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003529" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003530 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003531 else
3532 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3533 endif
3534
3535 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003536" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003537 let didwork= 0
3538 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003539" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003540 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003541" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003542 let cnt= 1
3543 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003544" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003545 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003546 let didwork = 1
3547 let cnt = cnt + 1
3548 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003549 endif
3550
3551 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003552 " Note: history is saved only when PerformListing is done;
3553 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3554 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003555 let first = 1
3556 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003557 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003558 while ( first || cnt != g:netrw_dirhistcnt )
3559" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003560 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003561" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003562 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003563 let didwork= 1
3564 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003565 let histcnt = histcnt + 1
3566 let first = 0
3567 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003568 if cnt < 0
3569 let cnt= cnt + g:netrw_dirhistmax
3570 endif
3571 endwhile
3572 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003573 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003574 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003575 if didwork
3576 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3577 endif
3578
3579 elseif a:chg == 3
3580 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003581" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003582 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 +02003583 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003584 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3585 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003586 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003587" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003588 endif
3589
3590 elseif a:chg == 4
3591 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003592" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003593 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003594 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3595 if g:netrw_dirhistcnt < 0
3596 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003597 endif
3598 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003599 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003600 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003601 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3602" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003603 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003604 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003605" call Decho("setl ma noro",'~'.expand("<slnum>"))
3606 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003607 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003608" call Decho("setl nomod",'~'.expand("<slnum>"))
3609" 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 +00003610 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003611" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3612 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003613 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003614 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003615 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003616 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003617 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003618 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003619 echo "Sorry, no predecessor directory exists yet"
3620 endif
3621
3622 elseif a:chg == 5
3623 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003624" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003625 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003626 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3627 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3628" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003629 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003630" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003631 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003632 sil! NetrwKeepj %d _
3633" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3634" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003635 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003636" 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 +02003637 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003638" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3639 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003640 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003641 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3642 if g:netrw_dirhistcnt < 0
3643 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003644 endif
3645 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003646 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003647 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003648 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003649 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003650 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003651
3652 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003653" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003654 if exists("s:netrwmarkfilelist_{curbufnr}")
3655 call s:NetrwBookmark(1)
3656 echo "removed marked files from bookmarks"
3657 else
3658 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003659 let iremove = v:count
3660 let dremove = g:netrw_bookmarklist[iremove - 1]
3661" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003662 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003663" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3664 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3665 echo "removed ".dremove." from g:netrw_bookmarklist"
3666" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003667 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003668" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003669
3670 try
3671 call s:NetrwBookHistSave()
3672 catch
3673 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003674 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003675 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003676 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003677 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003678" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003679endfun
3680
3681" ---------------------------------------------------------------------
3682" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003683" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003684" Sister function: s:NetrwBookHistSave()
3685fun! s:NetrwBookHistRead()
3686" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003687 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003688" 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 +02003689 return
3690 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003691 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003692
3693 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003694 if !exists("s:netrw_initbookhist")
3695 let home = s:NetrwHome()
3696 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003697 if filereadable(s:NetrwFile(savefile))
3698" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003699 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003700 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003701
3702 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003703 if g:netrw_dirhistmax > 0
3704 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003705 if filereadable(s:NetrwFile(savefile))
3706" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003707 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003708 endif
3709 let s:netrw_initbookhist= 1
3710 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003711 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003712 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003713
Bram Moolenaar97d62492012-11-15 21:28:22 +01003714 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003715" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3716" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003717" call Dret("s:NetrwBookHistRead")
3718endfun
3719
3720" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003721" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003722" Sister function: s:NetrwBookHistRead()
3723" I used to do this via viminfo but that appears to
3724" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003725" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3726" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003727" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003728fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003729" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003730 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003731" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003732 return
3733 endif
3734
Bram Moolenaar5c736222010-01-06 20:54:52 +01003735 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003736" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003737 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003738
3739 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003740 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003741" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003742 if g:netrw_use_noswf
3743 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3744 else
3745 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3746 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003747 setl nocin noai noci magic nospell nohid wig= noaw
3748 setl ma noro write
3749 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003750 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003751
Bram Moolenaar85850f32019-07-19 22:05:51 +02003752 " rename enew'd file: .netrwhist -- no attempt to merge
3753 " record dirhistmax and current dirhistcnt
3754 " save history
3755" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003756 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003757 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003758 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3759 if g:netrw_dirhistmax > 0
3760 let lastline = line("$")
3761 let cnt = g:netrw_dirhistcnt
3762 let first = 1
3763 while ( first || cnt != g:netrw_dirhistcnt )
3764 let lastline= lastline + 1
3765 if exists("g:netrw_dirhist_{cnt}")
3766 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3767" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3768 endif
3769 let first = 0
3770 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3771 if cnt < 0
3772 let cnt= cnt + g:netrw_dirhistmax
3773 endif
3774 endwhile
3775 exe "sil! w! ".savefile
3776" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3777 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003778
Bram Moolenaar85850f32019-07-19 22:05:51 +02003779 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003780 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003781 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003782" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003783 " merge and write .netrwbook
3784 let savefile= s:NetrwHome()."/.netrwbook"
3785
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003786 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003787 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003788 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003789 for bdm in booklist
3790 if index(g:netrw_bookmarklist,bdm) == -1
3791 call add(g:netrw_bookmarklist,bdm)
3792 endif
3793 endfor
3794 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003795 endif
3796
3797 " construct and save .netrwbook
3798 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003799 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003800" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003801 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003802
3803 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003804 let bgone= bufnr("%")
3805 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003806 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003807
3808" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003809endfun
3810
3811" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003812" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3813" list of the contents of a local or remote directory. It is assumed that the
3814" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3815" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003816" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003817fun! s:NetrwBrowse(islocal,dirname)
3818 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003819" 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 +02003820" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3821" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3822" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003823
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003824 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3825 " This is useful when one edits a local file, then :e ., then :Rex
3826 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3827 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003828" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003829 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003830
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003831 " s:NetrwBrowse : initialize history {{{3
3832 if !exists("s:netrw_initbookhist")
3833 NetrwKeepj call s:NetrwBookHistRead()
3834 endif
3835
3836 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003837 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003838 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003839" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003840 else
3841 let dirname= a:dirname
3842 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003843
Bram Moolenaar85850f32019-07-19 22:05:51 +02003844 " repoint t:netrw_lexbufnr if appropriate
3845 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3846" call Decho("set repointlexbufnr to true!")
3847 let repointlexbufnr= 1
3848 endif
3849
3850 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003851 if exists("s:netrw_skipbrowse")
3852 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003853" 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 +01003854" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003855 return
3856 endif
3857 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003858 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003859" call Dret("s:NetrwBrowse : missing shellescape()")
3860 return
3861 endif
3862 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003863 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003864" call Dret("s:NetrwBrowse : missing fnameescape()")
3865 return
3866 endif
3867
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003868 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003869 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003870
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003871 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003872 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3873 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3874" call Decho("clearing marked files",'~'.expand("<slnum>"))
3875 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3876 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003877 endif
3878
3879 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003880 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003881" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3882" 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 +02003883 if s:NetrwLcd(dirname)
3884" call Dret("s:NetrwBrowse : lcd failure")
3885 return
3886 endif
3887 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003888" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003889
Bram Moolenaar5c736222010-01-06 20:54:52 +01003890 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003891 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003892" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003893 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003894" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003895 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003896 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003897 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003898" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003899
3900 " remove any filetype indicator from end of dirname, except for the
3901 " "this is a directory" indicator (/).
3902 " There shouldn't be one of those here, anyway.
3903 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003904" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003905 call s:RemotePathAnalysis(dirname)
3906
3907 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3908 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003909 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003910 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003911" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003912 let b:netrw_curdir = dirname
3913 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003914 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003915 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3916 sil call netrw#NetRead(2,url)
3917 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003918" call Decho("url<".url.">",'~'.expand("<slnum>"))
3919" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3920" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003921 if s:path =~ '.bz2'
3922 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3923 elseif s:path =~ '.gz'
3924 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3925 elseif s:path =~ '.gz'
3926 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3927 else
3928 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3929 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003930 endif
3931
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003932 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003933 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003934 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003935" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003936 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003937" 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 +00003938
Bram Moolenaar446cb832008-06-24 21:56:24 +00003939" call Dret("s:NetrwBrowse : file<".s:fname.">")
3940 return
3941 endif
3942
Bram Moolenaaradc21822011-04-01 18:03:16 +02003943 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003944 call s:UseBufWinVars()
3945
3946 " set up some variables {{{3
3947 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003948 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003949 let s:last_sort_by = g:netrw_sort_by
3950
3951 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003952 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003953
Bram Moolenaar97d62492012-11-15 21:28:22 +01003954 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003955" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003956 let svpos = winsaveview()
3957" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003958 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003959
Bram Moolenaar446cb832008-06-24 21:56:24 +00003960 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003961 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3962 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3963" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3964" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3965 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3966 else
3967" " call Decho("2match none",'~'.expand("<slnum>"))
3968 2match none
3969 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003970 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003971 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003972 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003973" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003974 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003975" 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 +01003976" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003977 return
3978 endif
3979
3980 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003981" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003982 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003983 if b:netrw_curdir =~ '[/\\]$'
3984 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3985 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003986 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3987 let b:netrw_curdir= b:netrw_curdir."/"
3988 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003989 if b:netrw_curdir == ''
3990 if has("amiga")
3991 " On the Amiga, the empty string connotes the current directory
3992 let b:netrw_curdir= getcwd()
3993 else
3994 " under unix, when the root directory is encountered, the result
3995 " from the preceding substitute is an empty string.
3996 let b:netrw_curdir= '/'
3997 endif
3998 endif
3999 if !a:islocal && b:netrw_curdir !~ '/$'
4000 let b:netrw_curdir= b:netrw_curdir.'/'
4001 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004002" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004003
4004 " ------------
4005 " (local only) {{{3
4006 " ------------
4007 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004008" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004009
4010 " Set up ShellCmdPost handling. Append current buffer to browselist
4011 call s:LocalFastBrowser()
4012
4013 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
4014 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004015" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
4016" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004017 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004018 if s:NetrwLcd(b:netrw_curdir)
4019" call Dret("s:NetrwBrowse : lcd failure")
4020 return
4021 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004022 endif
4023 endif
4024
4025 " --------------------------------
4026 " remote handling: {{{3
4027 " --------------------------------
4028 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004029" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004030
Bram Moolenaar97d62492012-11-15 21:28:22 +01004031 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004032" 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 +02004033 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004034 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004035" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004036 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4037 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4038 if dirname !~ '/$'
4039 let dirname= dirname.'/'
4040 endif
4041 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004042" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004043 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004044 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004045" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004046 endif
4047
4048 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4049 if dirname !~ dirpat
4050 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004051 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004052 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004053 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004054" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004055 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004056" 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 +00004057" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4058 return
4059 endif
4060 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004061" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004062 endif " (additional remote handling)
4063
Bram Moolenaar85850f32019-07-19 22:05:51 +02004064 " -------------------------------
4065 " Perform Directory Listing: {{{3
4066 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004067 NetrwKeepj call s:NetrwMaps(a:islocal)
4068 NetrwKeepj call s:NetrwCommands(a:islocal)
4069 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004070
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004071 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004072 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004073" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4074
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004075 " If there is a rexposn: restore position with rexposn
4076 " Otherwise : set rexposn
4077 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004078" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4079 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4080 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4081 NetrwKeepj exe w:netrw_bannercnt
4082 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004083 else
4084 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4085 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004086 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004087 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004088" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004089 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004090 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004091
Bram Moolenaar85850f32019-07-19 22:05:51 +02004092 " repoint t:netrw_lexbufnr if appropriate
4093 if exists("repointlexbufnr")
4094 let t:netrw_lexbufnr= bufnr("%")
4095" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4096 endif
4097
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004098 " restore position
4099 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004100" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4101 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004102 endif
4103
Bram Moolenaara6878372014-03-22 21:02:50 +01004104 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004105 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4106 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004107" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4108" 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 +02004109" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004110 return
4111endfun
4112
4113" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4115" may not apply correctly; ie. netrw's idea of the current directory may
4116" differ from vim's. This function insures that netrw's idea of the current
4117" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004118" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004119fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004120" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4121" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4122" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4123" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4124" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004125
4126 " clean up any leading treedepthstring
4127 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4128 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004129" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004130 else
4131 let fname= a:fname
4132 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004133
4134 if g:netrw_keepdir
4135 " vim's idea of the current directory possibly may differ from netrw's
4136 if !exists("b:netrw_curdir")
4137 let b:netrw_curdir= getcwd()
4138 endif
4139
4140 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004141 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004142 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004143 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004144" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004145 else
4146 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004147 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004148" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004149 endif
4150
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004152 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004153 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004154" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004155 else
4156 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004157 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004158" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004159 endif
4160 else
4161 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004162 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004163" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4164" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4165" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004166 endif
4167
Bram Moolenaar85850f32019-07-19 22:05:51 +02004168" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004169 return ret
4170endfun
4171
4172" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004173" s:NetrwFileInfo: supports qf (query for file information) {{{2
4174fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004175" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004176 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004177 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004178 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004179 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004180 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004181 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004182 let lsopt= "-lsadh --si"
4183 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004184" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004185 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004186
4187 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004188 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004189" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004190
Bram Moolenaara6878372014-03-22 21:02:50 +01004191 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004192 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004193" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004194
4195 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004196 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004197" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004198
Bram Moolenaar446cb832008-06-24 21:56:24 +00004199 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004200" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004201 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004202" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004203 endif
4204 else
4205 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004206" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4207 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004208 let fname= substitute(a:fname,".$","","")
4209 else
4210 let fname= a:fname
4211 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004212 let t = getftime(s:NetrwFile(fname))
4213 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004214 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004215 let sz= s:NetrwHumanReadable(sz)
4216 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004217 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4218" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004219 endif
4220 else
4221 echo "sorry, \"qf\" not supported yet for remote files"
4222 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004223 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004224" call Dret("s:NetrwFileInfo")
4225endfun
4226
4227" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004228" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4229fun! s:NetrwFullPath(filename)
4230" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4231 let filename= a:filename
4232 if filename !~ '^/'
4233 let filename= resolve(getcwd().'/'.filename)
4234 endif
4235 if filename != "/" && filename =~ '/$'
4236 let filename= substitute(filename,'/$','','')
4237 endif
4238" " call Dret("s:NetrwFullPath <".filename.">")
4239 return filename
4240endfun
4241
4242" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004243" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004244" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004245" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004246" 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 +00004247fun! s:NetrwGetBuffer(islocal,dirname)
4248" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004249" 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 +02004250" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4251" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004252 let dirname= a:dirname
4253
4254 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004255" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004256 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004257" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004258 let s:netrwbuf= {}
4259 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004260" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4261" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4262
4263 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4264 let bufnum = -1
4265
4266 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4267 if has_key(s:netrwbuf,"NetrwTreeListing")
4268 let bufnum= s:netrwbuf["NetrwTreeListing"]
4269 else
4270 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4271 endif
4272" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4273 if !bufexists(bufnum)
4274 call remove(s:netrwbuf,"NetrwTreeListing"])
4275 let bufnum= -1
4276 endif
4277 elseif bufnr("NetrwTreeListing") != -1
4278 let bufnum= bufnr("NetrwTreeListing")
4279" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4280 else
4281" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4282 let bufnum= -1
4283 endif
4284
4285 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004286 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004287" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004288 if !bufexists(bufnum)
4289 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4290 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004291 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004292
Bram Moolenaar446cb832008-06-24 21:56:24 +00004293 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004294" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004295 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004296 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004297" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4298
Bram Moolenaar71badf92023-04-22 22:40:14 +01004299 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004300 " IF the buffer already has the desired name
4301 " AND it is empty
4302 let curbuf = bufname("%")
4303 if curbuf == '.'
4304 let curbuf = getcwd()
4305 endif
4306" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004307" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004308" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4309" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4310" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4311" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4312 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004313" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4314 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004315 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004316" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004317 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004318 " 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 +00004319
4320 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004321 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004322" 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 +00004323 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004324" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004325 " name the buffer
4326 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4327 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004328" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004329 let w:netrw_treebufnr = bufnr("%")
4330 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004331 if g:netrw_use_noswf
4332 setl nobl bt=nofile noswf
4333 else
4334 setl nobl bt=nofile
4335 endif
4336 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4337 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4338 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4339 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004340" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004341 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004342 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004343 " enter the new buffer into the s:netrwbuf dictionary
4344 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4345" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4346" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004347 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004348" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004349
4350 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004351" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004352 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004353 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004354 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004355
4356 if &ft == "netrw"
4357" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4358 exe "sil! NetrwKeepj noswapfile b ".bufnum
4359" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004360 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004361" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4362 call s:NetrwEditBuf(bufnum)
4363" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004364 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004365" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004366 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004367 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004368 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004369
4370 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004371 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004372
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004373 if line("$") <= 1 && getline(1) == ""
4374 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004375 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004376" 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>"))
4377" 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 +01004378" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4379 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004380
Bram Moolenaar97d62492012-11-15 21:28:22 +01004381 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004382" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004383 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004384 sil NetrwKeepj %d _
4385" 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>"))
4386" 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 +01004387" 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 +00004388 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004389
Bram Moolenaar446cb832008-06-24 21:56:24 +00004390 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004391" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4392" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004393 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004394 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004395 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004396" 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>"))
4397" 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 +01004398" 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 +00004399 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004400
Bram Moolenaar446cb832008-06-24 21:56:24 +00004401 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004402" 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>"))
4403" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4404" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004405 return 1
4406 endif
4407 endif
4408
4409 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4410 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4411 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4412 " med 1 D H
4413 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004414" 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 +00004415 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004416 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004417 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004418
4419 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004420" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4421" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4422 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004423
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004424" 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>"))
4425" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4426" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004427 return 0
4428endfun
4429
4430" ---------------------------------------------------------------------
4431" s:NetrwGetcwd: get the current directory. {{{2
4432" Change backslashes to forward slashes, if any.
4433" If doesc is true, escape certain troublesome characters
4434fun! s:NetrwGetcwd(doesc)
4435" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4436 let curdir= substitute(getcwd(),'\\','/','ge')
4437 if curdir !~ '[\/]$'
4438 let curdir= curdir.'/'
4439 endif
4440 if a:doesc
4441 let curdir= fnameescape(curdir)
4442 endif
4443" call Dret("NetrwGetcwd <".curdir.">")
4444 return curdir
4445endfun
4446
4447" ---------------------------------------------------------------------
4448" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4449fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004450" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4451" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4452 let keepsol= &l:sol
4453 setl nosol
4454
Bram Moolenaar446cb832008-06-24 21:56:24 +00004455 call s:UseBufWinVars()
4456
4457 " insure that w:netrw_liststyle is set up
4458 if !exists("w:netrw_liststyle")
4459 if exists("g:netrw_liststyle")
4460 let w:netrw_liststyle= g:netrw_liststyle
4461 else
4462 let w:netrw_liststyle= s:THINLIST
4463 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004464" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004465 endif
4466
4467 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4468 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004469" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004470 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004471 let dirname= "./"
4472 let curline= getline('.')
4473
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004474 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004475 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004476 let s:netrw_skipbrowse= 1
4477 echo 'Pressing "s" also works'
4478
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004479 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004480 let s:netrw_skipbrowse= 1
4481 echo 'Press "S" to edit sorting sequence'
4482
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004483 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004484 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004485 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004486
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004487 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004488 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489 let s:netrw_skipbrowse= 1
4490 echo 'Pressing "a" also works'
4491
4492 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004493 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004494 endif
4495
4496 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004497" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004498 NetrwKeepj norm! 0
4499 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004500
4501 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004502" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004503 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004504 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4505
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004506 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004507" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004508 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004509 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004510
4511 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004512" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004513 let dirname= getline('.')
4514
4515 if !exists("b:netrw_cpf")
4516 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004517 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 +01004518 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004519" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004520 endif
4521
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004522" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004523 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004524" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4525" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004526 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004527 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004528 else
4529 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004530 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004531 endif
4532 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004533 let eofname= filestart + b:netrw_cpf + 1
4534 if eofname <= col("$")
4535 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004536 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004537 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004538 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004539 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004540 let dirname = @a
4541 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004542" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004543 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004544" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545 endif
4546
4547 " symlinks are indicated by a trailing "@". Remove it before further processing.
4548 let dirname= substitute(dirname,"@$","","")
4549
4550 " executables are indicated by a trailing "*". Remove it before further processing.
4551 let dirname= substitute(dirname,"\*$","","")
4552
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004553 let &l:sol= keepsol
4554
Bram Moolenaar446cb832008-06-24 21:56:24 +00004555" call Dret("s:NetrwGetWord <".dirname.">")
4556 return dirname
4557endfun
4558
4559" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004560" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4561" g:netrw_bufsettings will be used after the listing is produced.
4562" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004563fun! s:NetrwListSettings(islocal)
4564" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004565" 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 +00004566 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004567" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4568 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4569 setl bt=nofile nobl ma nonu nowrap noro nornu
4570 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004571 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004572 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004573 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004574" call Dredir("ls!","s:NetrwListSettings")
4575" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004576 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004577 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004578 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004579 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004580 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004581 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004582 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004583" 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 +00004584" call Dret("s:NetrwListSettings")
4585endfun
4586
4587" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004588" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004589" islocal=0: remote browsing
4590" =1: local browsing
4591fun! s:NetrwListStyle(islocal)
4592" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004593
Bram Moolenaar97d62492012-11-15 21:28:22 +01004594 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004595 let fname = s:NetrwGetWord()
4596 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004597 let svpos = winsaveview()
4598" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004599 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004600" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4601" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4602" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004603
Bram Moolenaar85850f32019-07-19 22:05:51 +02004604 " repoint t:netrw_lexbufnr if appropriate
4605 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4606" call Decho("set repointlexbufnr to true!")
4607 let repointlexbufnr= 1
4608 endif
4609
Bram Moolenaar446cb832008-06-24 21:56:24 +00004610 if w:netrw_liststyle == s:THINLIST
4611 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004612" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004613 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4614
4615 elseif w:netrw_liststyle == s:LONGLIST
4616 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004617" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004618 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4619
4620 elseif w:netrw_liststyle == s:WIDELIST
4621 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004622" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004623 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4624
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004625 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004626" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004627 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4628
4629 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004630 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004631 let g:netrw_liststyle = s:THINLIST
4632 let w:netrw_liststyle = g:netrw_liststyle
4633 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4634 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004635 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004636" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004637
4638 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004639" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4640 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004641 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004642" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004643 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004644" 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 +00004645
4646 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004647" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004648 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004649 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004650
Bram Moolenaar85850f32019-07-19 22:05:51 +02004651 " repoint t:netrw_lexbufnr if appropriate
4652 if exists("repointlexbufnr")
4653 let t:netrw_lexbufnr= bufnr("%")
4654" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4655 endif
4656
Bram Moolenaar13600302014-05-22 18:26:40 +02004657 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004658" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4659 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004660 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004661
4662" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4663endfun
4664
4665" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004666" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4667fun! s:NetrwBannerCtrl(islocal)
4668" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4669
Bram Moolenaar97d62492012-11-15 21:28:22 +01004670 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004671 " toggle the banner (enable/suppress)
4672 let g:netrw_banner= !g:netrw_banner
4673
4674 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004675 let svpos= winsaveview()
4676" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004677 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4678
4679 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004680 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4681 let fname= s:NetrwGetWord()
4682 sil NetrwKeepj $
4683 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4684" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4685 if result <= 0 && exists("w:netrw_bannercnt")
4686 exe "NetrwKeepj ".w:netrw_bannercnt
4687 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004688 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004689 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004690" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4691endfun
4692
4693" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004694" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4695"
4696" No bang: enters files/directories into Netrw's bookmark system
4697" No argument and in netrw buffer:
4698" if there are marked files: bookmark marked files
4699" otherwise : bookmark file/directory under cursor
4700" No argument and not in netrw buffer: bookmarks current open file
4701" Has arguments: globs them individually and bookmarks them
4702"
4703" With bang: deletes files/directories from Netrw's bookmark system
4704fun! s:NetrwBookmark(del,...)
4705" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4706 if a:0 == 0
4707 if &ft == "netrw"
4708 let curbufnr = bufnr("%")
4709
4710 if exists("s:netrwmarkfilelist_{curbufnr}")
4711 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004712" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004713 let svpos = winsaveview()
4714" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004715 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004716 for fname in s:netrwmarkfilelist_{curbufnr}
4717 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4718 endfor
4719 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4720 call s:NetrwUnmarkList(curbufnr,curdir)
4721 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004722" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4723 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004724 else
4725 let fname= s:NetrwGetWord()
4726 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4727 endif
4728
4729 else
4730 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004731" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004732 let fname= expand("%")
4733 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4734 endif
4735
4736 else
4737 " bookmark specified files
4738 " attempts to infer if working remote or local
4739 " by deciding if the current file begins with an url
4740 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004741 let islocal= expand("%") !~ '^\a\{3,}://'
4742" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004743 let i = 1
4744 while i <= a:0
4745 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004746 if v:version > 704 || (v:version == 704 && has("patch656"))
4747 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004748 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004749 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004750 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004751 else
4752 let mbfiles= [a:{i}]
4753 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004754" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004755 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004756" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004757 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4758 endfor
4759 let i= i + 1
4760 endwhile
4761 endif
4762
4763 " update the menu
4764 call s:NetrwBookmarkMenu()
4765
4766" call Dret("s:NetrwBookmark")
4767endfun
4768
4769" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004770" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4771" .2.[cnt] for bookmarks, and
4772" .3.[cnt] for history
4773" (see s:NetrwMenu())
4774fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004775 if !exists("s:netrw_menucnt")
4776 return
4777 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004778" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004779
4780 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004781 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004782 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004783" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004784 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4785 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004786 endif
4787 if !exists("s:netrw_initbookhist")
4788 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004789 endif
4790
4791 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004792 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004793 let cnt= 1
4794 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004795" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004796 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004797
4798 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004799 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004800
4801 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004802 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 +01004803 let cnt= cnt + 1
4804 endfor
4805
4806 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004807
4808 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004809 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004810 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004811 let first = 1
4812 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004813 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004814 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004815 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004816 if exists("g:netrw_dirhist_{cnt}")
4817 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004818" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004819 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4820 endif
4821 let first = 0
4822 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4823 if cnt < 0
4824 let cnt= cnt + g:netrw_dirhistmax
4825 endif
4826 endwhile
4827 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004828
Bram Moolenaar9964e462007-05-05 17:54:07 +00004829 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004830" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004831endfun
4832
4833" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004834" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4835" directory and a new directory name. Also, if the
4836" "new directory name" is actually a file,
4837" NetrwBrowseChgDir() edits the file.
4838fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004839" 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 +01004840" 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 +00004841
Bram Moolenaar97d62492012-11-15 21:28:22 +01004842 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004843 if !exists("b:netrw_curdir")
4844 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4845 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004846 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004847" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4848" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004849" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004850" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004851 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004852 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004853" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004854
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004855 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004856" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004857 call s:SavePosn(s:netrw_posn)
4858 NetrwKeepj call s:NetrwOptionsSave("s:")
4859 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004860 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004861 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004862 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004863 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004864 endif
4865 let newdir = a:newdir
4866 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004867 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004868" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004869" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004870" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004871
4872 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004873" 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 +01004874 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004875" 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 +01004876 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004877 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004878" 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 +01004879 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004880" 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 +02004881 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004882 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004883 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004884 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004885" 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 +01004886 endif
4887 endif
4888" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004889" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004890 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004891
Bram Moolenaar446cb832008-06-24 21:56:24 +00004892 " set up o/s-dependent directory recognition pattern
4893 if has("amiga")
4894 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004895 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004896 let dirpat= '[\/]$'
4897 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004898" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004899
4900 if dirname !~ dirpat
4901 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004902 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004904" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004905 endif
4906
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004907" 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 +01004908 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004909 " ------------------------------
4910 " NetrwBrowseChgDir: edit a file {{{3
4911 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004912" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004913
Bram Moolenaar97d62492012-11-15 21:28:22 +01004914 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004915 let s:rexposn_{bufnr("%")}= winsaveview()
4916" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004917" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4918" 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 +01004919
Bram Moolenaar446cb832008-06-24 21:56:24 +00004920 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004921" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4922" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004923" let newdir = s:NetrwTreePath(s:netrw_treetop)
4924" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004925 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004926 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4927" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4928 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004929 if dirname =~ '/$'
4930 let dirname= dirname.newdir
4931 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004932 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004933 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004934" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4935" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004936 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004937" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004938 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004939 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004940 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004941 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004942" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004943 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004944 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004945" 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 +02004946 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004947 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004948 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004949" " 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 +01004950 if type(g:netrw_browse_split) == 3
4951 " open file in server
4952 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004953" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004954 call s:NetrwServerEdit(a:islocal,dirname)
4955" call Dret("s:NetrwBrowseChgDir")
4956 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004957
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004958 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004959 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004960" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004961 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4962 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004963 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004964 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004965 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004966 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004967
Bram Moolenaar446cb832008-06-24 21:56:24 +00004968 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004969 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004970" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004971 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4972 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004973 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004974 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004975 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004976 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004977
Bram Moolenaar446cb832008-06-24 21:56:24 +00004978 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004979 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004980" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004981 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004982 if !exists("b:netrw_curdir")
4983 let b:netrw_curdir= getcwd()
4984 endif
4985 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004986
Bram Moolenaar446cb832008-06-24 21:56:24 +00004987 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004988 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004989" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004990 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004991 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004992" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004993 return
4994 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004995 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004996
Bram Moolenaar9964e462007-05-05 17:54:07 +00004997 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004998 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004999" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005000 call s:NetrwMenu(0)
5001 " optional change to window
5002 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005003" 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 +02005004 if winnr("$")+1 == g:netrw_chgwin
5005 " if g:netrw_chgwin is set to one more than the last window, then
5006 " vertically split the last window to make that window available.
5007 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005008 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
Bram Moolenaar13600302014-05-22 18:26:40 +02005009 vs
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005010 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02005011 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005012 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00005013 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005014 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00005015 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005016
Bram Moolenaar9964e462007-05-05 17:54:07 +00005017 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005018
Bram Moolenaar446cb832008-06-24 21:56:24 +00005019 " the point where netrw actually edits the (local) file
5020 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01005021 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005022 if !&mod
5023 " if e the new file would fail due to &mod, then don't change any of the flags
5024 let dolockout= 1
5025 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005026 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005027" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005028 " some like c-^ to return to the last edited file
5029 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005030 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5031 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005032 call s:NetrwEditFile("e","",dirname)
5033" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005034 " COMBAK -- cuc cul related
5035 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005036 if &hidden || &bufhidden == "hide"
5037 " file came from vim's hidden storage. Don't "restore" options with it.
5038 let dorestore= 0
5039 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005040 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005041" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005042 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005043
5044 " handle g:Netrw_funcref -- call external-to-netrw functions
5045 " This code will handle g:Netrw_funcref as an individual function reference
5046 " or as a list of function references. It will ignore anything that's not
5047 " a function reference. See :help Funcref for information about function references.
5048 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005049" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005050 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005051" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005052 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005053 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005054" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005055 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005056 if type(Fncref) == 2
5057 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005058 endif
5059 endfor
5060 endif
5061 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005062 endif
5063
5064 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005065 " ----------------------------------------------------
5066 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5067 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005068" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005069 let dirname = newdir
5070 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005071 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005072 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005073
5074 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005075 " ---------------------------------------------
5076 " NetrwBrowseChgDir: refresh the directory list {{{3
5077 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005078" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005079 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005080 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005081
5082 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005083 " --------------------------------------
5084 " NetrwBrowseChgDir: go up one directory {{{3
5085 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005086" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005087
5088 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5089 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005090" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5091" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005092 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005093 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005094 endif
5095
5096 if has("amiga")
5097 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005098" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005099 if a:islocal
5100 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5101 let dirname= substitute(dirname,'/$','','')
5102 else
5103 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5104 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005105" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005106
Bram Moolenaar8d043172014-01-23 14:24:41 +01005107 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
5108 " windows
5109 if a:islocal
5110 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5111 if dirname == ""
5112 let dirname= '/'
5113 endif
5114 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005115 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005116 endif
5117 if dirname =~ '^\a:$'
5118 let dirname= dirname.'/'
5119 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005120" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005121
Bram Moolenaar446cb832008-06-24 21:56:24 +00005122 else
5123 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005124" 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 +00005125 if a:islocal
5126 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5127 if dirname == ""
5128 let dirname= '/'
5129 endif
5130 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005131 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005133" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005134 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005135 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005136 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005137
5138 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005139 " --------------------------------------
5140 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5141 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005142" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005143 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5144" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005145 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005146 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005147" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5148 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005149 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005150 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005151" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005152 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005153 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005154" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005155
5156 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005157" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005158 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005159" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 let haskey= 1
5161 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005162" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005163 endif
5164
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005165 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005166" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005167 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005168 if has_key(w:netrw_treedict,treedir."/")
5169 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005170" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171 let haskey = 1
5172 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005173" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005174 endif
5175 endif
5176
5177 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005178" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005179 if !haskey && treedir =~ '/$'
5180 let treedir= substitute(treedir,'/$','','')
5181 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005182" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005183 let haskey = 1
5184 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005185" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005186 endif
5187 endif
5188
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005189" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005190 if haskey
5191 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005192" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005193 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005194" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5195" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005196 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005197 else
5198 " go down one directory
5199 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005200" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5201" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005202 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005203 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005204" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005205 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005206
5207 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005208 " ----------------------------------------
5209 " NetrwBrowseChgDir: Go down one directory {{{3
5210 " ----------------------------------------
5211 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005212" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005213 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005214 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005215 endif
5216
Bram Moolenaar97d62492012-11-15 21:28:22 +01005217 " --------------------------------------
5218 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5219 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005220 if dorestore
5221 " dorestore is zero'd when a local file was hidden or bufhidden;
5222 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005223" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005224 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005225" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005226" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005227 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005228 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005229" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005230 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005231" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5232" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005233 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005234" 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 +02005235 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005236" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5237" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005238 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005239" 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 +02005240 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005241 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005242 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005243 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005244
Bram Moolenaar446cb832008-06-24 21:56:24 +00005245" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5246 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005247endfun
5248
5249" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005250" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5251" for thin, long, and wide: cursor placed just after banner
5252" for tree, keeps cursor on current filename
5253fun! s:NetrwBrowseUpDir(islocal)
5254" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005255 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5256 " this test needed because occasionally this function seems to be incorrectly called
5257 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005258 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005259 " directories.
5260" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5261 return
5262 endif
5263
Bram Moolenaara6878372014-03-22 21:02:50 +01005264 norm! 0
5265 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005266" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005267 let curline= getline(".")
5268 let swwline= winline() - 1
5269 if exists("w:netrw_treetop")
5270 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005271 elseif exists("b:netrw_curdir")
5272 let w:netrw_treetop= b:netrw_curdir
5273 else
5274 let w:netrw_treetop= getcwd()
5275 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005276 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005277 let curfile = getline(".")
5278 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005279 if a:islocal
5280 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5281 else
5282 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5283 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005284" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5285" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5286 if w:netrw_treetop == '/'
5287 keepj call search('^\M'.curfile,"w")
5288 elseif curfile == '../'
5289 keepj call search('^\M'.curfile,"wb")
5290 else
5291" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5292 while 1
5293 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5294 let treepath= s:NetrwTreePath(w:netrw_treetop)
5295" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5296 if treepath == curpath
5297 break
5298 endif
5299 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005300 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005301
Bram Moolenaara6878372014-03-22 21:02:50 +01005302 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005303" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005304 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005305 if exists("b:netrw_curdir")
5306 let curdir= b:netrw_curdir
5307 else
5308 let curdir= expand(getcwd())
5309 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005310 if a:islocal
5311 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5312 else
5313 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5314 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005315 call s:RestorePosn(s:netrw_posn)
5316 let curdir= substitute(curdir,'^.*[\/]','','')
5317 call search('\<'.curdir.'/','wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005318 endif
5319" call Dret("s:NetrwBrowseUpDir")
5320endfun
5321
5322" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005323" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005324" given filename; typically this means given their extension.
5325" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005326fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005327 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005328" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005329
Bram Moolenaar91359012019-11-30 17:57:03 +01005330 if a:remote == 0 && isdirectory(a:fname)
5331 " if its really just a local directory, then do a "gf" instead
5332" 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 +01005333" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5334 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005335" call Dret("netrw#BrowseX")
5336 return
5337 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5338 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5339" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5340" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5341" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5342" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5343 norm! gf
5344" call Dret("netrw#BrowseX")
5345 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005346 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005347" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005348
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005349 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5350 let remote = a:remote
5351 else
5352 let remote = 0
5353 endif
5354
Bram Moolenaar97d62492012-11-15 21:28:22 +01005355 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005356 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005357" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005358
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005359 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5360 let awkeep = &aw
5361 set noaw
5362
Bram Moolenaar5c736222010-01-06 20:54:52 +01005363 " special core dump handler
5364 if a:fname =~ '/core\(\.\d\+\)\=$'
5365 if exists("g:Netrw_corehandler")
5366 if type(g:Netrw_corehandler) == 2
5367 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005368" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005369 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005370 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005371 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005372" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005373 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005374 if type(Fncref) == 2
5375 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005376 endif
5377 endfor
5378 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005379" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005380 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005381 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005382 let &aw= awkeep
5383" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005384 return
5385 endif
5386 endif
5387
Bram Moolenaar446cb832008-06-24 21:56:24 +00005388 " set up the filename
5389 " (lower case the extension, make a local copy of a remote file)
5390 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5391 if has("win32") || has("win95") || has("win64") || has("win16")
5392 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005393 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005394 if exten =~ "[\\/]"
5395 let exten= ""
5396 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005397" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005398
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005399 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005400 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005401" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005402 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005403 call netrw#NetRead(3,a:fname)
5404 " attempt to rename tempfile
5405 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005406 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005407" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5408" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005409 if s:netrw_tmpfile != newname && newname != ""
5410 if rename(s:netrw_tmpfile,newname) == 0
5411 " renaming succeeded
5412" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5413 let fname= newname
5414 else
5415 " renaming failed
5416" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5417 let fname= s:netrw_tmpfile
5418 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005419 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005420 let fname= s:netrw_tmpfile
5421 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005422 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005423" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005424 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005425 " special ~ handler for local
5426 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005427" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5428 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005429 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005430 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005431" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5432" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005433
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005434 " set up redirection (avoids browser messages)
5435 " by default, g:netrw_suppress_gx_mesg is true
5436 if g:netrw_suppress_gx_mesg
5437 if &srr =~ "%s"
5438 if (has("win32") || has("win95") || has("win64") || has("win16"))
5439 let redir= substitute(&srr,"%s","nul","")
5440 else
5441 let redir= substitute(&srr,"%s","/dev/null","")
5442 endif
5443 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5444 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005445 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005446 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005447 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005448 else
5449 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005450 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005451" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005452
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005453 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005454 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005455" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005456 if g:netrw_browsex_viewer =~ '\s'
5457 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5458 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5459 let oviewer = ''
5460 let cnt = 1
5461 while !executable(viewer) && viewer != oviewer
5462 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5463 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5464 let cnt = cnt + 1
5465 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005466" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005467 endwhile
5468 else
5469 let viewer = g:netrw_browsex_viewer
5470 let viewopt = ""
5471 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005472" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005473 endif
5474
5475 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005476" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005477 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005478" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005479 let ret= netrwFileHandlers#Invoke(exten,fname)
5480
5481 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005482" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005483 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005484 let ret= v:shell_error
5485
5486 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005487" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005488 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005489 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005490 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005491 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005492 else
5493 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5494 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005495 let ret= v:shell_error
5496
Bram Moolenaar97d62492012-11-15 21:28:22 +01005497 elseif has("win32unix")
5498 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005499" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005500 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005501" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005502 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005503 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005504" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005505 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005506 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005507" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005508 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005509 else
5510 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5511 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005512 let ret= v:shell_error
5513
Bram Moolenaar85850f32019-07-19 22:05:51 +02005514 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005515" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5516 if a:fname =~ '^https\=://'
5517 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5518 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005519" call Decho("fname<".fname.">")
5520" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005521 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5522
5523 else
5524 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5525 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005526 let ret= v:shell_error
5527
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005528 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5529" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5530 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5531 let ret= v:shell_error
5532
5533 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5534" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5535 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5536 let ret= v:shell_error
5537
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005538 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005539" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005540 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005541 let ret= v:shell_error
5542
5543 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005544" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005545 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005546 let ret= v:shell_error
5547
5548 else
5549 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005550" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005551 let ret= netrwFileHandlers#Invoke(exten,fname)
5552 endif
5553
5554 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5555 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005556" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005557 let ret= netrwFileHandlers#Invoke(exten,fname)
5558 endif
5559
Bram Moolenaarc236c162008-07-13 17:41:49 +00005560 " restoring redraw! after external file handlers
5561 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005562
5563 " cleanup: remove temporary file,
5564 " delete current buffer if success with handler,
5565 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005566 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005567 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005568" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005569"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005570" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005571" endif
5572
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005573 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005574 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005575 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005576 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005577 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005578 if use_ctrlo
5579 exe "sil! NetrwKeepj norm! \<c-o>"
5580 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005581 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005582" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005583 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005584 let @@ = ykeep
5585 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005586
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005587" call Dret("netrw#BrowseX")
5588endfun
5589
5590" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005591" netrw#GX: gets word under cursor for gx support {{{2
5592" See also: netrw#BrowseXVis
5593" netrw#BrowseX
5594fun! netrw#GX()
5595" call Dfunc("netrw#GX()")
5596 if &ft == "netrw"
5597 let fname= s:NetrwGetWord()
5598 else
5599 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5600 endif
5601" call Dret("netrw#GX <".fname.">")
5602 return fname
5603endfun
5604
5605" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005606" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5607fun! netrw#BrowseXVis()
5608" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005609 let akeep = @a
5610 norm! gv"ay
5611 let gxfile= @a
5612 let @a = akeep
5613 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005614" call Dret("netrw#BrowseXVis")
5615endfun
5616
5617" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005618" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5619" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5620" to become an unlisted buffer, so in that case don't bwipe it.
5621fun! s:NetrwBufRename(newname)
5622" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5623" call Dredir("ls!","s:NetrwBufRename (before rename)")
5624 let oldbufname= bufname(bufnr("%"))
5625" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5626
5627 if oldbufname != a:newname
5628" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5629 let b:junk= 1
5630" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5631 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005632" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005633 let oldbufnr= bufnr(oldbufname)
5634" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5635" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5636 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5637" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5638 exe "bwipe! ".oldbufnr
5639" else " Decho
5640" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005641" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5642" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5643" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005644 endif
5645" call Dredir("ls!","s:NetrwBufRename (after rename)")
5646" else " Decho
5647" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5648 endif
5649
5650" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5651endfun
5652
5653" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005654" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005655fun! netrw#CheckIfRemote(...)
5656" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5657 if a:0 > 0
5658 let curfile= a:1
5659 else
5660 let curfile= expand("%")
5661 endif
5662" call Decho("curfile<".curfile.">")
5663 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005664" call Dret("netrw#CheckIfRemote 1")
5665 return 1
5666 else
5667" call Dret("netrw#CheckIfRemote 0")
5668 return 0
5669 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005670endfun
5671
5672" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005673" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5674fun! s:NetrwChgPerm(islocal,curdir)
5675" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005676 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005677 call inputsave()
5678 let newperm= input("Enter new permission: ")
5679 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005680 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5681 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5682" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005683 call system(chgperm)
5684 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005685 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005686 endif
5687 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005688 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005689 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005690 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005691" call Dret("s:NetrwChgPerm")
5692endfun
5693
5694" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005695" s:CheckIfKde: checks if kdeinit is running {{{2
5696" Returns 0: kdeinit not running
5697" 1: kdeinit is running
5698fun! s:CheckIfKde()
5699" call Dfunc("s:CheckIfKde()")
5700 " seems kde systems often have gnome-open due to dependencies, even though
5701 " gnome-open's subsidiary display tools are largely absent. Kde systems
5702 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5703 if !exists("s:haskdeinit")
5704 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005705 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005706 if v:shell_error
5707 let s:haskdeinit = 0
5708 endif
5709 else
5710 let s:haskdeinit= 0
5711 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005712" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005713 endif
5714
5715" call Dret("s:CheckIfKde ".s:haskdeinit)
5716 return s:haskdeinit
5717endfun
5718
5719" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005720" s:NetrwClearExplore: clear explore variables (if any) {{{2
5721fun! s:NetrwClearExplore()
5722" call Dfunc("s:NetrwClearExplore()")
5723 2match none
5724 if exists("s:explore_match") |unlet s:explore_match |endif
5725 if exists("s:explore_indx") |unlet s:explore_indx |endif
5726 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5727 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5728 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5729 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5730 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5731 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5732 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5733" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005734" call Dret("s:NetrwClearExplore")
5735endfun
5736
5737" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005738" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5739fun! s:NetrwEditBuf(bufnum)
5740" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5741 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5742" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5743 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5744 else
5745" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005746 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005747 endif
5748" call Dret("s:NetrwEditBuf")
5749endfun
5750
5751" ---------------------------------------------------------------------
5752" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5753" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5754fun! s:NetrwEditFile(cmd,opt,fname)
5755" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5756 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5757" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5758 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5759 else
5760" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5761 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5762 endif
5763" call Dret("s:NetrwEditFile")
5764endfun
5765
5766" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005767" s:NetrwExploreListUniq: {{{2
5768fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005769" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005770
5771 " this assumes that the list is already sorted
5772 let newexplist= []
5773 for member in a:explist
5774 if !exists("uniqmember") || member != uniqmember
5775 let uniqmember = member
5776 let newexplist = newexplist + [ member ]
5777 endif
5778 endfor
5779
Bram Moolenaar15146672011-10-20 22:22:38 +02005780" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005781 return newexplist
5782endfun
5783
5784" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005785" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5786fun! s:NetrwForceChgDir(islocal,newdir)
5787" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005788 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005789 if a:newdir !~ '/$'
5790 " ok, looks like force is needed to get directory-style treatment
5791 if a:newdir =~ '@$'
5792 let newdir= substitute(a:newdir,'@$','/','')
5793 elseif a:newdir =~ '[*=|\\]$'
5794 let newdir= substitute(a:newdir,'.$','/','')
5795 else
5796 let newdir= a:newdir.'/'
5797 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005798" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005799 else
5800 " should already be getting treatment as a directory
5801 let newdir= a:newdir
5802 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005803 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005804 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005805 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005806" call Dret("s:NetrwForceChgDir")
5807endfun
5808
5809" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005810" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005811" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5812" expr : this is the expression to follow the directory. Will use s:ComposePath()
5813" pare =1: remove the current directory from the resulting glob() filelist
5814" =0: leave the current directory in the resulting glob() filelist
5815fun! s:NetrwGlob(direntry,expr,pare)
5816" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005817 if netrw#CheckIfRemote()
5818 keepalt 1sp
5819 keepalt enew
5820 let keep_liststyle = w:netrw_liststyle
5821 let w:netrw_liststyle = s:THINLIST
5822 if s:NetrwRemoteListing() == 0
5823 keepj keepalt %s@/@@
5824 let filelist= getline(1,$)
5825 q!
5826 else
5827 " remote listing error -- leave treedict unchanged
5828 let filelist= w:netrw_treedict[a:direntry]
5829 endif
5830 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005831 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5832 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5833 if a:pare
5834 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5835 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005836 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005837 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5838 if a:pare
5839 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5840 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005841 endif
5842" call Dret("s:NetrwGlob ".string(filelist))
5843 return filelist
5844endfun
5845
5846" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005847" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5848fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005849" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005850 if a:newfile =~ '[/@*=|\\]$'
5851 let newfile= substitute(a:newfile,'.$','','')
5852 else
5853 let newfile= a:newfile
5854 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005855 if a:islocal
5856 call s:NetrwBrowseChgDir(a:islocal,newfile)
5857 else
5858 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5859 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005860" call Dret("s:NetrwForceFile")
5861endfun
5862
5863" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5865" and switches the hiding mode. The actual hiding is done by
5866" s:NetrwListHide().
5867" g:netrw_hide= 0: show all
5868" 1: show not-hidden files
5869" 2: show hidden files only
5870fun! s:NetrwHide(islocal)
5871" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005872 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005873 let svpos= winsaveview()
5874" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005875
5876 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005877" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5878" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005879
5880 " hide the files in the markfile list
5881 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005882" 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 +00005883 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5884 " remove fname from hiding list
5885 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5886 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5887 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005888" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005889 else
5890 " append fname to hiding list
5891 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5892 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5893 else
5894 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5895 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005896" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005897 endif
5898 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005899 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005900 let g:netrw_hide= 1
5901
5902 else
5903
5904 " switch between show-all/show-not-hidden/show-hidden
5905 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005906 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005907 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005908 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005909 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005910" call Dret("NetrwHide")
5911 return
5912 endif
5913 endif
5914
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005915 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005916" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5917 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005918 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005919" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005920endfun
5921
5922" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005923" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5924fun! s:NetrwHideEdit(islocal)
5925" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5926
5927 let ykeep= @@
5928 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005929 let svpos= winsaveview()
5930" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005931
5932 " get new hiding list from user
5933 call inputsave()
5934 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5935 call inputrestore()
5936 let g:netrw_list_hide= newhide
5937" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5938
5939 " refresh the listing
5940 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5941
5942 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005943" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5944 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005945 let @@= ykeep
5946
5947" call Dret("NetrwHideEdit")
5948endfun
5949
5950" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005951" s:NetrwHidden: invoked by "gh" {{{2
5952fun! s:NetrwHidden(islocal)
5953" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005954 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005955 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005956 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005957" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005958
5959 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005960 " remove .file pattern from hiding list
5961" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005962 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005963 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005964" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005965 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5966 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005967" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005968 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5969 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005970 if g:netrw_list_hide =~ '^,'
5971 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5972 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005973
5974 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005975 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005976" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5977 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005978 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005979" call Dret("s:NetrwHidden")
5980endfun
5981
5982" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005983" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5984fun! s:NetrwHome()
5985 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005986 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005987 else
5988 " go to vim plugin home
5989 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005990 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005991 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005992 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005993 let home= basehome."/.vim"
5994 break
5995 endif
5996 endfor
5997 if home == ""
5998 " just pick the first directory
5999 let home= substitute(&rtp,',.*$','','')
6000 endif
6001 if (has("win32") || has("win95") || has("win64") || has("win16"))
6002 let home= substitute(home,'/','\\','g')
6003 endif
6004 endif
6005 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006006 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006007" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006008 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02006009" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006010 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01006011 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006012" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006013 call mkdir(home)
6014 endif
6015 endif
6016 let g:netrw_home= home
6017 return home
6018endfun
6019
6020" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006021" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6022fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006023 if exists("s:netrwdrag")
6024 return
6025 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006026 if &ft != "netrw"
6027 return
6028 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006029" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006030
Bram Moolenaar97d62492012-11-15 21:28:22 +01006031 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006032 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006033 while getchar(0) != 0
6034 "clear the input stream
6035 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006036 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006037 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006038 let mouse_lnum = v:mouse_lnum
6039 let wlastline = line('w$')
6040 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006041" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6042" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006043 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6044 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006045 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006046" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6047 return
6048 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006049 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006050 " 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 +01006051 " without this test when its disabled.
6052 " 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 +01006053" 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 +01006054 if v:mouse_col > virtcol('.')
6055 let @@= ykeep
6056" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6057 return
6058 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006059
Bram Moolenaar446cb832008-06-24 21:56:24 +00006060 if a:islocal
6061 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006062 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006063 endif
6064 else
6065 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006066 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006067 endif
6068 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006069 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006070" call Dret("s:NetrwLeftmouse")
6071endfun
6072
6073" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006074" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6075fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006076 if &ft != "netrw"
6077 return
6078 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006079" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6080 call s:NetrwMarkFileTgt(a:islocal)
6081" call Dret("s:NetrwCLeftmouse")
6082endfun
6083
6084" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006085" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6086" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006087" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006088" a:islocal=2 : <c-r> used, remote
6089" a:islocal=3 : <c-r> used, local
6090fun! s:NetrwServerEdit(islocal,fname)
6091" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6092 let islocal = a:islocal%2 " =0: remote =1: local
6093 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006094" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006095
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006096 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006097 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006098 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006099" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006100 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006101 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006102 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6103 unlet s:netrw_browse_split_{winnr()}
6104 endif
6105 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6106" call Dret("s:NetrwServerEdit")
6107 return
6108 endif
6109
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006110" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006111 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006112" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006113
6114 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006115" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006116 let srvrname = g:netrw_browse_split[0]
6117 let tabnum = g:netrw_browse_split[1]
6118 let winnum = g:netrw_browse_split[2]
6119
6120 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006121" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006122
6123 if !ctrlr
6124 " user must have closed the server window and the user did not use <c-r>, but
6125 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006126" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006127 if exists("g:netrw_browse_split")
6128 unlet g:netrw_browse_split
6129 endif
6130 let g:netrw_browse_split= 0
6131 if exists("s:netrw_browse_split_".winnr())
6132 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6133 endif
6134 call s:NetrwBrowseChgDir(islocal,a:fname)
6135" call Dret("s:NetrwServerEdit")
6136 return
6137
6138 elseif has("win32") && executable("start")
6139 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006140" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006141 call system("start gvim --servername ".srvrname)
6142
6143 else
6144 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006145" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006146 call system("gvim --servername ".srvrname)
6147 endif
6148 endif
6149
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006150" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006151 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6152 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006153 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006154
6155 else
6156
6157 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6158
6159 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006160" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006161 if exists("g:netrw_browse_split")
6162 unlet g:netrw_browse_split
6163 endif
6164 let g:netrw_browse_split= 0
6165 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6166" call Dret("s:NetrwServerEdit")
6167 return
6168
6169 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006170" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006171 if has("win32") && executable("start")
6172 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006173" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006174 call system("start gvim --servername ".g:netrw_servername)
6175 else
6176 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006177" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006178 call system("gvim --servername ".g:netrw_servername)
6179 endif
6180 endif
6181 endif
6182
6183 while 1
6184 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006185" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6186 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006187 break
6188 catch /^Vim\%((\a\+)\)\=:E241/
6189 sleep 200m
6190 endtry
6191 endwhile
6192
6193 if exists("g:netrw_browse_split")
6194 if type(g:netrw_browse_split) != 3
6195 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6196 endif
6197 unlet g:netrw_browse_split
6198 endif
6199 let g:netrw_browse_split= [g:netrw_servername,1,1]
6200 endif
6201
6202 else
6203 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6204 endif
6205
6206" call Dret("s:NetrwServerEdit")
6207endfun
6208
6209" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006210" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6211fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006212 if &ft != "netrw"
6213 return
6214 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006215" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006216
Bram Moolenaar8d043172014-01-23 14:24:41 +01006217 let s:ngw= s:NetrwGetWord()
6218 call s:NetrwMarkFile(a:islocal,s:ngw)
6219
6220" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006221endfun
6222
6223" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006224" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6225" Used to mark multiple files.
6226fun! s:NetrwSLeftdrag(islocal)
6227" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6228 if !exists("s:netrwdrag")
6229 let s:netrwdrag = winnr()
6230 if a:islocal
6231 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006232 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006233 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006234 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006235 endif
6236 let ngw = s:NetrwGetWord()
6237 if !exists("s:ngw") || s:ngw != ngw
6238 call s:NetrwMarkFile(a:islocal,ngw)
6239 endif
6240 let s:ngw= ngw
6241" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6242endfun
6243
6244" ---------------------------------------------------------------------
6245" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6246fun! s:NetrwSLeftrelease(islocal)
6247" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6248 if exists("s:netrwdrag")
6249 nunmap <s-leftrelease>
6250 let ngw = s:NetrwGetWord()
6251 if !exists("s:ngw") || s:ngw != ngw
6252 call s:NetrwMarkFile(a:islocal,ngw)
6253 endif
6254 if exists("s:ngw")
6255 unlet s:ngw
6256 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006257 unlet s:netrwdrag
6258 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006259" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006260endfun
6261
6262" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006263" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6264" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006265fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006266" 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 +02006267" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006268 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006269
6270 " 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 +02006271 " How-it-works: take the hiding command, convert it into a range.
6272 " Duplicate characters don't matter.
6273 " Remove all such characters from the '/~@#...890' string.
6274 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006275" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006276 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006277 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006278" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006279
6280 while listhide != ""
6281 if listhide =~ ','
6282 let hide = substitute(listhide,',.*$','','e')
6283 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6284 else
6285 let hide = listhide
6286 let listhide = ""
6287 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006288" 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 +01006289 if g:netrw_sort_by =~ '^[ts]'
6290 if hide =~ '^\^'
6291" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6292 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6293 elseif hide =~ '^\\(\^'
6294 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6295 endif
6296" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6297 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006298
6299 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006300" 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 +00006301 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006302" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006303 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006304 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006305" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006306 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006307 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006308" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006309 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006310
Bram Moolenaar446cb832008-06-24 21:56:24 +00006311 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006312 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006313" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006314 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006315" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006316 endif
6317
Bram Moolenaaradc21822011-04-01 18:03:16 +02006318 " remove any blank lines that have somehow remained.
6319 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006320 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006321
Bram Moolenaar97d62492012-11-15 21:28:22 +01006322 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006323" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006324endfun
6325
6326" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006327" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006328" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006329fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006330" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006331
Bram Moolenaar97d62492012-11-15 21:28:22 +01006332 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006333 " get name of new directory from user. A bare <CR> will skip.
6334 " if its currently a directory, also request will be skipped, but with
6335 " a message.
6336 call inputsave()
6337 let newdirname= input("Please give directory name: ")
6338 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006339" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006340
6341 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006342 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006343" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006344 return
6345 endif
6346
6347 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006348" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006349
6350 " Local mkdir:
6351 " sanity checks
6352 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006353" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6354 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006355 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006356 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006357 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006358 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006359" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006360 return
6361 endif
6362 if s:FileReadable(fullnewdir)
6363 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006364 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006365 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006366 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006367" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006368 return
6369 endif
6370
6371 " requested new local directory is neither a pre-existing file or
6372 " directory, so make it!
6373 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006374 if has("unix")
6375 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6376 else
6377 call mkdir(fullnewdir,"p")
6378 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006379 else
6380 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006381 if s:NetrwLcd(b:netrw_curdir)
6382" call Dret("s:NetrwMakeDir : lcd failure")
6383 return
6384 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006385" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006386 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006387 if v:shell_error != 0
6388 let @@= ykeep
6389 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 +01006390" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006391 return
6392 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006393 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006394" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006395 if s:NetrwLcd(netrw_origdir)
6396" call Dret("s:NetrwBrowse : lcd failure")
6397 return
6398 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006399 endif
6400 endif
6401
6402 if v:shell_error == 0
6403 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006404" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006405 let svpos= winsaveview()
6406" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006407 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006408" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6409 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006410 elseif !exists("g:netrw_quiet")
6411 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6412 endif
6413" redraw!
6414
6415 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006416 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006417" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006418 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6419 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006420 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006421 if v:shell_error == 0
6422 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006423 let svpos= winsaveview()
6424" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006425 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006426" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6427 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006428 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006429 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006430 endif
6431" redraw!
6432
6433 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006434 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006435 let svpos= winsaveview()
6436" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006437" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006438 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006439" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006440 let remotepath= b:netrw_fname
6441 else
6442 let remotepath= ""
6443 endif
6444 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006445 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006446" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6447 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006448
Bram Moolenaar446cb832008-06-24 21:56:24 +00006449 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006450 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006451 let svpos= winsaveview()
6452" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006453" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006454 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006455" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006456 let remotepath= b:netrw_fname
6457 else
6458 let remotepath= ""
6459 endif
6460 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006461 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006462" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6463 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006464 endif
6465
Bram Moolenaar97d62492012-11-15 21:28:22 +01006466 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006467" call Dret("s:NetrwMakeDir")
6468endfun
6469
6470" ---------------------------------------------------------------------
6471" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6472fun! s:TreeSqueezeDir(islocal)
6473" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6474 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6475 " its a tree-listing style
6476 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006477 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006478 let depth = strchars(substitute(curdepth,' ','','g'))
6479 let srch = -1
6480" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6481" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006482" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006483" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6484 if depth >= 2
6485 NetrwKeepj norm! 0
6486 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6487 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6488" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6489" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6490 elseif depth == 1
6491 NetrwKeepj norm! 0
6492 let treedepthchr= substitute(s:treedepthstring,' ','','')
6493 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6494" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6495 endif
6496 if srch > 0
6497" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6498 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6499 exe srch
6500 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006501 endif
6502" call Dret("s:TreeSqueezeDir")
6503endfun
6504
6505" ---------------------------------------------------------------------
6506" s:NetrwMaps: {{{2
6507fun! s:NetrwMaps(islocal)
6508" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6509
Bram Moolenaar85850f32019-07-19 22:05:51 +02006510 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006511 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006512" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006513 if !hasmapto("<Plug>NetrwReturn")
6514 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006515" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006516 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6517 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006518" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006519 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6520 endif
6521 endif
6522 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006523" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006524 endif
6525
Bram Moolenaar85850f32019-07-19 22:05:51 +02006526 " generate default <Plug> maps {{{3
6527 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006528 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006529 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6530 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6531 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6532 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6533 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6534 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6535 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6536 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6537 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6538 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6539" ---------------------------------------------------------------------
6540" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6541" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6542" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6543" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6544" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6545" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6546" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6547" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6548" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6549" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6550" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6551" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6552" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6553" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6554" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6555" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6556" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6557" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6558" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6559" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6560" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6561" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6562" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6563" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6564" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6565" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6566" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6567" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6568" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6569" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6570" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6571" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6572" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6573" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6574" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6575" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6576" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6577" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6578" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6579" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6580" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6581" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6582" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6583" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6584" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6585" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6586" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6587
Bram Moolenaara6878372014-03-22 21:02:50 +01006588 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006589" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006590 " local normal-mode maps {{{3
6591 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6592 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6593 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6594 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6595 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6596 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6597 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6598 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6599 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6600 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6601 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6602" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006603 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6604 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6605 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006606 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006607 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006608 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6609 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6610 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6611 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006612 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6613 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6614 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6615 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6616 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6617 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6618 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6619 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6620 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6621 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6622 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6623 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6624 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006625 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006626 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006627 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6628 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6629 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6630 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6631 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006632 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006633 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006634 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6635 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006636 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6637 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6638 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006639 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006640 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006641 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6642 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006643 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006644 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006645 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6646 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6647 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006648 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6649 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006650
6651 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 +01006652 if !hasmapto('<Plug>NetrwHideEdit')
6653 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006654 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006655 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006656 if !hasmapto('<Plug>NetrwRefresh')
6657 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006658 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006659 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 +01006660 if s:didstarstar || !mapcheck("<s-down>","n")
6661 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006662 endif
6663 if s:didstarstar || !mapcheck("<s-up>","n")
6664 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006665 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006666 if !hasmapto('<Plug>NetrwTreeSqueeze')
6667 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006668 endif
6669 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006670 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6671 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006672 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6673 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6674 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6675 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6676 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6677 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6678 imap <buffer> <leftmouse> <Plug>ILeftmouse
6679 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006680 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006681 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006682 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006683 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006684 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006685 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
Bram Moolenaara6878372014-03-22 21:02:50 +01006686 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6687 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006688 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006689 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6690 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6691 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6692 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6693 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6694 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6695 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006696 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6697
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006698 " support user-specified maps
6699 call netrw#UserMaps(1)
6700
Bram Moolenaar85850f32019-07-19 22:05:51 +02006701 else
6702 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006703" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006704 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006705 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6706 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6707 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6708 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6709 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6710 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6711 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6712 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6713 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6714 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6715 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6716" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006717 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6718 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6719 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6720 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6721 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6722 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6723 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6724 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006725 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006726 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006727 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6728 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6729 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6730 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6731 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6732 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6733 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6734 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6735 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6736 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6737 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006738 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006739 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006740 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6741 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6742 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6743 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6744 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006745 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6746 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6747 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6748 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006749 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006750 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6751 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006752 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006753 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 +01006754 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6755 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6756 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6757 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6758 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6759 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6760 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6761 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6762 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006763 if !hasmapto('<Plug>NetrwHideEdit')
6764 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006765 endif
6766 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6767 if !hasmapto('<Plug>NetrwRefresh')
6768 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006769 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006770 if !hasmapto('<Plug>NetrwTreeSqueeze')
6771 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006772 endif
6773 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006774
6775 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006776 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006777
6778 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6779 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006780 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6781 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6782 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6783 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
6784 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6785 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6786 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6787 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6788 nmap <middlemouse> <Plug>NetrwMiddlemouse
6789 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6790 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6791 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6792 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006793 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006794 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
Bram Moolenaara6878372014-03-22 21:02:50 +01006795 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6796 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006797 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006798 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6799 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6800 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6801 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6802 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6803 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6804 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006805 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006806
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006807 " support user-specified maps
6808 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006809 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006810
6811" call Dret("s:NetrwMaps")
6812endfun
6813
6814" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006815" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006816" If -buffer, the command is only available from within netrw buffers
6817" Otherwise, the command is available from any window, so long as netrw
6818" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006819fun! s:NetrwCommands(islocal)
6820" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6821
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006822 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6823 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006824 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 +01006825 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006826 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006827 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006828 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006829 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006830 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006831
6832" call Dret("s:NetrwCommands")
6833endfun
6834
6835" ---------------------------------------------------------------------
6836" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6837" glob()ing only works with local files
6838fun! s:NetrwMarkFiles(islocal,...)
6839" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006840 let curdir = s:NetrwGetCurdir(a:islocal)
6841 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006842 while i <= a:0
6843 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006844 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006845 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006846 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006847 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006848 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006849 else
6850 let mffiles= [a:{i}]
6851 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006852" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006853 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006854" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006855 call s:NetrwMarkFile(a:islocal,mffile)
6856 endfor
6857 let i= i + 1
6858 endwhile
6859" call Dret("s:NetrwMarkFiles")
6860endfun
6861
6862" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006863" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006864fun! s:NetrwMarkTarget(...)
6865" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6866 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006867 let curdir = s:NetrwGetCurdir(1)
6868 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006869 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006870 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6871 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006872 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006873" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006874 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006875 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6876 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006877 let svpos = winsaveview()
6878" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006879 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006880" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6881 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006882" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006883endfun
6884
6885" ---------------------------------------------------------------------
6886" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6887" mark and unmark files. If a markfile list exists,
6888" then the rename and delete functions will use it instead
6889" of whatever may happen to be under the cursor at that
6890" moment. When the mouse and gui are available,
6891" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006892"
6893" Creates two lists
6894" s:netrwmarkfilelist -- holds complete paths to all marked files
6895" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6896"
6897" Creates a marked file match string
6898" s:netrwmarfilemtch_# -- used with 2match to display marked files
6899"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006900" Creates a buffer version of islocal
6901" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006902fun! s:NetrwMarkFile(islocal,fname)
6903" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006904" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006905
6906 " sanity check
6907 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006908" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006909 return
6910 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006911 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006912
Bram Moolenaar97d62492012-11-15 21:28:22 +01006913 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006914 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006915 if a:fname =~ '^\a'
6916 let leader= '\<'
6917 else
6918 let leader= ''
6919 endif
6920 if a:fname =~ '\a$'
6921 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6922 else
6923 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6924 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006925
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006926 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006927 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006928" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6929" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6930" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006931 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006932
6933 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006934 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006935" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006937 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006938
6939 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006940 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006941" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6943 if s:netrwmarkfilelist_{curbufnr} == []
6944 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006945" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006946 call s:NetrwUnmarkList(curbufnr,curdir)
6947 else
6948 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006949" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006950 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006951 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952 for fname in s:netrwmarkfilelist_{curbufnr}
6953 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006954 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006955 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006956 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006957 endif
6958 let first= 0
6959 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006960" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006961 endif
6962 endif
6963
6964 else
6965 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006966" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006967
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006968" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006970 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6971" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006972
6973 " build initial markfile matching pattern
6974 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006975 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006976 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006977 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006978 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006979" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006980 endif
6981
6982 " handle global markfilelist
6983 if exists("s:netrwmarkfilelist")
6984 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6985 if index(s:netrwmarkfilelist,dname) == -1
6986 " append new filename to global markfilelist
6987 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006988" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006989 else
6990 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006991" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6992" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006993 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006994" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006995 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006996" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006997 unlet s:netrwmarkfilelist
6998 endif
6999 endif
7000 else
7001 " initialize new global-directory markfilelist
7002 let s:netrwmarkfilelist= []
7003 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007004" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007005 endif
7006
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007007 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02007008 if has("syntax") && exists("g:syntax_on") && g:syntax_on
7009 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
7010" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
7011 if exists("g:did_drchip_netrwlist_syntax")
7012 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
7013 endif
7014 else
7015" " call Decho("2match none",'~'.expand("<slnum>"))
7016 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01007017 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007018 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007019 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007020" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
7021" 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 +00007022endfun
7023
7024" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007025" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7026" mA: move the argument list to marked file list (tomflist=1)
7027" Uses the global marked file list
7028fun! s:NetrwMarkFileArgList(islocal,tomflist)
7029" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7030
7031 let svpos = winsaveview()
7032" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7033 let curdir = s:NetrwGetCurdir(a:islocal)
7034 let curbufnr = bufnr("%")
7035
7036 if a:tomflist
7037 " mA: move argument list to marked file list
7038 while argc()
7039 let fname= argv(0)
7040" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7041 exe "argdel ".fnameescape(fname)
7042 call s:NetrwMarkFile(a:islocal,fname)
7043 endwhile
7044
7045 else
7046 " ma: move marked file list to argument list
7047 if exists("s:netrwmarkfilelist")
7048
7049 " for every filename in the marked list
7050 for fname in s:netrwmarkfilelist
7051" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7052 exe "argadd ".fnameescape(fname)
7053 endfor " for every file in the marked list
7054
7055 " unmark list and refresh
7056 call s:NetrwUnmarkList(curbufnr,curdir)
7057 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7058" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7059 NetrwKeepj call winrestview(svpos)
7060 endif
7061 endif
7062
7063" call Dret("s:NetrwMarkFileArgList")
7064endfun
7065
7066" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007067" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7068" compress/decompress files using the programs
7069" in g:netrw_compress and g:netrw_uncompress,
7070" using g:netrw_compress_suffix to know which to
7071" do. By default:
7072" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007073" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007074fun! s:NetrwMarkFileCompress(islocal)
7075" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007076 let svpos = winsaveview()
7077" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007078 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007079 let curbufnr = bufnr("%")
7080
Bram Moolenaarff034192013-04-24 18:51:19 +02007081 " sanity check
7082 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007083 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007084" call Dret("s:NetrwMarkFileCompress")
7085 return
7086 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007087" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007088
Bram Moolenaar446cb832008-06-24 21:56:24 +00007089 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007090
7091 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007092 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007093 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007094" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007095 if exists("g:netrw_decompress['".sfx."']")
7096 " fname has a suffix indicating that its compressed; apply associated decompression routine
7097 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007098" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007099 let exe= netrw#WinPath(exe)
7100 if a:islocal
7101 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007102 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007103 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007104 call system(exe." ".fname)
7105 if v:shell_error
7106 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007107 endif
7108 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007109 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7110 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007111 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007112
Bram Moolenaarff034192013-04-24 18:51:19 +02007113 endif
7114 unlet sfx
7115
Bram Moolenaar446cb832008-06-24 21:56:24 +00007116 if exists("exe")
7117 unlet exe
7118 elseif a:islocal
7119 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007120 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007121 if v:shell_error
7122 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7123 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007124 else
7125 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007126 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007127 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007128 endfor " for every file in the marked list
7129
Bram Moolenaar446cb832008-06-24 21:56:24 +00007130 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007131 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007132" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7133 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007134 endif
7135" call Dret("s:NetrwMarkFileCompress")
7136endfun
7137
7138" ---------------------------------------------------------------------
7139" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7140" If no marked files, then set up directory as the
7141" target. Currently does not support copying entire
7142" directories. Uses the local-buffer marked file list.
7143" Returns 1=success (used by NetrwMarkFileMove())
7144" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007145fun! s:NetrwMarkFileCopy(islocal,...)
7146" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7147
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007148 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007149 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007150 if b:netrw_curdir !~ '/$'
7151 if !exists("b:netrw_curdir")
7152 let b:netrw_curdir= curdir
7153 endif
7154 let b:netrw_curdir= b:netrw_curdir."/"
7155 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007156
Bram Moolenaarff034192013-04-24 18:51:19 +02007157 " sanity check
7158 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007159 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007160" call Dret("s:NetrwMarkFileCopy")
7161 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007162 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007163" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007164
Bram Moolenaar446cb832008-06-24 21:56:24 +00007165 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007166 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007167" call Dret("s:NetrwMarkFileCopy 0")
7168 return 0
7169 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007170" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007171
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007172 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007173 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007174" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007175 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007176 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7177" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7178 return
7179 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007180
7181 " copy marked files while within the same directory (ie. allow renaming)
7182 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7183 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7184 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007185" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007186 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007187 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7188 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007189" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007190 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007191 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007192 let oldname = a:1
7193 else
7194 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007195" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007196 let s:recursive= 1
7197 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7198 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7199 if ret == 0
7200 break
7201 endif
7202 endfor
7203 unlet s:recursive
7204 call s:NetrwUnmarkList(curbufnr,curdir)
7205" call Dret("s:NetrwMarkFileCopy ".ret)
7206 return ret
7207 endif
7208
7209 call inputsave()
7210 let newname= input("Copy ".oldname." to : ",oldname,"file")
7211 call inputrestore()
7212 if newname == ""
7213" call Dret("s:NetrwMarkFileCopy 0")
7214 return 0
7215 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007216 let args= s:ShellEscape(oldname)
7217 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007218 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007219 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7220 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007221 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007222 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7223 let args= substitute(args,'/','\\','g')
7224 let tgt = substitute(tgt, '/','\\','g')
7225 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007226 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7227 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7228 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7229 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7230" call Decho("args <".args.">",'~'.expand("<slnum>"))
7231" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007232 if isdirectory(s:NetrwFile(args))
7233" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007234 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007235" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007236 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7237 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7238 " contents to a target. One must append the source directory name to the target to get xcopy to
7239 " do the right thing.
7240 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007241" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007242 endif
7243 else
7244 let copycmd= g:netrw_localcopycmd
7245 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007246 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007247 let copycmd = substitute(copycmd,'\s.*$','','')
7248 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007249 let copycmd = netrw#WinPath(copycmd).copycmdargs
7250 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007251 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007252 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007253" call Decho("args <".args.">",'~'.expand("<slnum>"))
7254" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7255" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7256" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007257 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007258 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007259 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007260 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 +01007261 else
7262 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7263 endif
7264" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007265 return 0
7266 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007267
7268 elseif a:islocal && !s:netrwmftgt_islocal
7269 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007270" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007271 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007272
7273 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007274 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007275" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007276 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007277
7278 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007279 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007280" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007281 let curdir = getcwd()
7282 let tmpdir = s:GetTempfile("")
7283 if tmpdir !~ '/'
7284 let tmpdir= curdir."/".tmpdir
7285 endif
7286 if exists("*mkdir")
7287 call mkdir(tmpdir)
7288 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007289 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007290 if v:shell_error != 0
7291 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 +01007292" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007293 return
7294 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007295 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007296 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007297 if s:NetrwLcd(tmpdir)
7298" call Dret("s:NetrwMarkFileCopy : lcd failure")
7299 return
7300 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007301 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007302 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007303 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007304 if getcwd() == tmpdir
7305 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007306 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007307 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007308 if s:NetrwLcd(curdir)
7309" call Dret("s:NetrwMarkFileCopy : lcd failure")
7310 return
7311 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007312 if delete(tmpdir,"d")
7313 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007314 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007315 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007316 if s:NetrwLcd(curdir)
7317" call Dret("s:NetrwMarkFileCopy : lcd failure")
7318 return
7319 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007320 endif
7321 endif
7322 endif
7323
7324 " -------
7325 " cleanup
7326 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007327" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007328 " remove markings from local buffer
7329 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007330" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7331" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7332" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7333" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7334" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7335" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7336 if exists("s:recursive")
7337" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7338 else
7339" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007340 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007341 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007342 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007343 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007344 else
7345 " refresh local and targets for fast browsing
7346 if !exists("s:recursive")
7347 " remove markings from local buffer
7348" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7349 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7350 endif
7351
7352 " refresh buffers
7353 if s:netrwmftgt_islocal
7354" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7355 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7356 endif
7357 if a:islocal && s:netrwmftgt != curdir
7358" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7359 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7360 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007361 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007362
Bram Moolenaar446cb832008-06-24 21:56:24 +00007363" call Dret("s:NetrwMarkFileCopy 1")
7364 return 1
7365endfun
7366
7367" ---------------------------------------------------------------------
7368" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7369" invoke vim's diff mode on the marked files.
7370" Either two or three files can be so handled.
7371" Uses the global marked file list.
7372fun! s:NetrwMarkFileDiff(islocal)
7373" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7374 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007375
Bram Moolenaarff034192013-04-24 18:51:19 +02007376 " sanity check
7377 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007378 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007379" call Dret("s:NetrwMarkFileDiff")
7380 return
7381 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007382 let curdir= s:NetrwGetCurdir(a:islocal)
7383" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007384
Bram Moolenaara6878372014-03-22 21:02:50 +01007385 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007386 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007387 for fname in s:netrwmarkfilelist
7388 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007389 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007390" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007391 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007392 diffthis
7393 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007394 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007395" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007396 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007397 diffthis
7398 else
7399 break
7400 endif
7401 endfor
7402 call s:NetrwUnmarkList(curbufnr,curdir)
7403 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007404
Bram Moolenaar446cb832008-06-24 21:56:24 +00007405" call Dret("s:NetrwMarkFileDiff")
7406endfun
7407
7408" ---------------------------------------------------------------------
7409" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7410" Uses global markfilelist
7411fun! s:NetrwMarkFileEdit(islocal)
7412" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7413
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007414 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007415 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007416
7417 " sanity check
7418 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007419 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007420" call Dret("s:NetrwMarkFileEdit")
7421 return
7422 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007423" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007424
Bram Moolenaar446cb832008-06-24 21:56:24 +00007425 if exists("s:netrwmarkfilelist_{curbufnr}")
7426 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007427 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007428 " unmark markedfile list
7429" call s:NetrwUnmarkList(curbufnr,curdir)
7430 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007431" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007432 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007433 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007434 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007435
Bram Moolenaar446cb832008-06-24 21:56:24 +00007436" call Dret("s:NetrwMarkFileEdit")
7437endfun
7438
7439" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007440" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007441fun! s:NetrwMarkFileQFEL(islocal,qfel)
7442" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7443 call s:NetrwUnmarkAll()
7444 let curbufnr= bufnr("%")
7445
7446 if !empty(a:qfel)
7447 for entry in a:qfel
7448 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007449" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007450 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007451" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007452 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7453 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7454 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7455 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007456" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007457 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7458 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007459" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007460 endif
7461 endfor
7462 echo "(use me to edit marked files)"
7463 else
7464 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7465 endif
7466
7467" call Dret("s:NetrwMarkFileQFEL")
7468endfun
7469
7470" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007471" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7472" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7473" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7474fun! s:NetrwMarkFileExe(islocal,enbloc)
7475" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007476 let svpos = winsaveview()
7477" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007478 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007479 let curbufnr = bufnr("%")
7480
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007481 if a:enbloc == 0
7482 " individually apply command to files, one at a time
7483 " sanity check
7484 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7485 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7486" call Dret("s:NetrwMarkFileExe")
7487 return
7488 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007489" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007490
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007491 if exists("s:netrwmarkfilelist_{curbufnr}")
7492 " get the command
7493 call inputsave()
7494 let cmd= input("Enter command: ","","file")
7495 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007496" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007497 if cmd == ""
7498" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7499 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007500 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007501
7502 " apply command to marked files, individually. Substitute: filename -> %
7503 " If no %, then append a space and the filename to the command
7504 for fname in s:netrwmarkfilelist_{curbufnr}
7505 if a:islocal
7506 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007507 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007508 endif
7509 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007510 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007511 endif
7512 if cmd =~ '%'
7513 let xcmd= substitute(cmd,'%',fname,'g')
7514 else
7515 let xcmd= cmd.' '.fname
7516 endif
7517 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007518" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007519 let ret= system(xcmd)
7520 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007521" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007522 let ret= s:RemoteSystem(xcmd)
7523 endif
7524 if v:shell_error < 0
7525 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7526 break
7527 else
7528 echo ret
7529 endif
7530 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007531
7532 " unmark marked file list
7533 call s:NetrwUnmarkList(curbufnr,curdir)
7534
7535 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007536 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007537" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7538 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007539 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007540 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007541 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007542
7543 else " apply command to global list of files, en bloc
7544
7545 call inputsave()
7546 let cmd= input("Enter command: ","","file")
7547 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007548" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007549 if cmd == ""
7550" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7551 return
7552 endif
7553 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007554 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007555 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007556 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007557 endif
7558 if a:islocal
7559 call system(cmd)
7560 if v:shell_error < 0
7561 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7562 endif
7563 else
7564 let ret= s:RemoteSystem(cmd)
7565 endif
7566 call s:NetrwUnmarkAll()
7567
7568 " refresh the listing
7569 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007570" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7571 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007572
7573 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007574
Bram Moolenaar446cb832008-06-24 21:56:24 +00007575" call Dret("s:NetrwMarkFileExe")
7576endfun
7577
7578" ---------------------------------------------------------------------
7579" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7580" as the marked file(s) (toggles suffix presence)
7581" Uses the local marked file list.
7582fun! s:NetrwMarkHideSfx(islocal)
7583" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007584 let svpos = winsaveview()
7585" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007586 let curbufnr = bufnr("%")
7587
7588 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7589 if exists("s:netrwmarkfilelist_{curbufnr}")
7590
7591 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007592" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007593 " construct suffix pattern
7594 if fname =~ '\.'
7595 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7596 else
7597 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7598 endif
7599 " determine if its in the hiding list or not
7600 let inhidelist= 0
7601 if g:netrw_list_hide != ""
7602 let itemnum = 0
7603 let hidelist= split(g:netrw_list_hide,',')
7604 for hidepat in hidelist
7605 if sfxpat == hidepat
7606 let inhidelist= 1
7607 break
7608 endif
7609 let itemnum= itemnum + 1
7610 endfor
7611 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007612" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007613 if inhidelist
7614 " remove sfxpat from list
7615 call remove(hidelist,itemnum)
7616 let g:netrw_list_hide= join(hidelist,",")
7617 elseif g:netrw_list_hide != ""
7618 " append sfxpat to non-empty list
7619 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7620 else
7621 " set hiding list to sfxpat
7622 let g:netrw_list_hide= sfxpat
7623 endif
7624 endfor
7625
7626 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007627 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007628" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7629 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007630 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007631 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007632 endif
7633
7634" call Dret("s:NetrwMarkHideSfx")
7635endfun
7636
7637" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007638" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007639" Uses the local marked-file list.
7640fun! s:NetrwMarkFileVimCmd(islocal)
7641" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007642 let svpos = winsaveview()
7643" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007644 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007645 let curbufnr = bufnr("%")
7646
Bram Moolenaarff034192013-04-24 18:51:19 +02007647 " sanity check
7648 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007649 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007650" call Dret("s:NetrwMarkFileVimCmd")
7651 return
7652 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007653" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007654
Bram Moolenaar15146672011-10-20 22:22:38 +02007655 if exists("s:netrwmarkfilelist_{curbufnr}")
7656 " get the command
7657 call inputsave()
7658 let cmd= input("Enter vim command: ","","file")
7659 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007660" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007661 if cmd == ""
7662" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7663 return
7664 endif
7665
7666 " apply command to marked files. Substitute: filename -> %
7667 " If no %, then append a space and the filename to the command
7668 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007669" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007670 if a:islocal
7671 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007672 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007673" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007674 exe cmd
7675 exe "sil! keepalt wq!"
7676 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007677" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007678 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007679 endif
7680 endfor
7681
7682 " unmark marked file list
7683 call s:NetrwUnmarkList(curbufnr,curdir)
7684
7685 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007686 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007687" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7688 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007689 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007690 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007691 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007692
Bram Moolenaar15146672011-10-20 22:22:38 +02007693" call Dret("s:NetrwMarkFileVimCmd")
7694endfun
7695
7696" ---------------------------------------------------------------------
7697" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7698" as the marked file(s) (toggles suffix presence)
7699" Uses the local marked file list.
7700fun! s:NetrwMarkHideSfx(islocal)
7701" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007702 let svpos = winsaveview()
7703" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007704 let curbufnr = bufnr("%")
7705
7706 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7707 if exists("s:netrwmarkfilelist_{curbufnr}")
7708
7709 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007710" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007711 " construct suffix pattern
7712 if fname =~ '\.'
7713 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7714 else
7715 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7716 endif
7717 " determine if its in the hiding list or not
7718 let inhidelist= 0
7719 if g:netrw_list_hide != ""
7720 let itemnum = 0
7721 let hidelist= split(g:netrw_list_hide,',')
7722 for hidepat in hidelist
7723 if sfxpat == hidepat
7724 let inhidelist= 1
7725 break
7726 endif
7727 let itemnum= itemnum + 1
7728 endfor
7729 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007730" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007731 if inhidelist
7732 " remove sfxpat from list
7733 call remove(hidelist,itemnum)
7734 let g:netrw_list_hide= join(hidelist,",")
7735 elseif g:netrw_list_hide != ""
7736 " append sfxpat to non-empty list
7737 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7738 else
7739 " set hiding list to sfxpat
7740 let g:netrw_list_hide= sfxpat
7741 endif
7742 endfor
7743
7744 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007745 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007746" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7747 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007748 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007749 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007750 endif
7751
7752" call Dret("s:NetrwMarkHideSfx")
7753endfun
7754
7755" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007756" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7757" Uses the global markfilelist
7758fun! s:NetrwMarkFileGrep(islocal)
7759" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007760 let svpos = winsaveview()
7761" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007762 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007763 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007764
7765 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007766" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007767 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007768" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007769 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007770 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007771" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007772 let netrwmarkfilelist= "*"
7773 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007774
Bram Moolenaarff034192013-04-24 18:51:19 +02007775 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007776" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007777 call inputsave()
7778 let pat= input("Enter pattern: ","")
7779 call inputrestore()
7780 let patbang = ""
7781 if pat =~ '^!'
7782 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007783 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007784 endif
7785 if pat =~ '^\i'
7786 let pat = escape(pat,'/')
7787 let pat = '/'.pat.'/'
7788 else
7789 let nonisi = pat[0]
7790 endif
7791
7792 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007793" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007794 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007795 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007796 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007797 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007798" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7799 return
7800 endtry
7801 echo "(use :cn, :cp to navigate, :Rex to return)"
7802
7803 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007804" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7805 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007806
7807 if exists("nonisi")
7808 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007809" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007810 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007811 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007812 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007813 endif
7814
7815" call Dret("s:NetrwMarkFileGrep")
7816endfun
7817
7818" ---------------------------------------------------------------------
7819" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7820" uses the global marked file list
7821" s:netrwmfloc= 0: target directory is remote
7822" = 1: target directory is local
7823fun! s:NetrwMarkFileMove(islocal)
7824" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007825 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007826 let curbufnr = bufnr("%")
7827
7828 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007829 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007830 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007831" call Dret("s:NetrwMarkFileMove")
7832 return
7833 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007834" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007835
Bram Moolenaar446cb832008-06-24 21:56:24 +00007836 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007837 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007838" call Dret("s:NetrwMarkFileCopy 0")
7839 return 0
7840 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007841" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007842
7843 if a:islocal && s:netrwmftgt_islocal
7844 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007845" call Decho("move from local to local",'~'.expand("<slnum>"))
7846" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007847 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007848 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7849" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7850 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007851 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007852 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007854 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007855 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007856" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007857 if g:netrw_localmovecmd =~ '\s'
7858 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7859 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7860 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007861" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007862 else
7863 let movecmd = netrw#WinPath(movecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007864" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007865 endif
7866 else
7867 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007868" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007869 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007870 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007871 if g:netrw_keepdir
7872 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7873 let fname= b:netrw_curdir."/".fname
7874 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007875 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7876 let fname= substitute(fname,'/','\\','g')
Bram Moolenaar71badf92023-04-22 22:40:14 +01007877 if g:netrw_keepdir
7878 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7879 let fname= b:netrw_curdir."\\".fname
7880 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007881 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007882" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007883 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007884 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007885 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007886 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 +01007887 else
7888 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7889 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007890 break
7891 endif
7892 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007893
7894 elseif a:islocal && !s:netrwmftgt_islocal
7895 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007896" call Decho("move from local to remote",'~'.expand("<slnum>"))
7897" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007898 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007899 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007900" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007901 for fname in mflist
7902 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7903 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7904 endfor
7905 unlet mflist
7906
7907 elseif !a:islocal && s:netrwmftgt_islocal
7908 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007909" call Decho("move from remote to local",'~'.expand("<slnum>"))
7910" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007911 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007912 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007913" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007914 for fname in mflist
7915 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7916 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7917 endfor
7918 unlet mflist
7919
7920 elseif !a:islocal && !s:netrwmftgt_islocal
7921 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007922" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7923" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007924 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007925 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007926" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007927 for fname in mflist
7928 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7929 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7930 endfor
7931 unlet mflist
7932 endif
7933
7934 " -------
7935 " cleanup
7936 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007937" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007938
7939 " remove markings from local buffer
7940 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7941
7942 " refresh buffers
7943 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007944" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007945 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007946 endif
7947 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007948" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007949 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007950 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007951 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007952" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007953 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007954 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007955
Bram Moolenaar446cb832008-06-24 21:56:24 +00007956" call Dret("s:NetrwMarkFileMove")
7957endfun
7958
7959" ---------------------------------------------------------------------
7960" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7961" using the hardcopy command. Local marked-file list only.
7962fun! s:NetrwMarkFilePrint(islocal)
7963" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7964 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007965
7966 " sanity check
7967 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007968 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007969" call Dret("s:NetrwMarkFilePrint")
7970 return
7971 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007972" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7973 let curdir= s:NetrwGetCurdir(a:islocal)
7974
Bram Moolenaar446cb832008-06-24 21:56:24 +00007975 if exists("s:netrwmarkfilelist_{curbufnr}")
7976 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007977 call s:NetrwUnmarkList(curbufnr,curdir)
7978 for fname in netrwmarkfilelist
7979 if a:islocal
7980 if g:netrw_keepdir
7981 let fname= s:ComposePath(curdir,fname)
7982 endif
7983 else
7984 let fname= curdir.fname
7985 endif
7986 1split
7987 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007988" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007989 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007990" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007991 hardcopy
7992 q
7993 endfor
7994 2match none
7995 endif
7996" call Dret("s:NetrwMarkFilePrint")
7997endfun
7998
7999" ---------------------------------------------------------------------
8000" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
8001" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02008002" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00008003fun! s:NetrwMarkFileRegexp(islocal)
8004" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
8005
8006 " get the regular expression
8007 call inputsave()
8008 let regexp= input("Enter regexp: ","","file")
8009 call inputrestore()
8010
8011 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008012 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008013" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008014 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008015" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008016 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008017 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008018 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008019 else
8020 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008021 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008022 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008023" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024
8025 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008026 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008027 if fname =~ '^'.fnameescape(curdir)
8028" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8029 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8030 else
8031" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8032 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8033 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008034 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008035
8036 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008037" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008038
8039 " convert displayed listing into a filelist
8040 let eikeep = &ei
8041 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008042 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008043 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008044" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008046 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008047 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008048 sil NetrwKeepj norm! "ap
8049 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008050 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008051 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008052 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008053 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008054 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008055 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008056 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008057 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008058 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008059 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008060 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8061 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008062 call histdel("/",-1)
8063 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008064 endif
8065 " convert regexp into the more usual glob-style format
8066 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008067" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008068 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008069 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008070 let filelist= getline(1,line("$"))
8071 q!
8072 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008073 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008074 endfor
8075 unlet filelist
8076 let @a = areg
8077 let &ei = eikeep
8078 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008079 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008080
8081" call Dret("s:NetrwMarkFileRegexp")
8082endfun
8083
8084" ---------------------------------------------------------------------
8085" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8086" Uses the local marked file list.
8087fun! s:NetrwMarkFileSource(islocal)
8088" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8089 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008090
8091 " sanity check
8092 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008093 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008094" call Dret("s:NetrwMarkFileSource")
8095 return
8096 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008097" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8098 let curdir= s:NetrwGetCurdir(a:islocal)
8099
Bram Moolenaar446cb832008-06-24 21:56:24 +00008100 if exists("s:netrwmarkfilelist_{curbufnr}")
8101 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008102 call s:NetrwUnmarkList(curbufnr,curdir)
8103 for fname in netrwmarkfilelist
8104 if a:islocal
8105 if g:netrw_keepdir
8106 let fname= s:ComposePath(curdir,fname)
8107 endif
8108 else
8109 let fname= curdir.fname
8110 endif
8111 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008112" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008113 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008114 endfor
8115 2match none
8116 endif
8117" call Dret("s:NetrwMarkFileSource")
8118endfun
8119
8120" ---------------------------------------------------------------------
8121" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8122" Uses the global markfilelist
8123fun! s:NetrwMarkFileTag(islocal)
8124" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008125 let svpos = winsaveview()
8126" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008127 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008128 let curbufnr = bufnr("%")
8129
Bram Moolenaarff034192013-04-24 18:51:19 +02008130 " sanity check
8131 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008132 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008133" call Dret("s:NetrwMarkFileTag")
8134 return
8135 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008136" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008137
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008139" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8140 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008141 call s:NetrwUnmarkAll()
8142
8143 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008144
8145" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8146 call system(g:netrw_ctags." ".netrwmarkfilelist)
8147 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008148 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8149 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008150
Bram Moolenaar446cb832008-06-24 21:56:24 +00008151 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008152 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008153 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008154 let curdir= b:netrw_curdir
8155 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008156 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008157 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008158" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008159 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008160 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008161 wq!
8162 endif
8163 2match none
8164 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008165" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8166 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008167 endif
8168
8169" call Dret("s:NetrwMarkFileTag")
8170endfun
8171
8172" ---------------------------------------------------------------------
8173" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008174" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008175" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008176" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008177" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008178fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008179" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8180 let svpos = winsaveview()
8181" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008182 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008183 let hadtgt = exists("s:netrwmftgt")
8184 if !exists("w:netrw_bannercnt")
8185 let w:netrw_bannercnt= b:netrw_bannercnt
8186 endif
8187
8188 " set up target
8189 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008190" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008191 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8192 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008193" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008194 unlet s:netrwmftgt s:netrwmftgt_islocal
8195 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008196 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008197 endif
8198 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008199" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8200 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008201" call Dret("s:NetrwMarkFileTgt : removed target")
8202 return
8203 else
8204 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008205" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008206 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008207
8208 else
8209 " get word under cursor.
8210 " * If directory, use it for the target.
8211 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008212" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008213 let curword= s:NetrwGetWord()
8214 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008215 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008216 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008217" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008218 elseif !a:islocal && tgtdir =~ '/$'
8219 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008220" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008221 else
8222 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008223" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008224 endif
8225 endif
8226 if a:islocal
8227 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8228 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008229" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008230 endif
8231 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008232 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008233 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8234 endif
8235 let s:netrwmftgt_islocal= a:islocal
8236
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008237 " need to do refresh so that the banner will be updated
8238 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008239 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008240" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008241 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008242 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008243" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008244 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008245 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8246 else
8247 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8248 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008249" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8250 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008251 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008252 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008253 endif
8254
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008255" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8256" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008257" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8258endfun
8259
8260" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008261" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8262fun! s:NetrwGetCurdir(islocal)
8263" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8264
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008265 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008266 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8267" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8268 elseif !exists("b:netrw_curdir")
8269 let b:netrw_curdir= getcwd()
8270" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8271 endif
8272
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008273" 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 +01008274 if b:netrw_curdir !~ '\<\a\{3,}://'
8275 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008276" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008277 if g:netrw_keepdir == 0
8278 call s:NetrwLcd(curdir)
8279 endif
8280 endif
8281
8282" call Dret("s:NetrwGetCurdir <".curdir.">")
8283 return b:netrw_curdir
8284endfun
8285
8286" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008287" s:NetrwOpenFile: query user for a filename and open it {{{2
8288fun! s:NetrwOpenFile(islocal)
8289" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008290 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008291 call inputsave()
8292 let fname= input("Enter filename: ")
8293 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008294" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8295
8296 " determine if Lexplore is in use
8297 if exists("t:netrw_lexbufnr")
8298 " check if t:netrw_lexbufnr refers to a netrw window
8299" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8300 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8301 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8302" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8303 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8304 exe "NetrwKeepj e ".fnameescape(fname)
8305 let @@= ykeep
8306" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8307 endif
8308 endif
8309
8310 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008311 if fname !~ '[/\\]'
8312 if exists("b:netrw_curdir")
8313 if exists("g:netrw_quiet")
8314 let netrw_quiet_keep = g:netrw_quiet
8315 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008316 let g:netrw_quiet = 1
8317 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008318 let s:rexposn_{bufnr("%")}= winsaveview()
8319" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008320 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008321 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008322 else
8323 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8324 endif
8325 if exists("netrw_quiet_keep")
8326 let g:netrw_quiet= netrw_quiet_keep
8327 else
8328 unlet g:netrw_quiet
8329 endif
8330 endif
8331 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008332 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008333 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008334 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008335" call Dret("s:NetrwOpenFile")
8336endfun
8337
8338" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008339" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8340" For the mapping to this function be made via
8341" netrwPlugin, you'll need to have had
8342" g:netrw_usetab set to non-zero.
8343fun! netrw#Shrink()
8344" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8345 let curwin = winnr()
8346 let wiwkeep = &wiw
8347 set wiw=1
8348
8349 if &ft == "netrw"
8350 if winwidth(0) > g:netrw_wiw
8351 let t:netrw_winwidth= winwidth(0)
8352 exe "vert resize ".g:netrw_wiw
8353 wincmd l
8354 if winnr() == curwin
8355 wincmd h
8356 endif
8357" call Decho("vert resize 0",'~'.expand("<slnum>"))
8358 else
8359 exe "vert resize ".t:netrw_winwidth
8360" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8361 endif
8362
8363 elseif exists("t:netrw_lexbufnr")
8364 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8365 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8366 let t:netrw_winwidth= winwidth(0)
8367 exe "vert resize ".g:netrw_wiw
8368 wincmd l
8369 if winnr() == curwin
8370 wincmd h
8371 endif
8372" call Decho("vert resize 0",'~'.expand("<slnum>"))
8373 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8374 exe "vert resize ".t:netrw_winwidth
8375" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8376 else
8377 call netrw#Lexplore(0,0)
8378 endif
8379
8380 else
8381 call netrw#Lexplore(0,0)
8382 endif
8383 let wiw= wiwkeep
8384
8385" call Dret("netrw#Shrink")
8386endfun
8387
8388" ---------------------------------------------------------------------
8389" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8390fun! s:NetSortSequence(islocal)
8391" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8392
8393 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008394 let svpos= winsaveview()
8395" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008396 call inputsave()
8397 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8398 call inputrestore()
8399
8400 " refresh the listing
8401 let g:netrw_sort_sequence= newsortseq
8402 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008403" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8404 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008405 let @@= ykeep
8406
8407" call Dret("NetSortSequence")
8408endfun
8409
8410" ---------------------------------------------------------------------
8411" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8412" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008413" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008414fun! s:NetrwUnmarkList(curbufnr,curdir)
8415" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8416
8417 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008418 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008419 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8420 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8421 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8422 call remove(s:netrwmarkfilelist,idx) " remove from global list
8423 endfor
8424 if s:netrwmarkfilelist == []
8425 unlet s:netrwmarkfilelist
8426 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008427
Bram Moolenaar446cb832008-06-24 21:56:24 +00008428 " getting rid of the local marked-file lists is easy
8429 unlet s:netrwmarkfilelist_{a:curbufnr}
8430 endif
8431 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8432 unlet s:netrwmarkfilemtch_{a:curbufnr}
8433 endif
8434 2match none
8435" call Dret("s:NetrwUnmarkList")
8436endfun
8437
8438" ---------------------------------------------------------------------
8439" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8440fun! s:NetrwUnmarkAll()
8441" call Dfunc("s:NetrwUnmarkAll()")
8442 if exists("s:netrwmarkfilelist")
8443 unlet s:netrwmarkfilelist
8444 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008445 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008446 2match none
8447" call Dret("s:NetrwUnmarkAll")
8448endfun
8449
8450" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008451" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008452fun! s:NetrwUnmarkAll2()
8453" call Dfunc("s:NetrwUnmarkAll2()")
8454 redir => netrwmarkfilelist_let
8455 let
8456 redir END
8457 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008458 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8460 for flist in netrwmarkfilelist_list
8461 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8462 unlet s:netrwmarkfilelist_{curbufnr}
8463 unlet s:netrwmarkfilemtch_{curbufnr}
8464 endfor
8465" call Dret("s:NetrwUnmarkAll2")
8466endfun
8467
8468" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008469" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8470"
8471" Marked files are in two types of lists:
8472" s:netrwmarkfilelist -- holds complete paths to all marked files
8473" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8474"
8475" Marked files suitable for use with 2match are in:
8476" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008477fun! s:NetrwUnMarkFile(islocal)
8478" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008479 let svpos = winsaveview()
8480" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008481 let curbufnr = bufnr("%")
8482
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008483 " unmark marked file list
8484 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8485 if exists("s:netrwmarkfilelist")
8486" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008487 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008488 endif
8489
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008490 let ibuf= 1
8491 while ibuf < bufnr("$")
8492 if exists("s:netrwmarkfilelist_".ibuf)
8493 unlet s:netrwmarkfilelist_{ibuf}
8494 unlet s:netrwmarkfilemtch_{ibuf}
8495 endif
8496 let ibuf = ibuf + 1
8497 endwhile
8498 2match none
8499
Bram Moolenaar446cb832008-06-24 21:56:24 +00008500" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008501"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8502call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008503" call Dret("s:NetrwUnMarkFile")
8504endfun
8505
8506" ---------------------------------------------------------------------
8507" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8508fun! s:NetrwMenu(domenu)
8509
8510 if !exists("g:NetrwMenuPriority")
8511 let g:NetrwMenuPriority= 80
8512 endif
8513
Bram Moolenaaradc21822011-04-01 18:03:16 +02008514 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008515" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8516
8517 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008518" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008519 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008520 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8524 if g:netrw_dirhistmax > 0
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8529 else
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8531 endif
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8546 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 +01008547 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 +02008548 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8553 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8555 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8556 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8558 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8559 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8560 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8561 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8562 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8563 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8564 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8565 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8566 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8567 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8568 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8569 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8570 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8571 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8572 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8573 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8574 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8575 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8576 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8577 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>'
8578 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>'
8579 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>'
8580 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8581 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>'
8582 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>'
8583 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 +01008584 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 +02008585 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8586 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008587 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008588 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8589 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008590
8591 elseif !a:domenu
8592 let s:netrwcnt = 0
8593 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008594 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008595 exe curwin."wincmd w"
8596
8597 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008598" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008599 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008600" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008601 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008602 endif
8603 endif
8604" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008605 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008606 endif
8607
8608endfun
8609
8610" ---------------------------------------------------------------------
8611" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8612" Used by the O maps (as <SID>NetrwObtain())
8613fun! s:NetrwObtain(islocal)
8614" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8615
Bram Moolenaar97d62492012-11-15 21:28:22 +01008616 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008617 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008618 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008619 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008620 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8621 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008622 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008623 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008624 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008625
8626" call Dret("NetrwObtain")
8627endfun
8628
8629" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008630" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8631" If there's only one window, then the window will first be split.
8632" Returns:
8633" choice = 0 : didn't have to choose
8634" choice = 1 : saved modified file in window first
8635" choice = 2 : didn't save modified file, opened window
8636" choice = 3 : cancel open
8637fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008638" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639
Bram Moolenaar97d62492012-11-15 21:28:22 +01008640 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008641 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008642 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008643" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008644
8645 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008646 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008647 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008648" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8649" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8650 let curword = s:NetrwGetWord()
8651 let choice = 0
8652 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8653" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008654 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008655" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008656 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008657" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008658" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008659" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008660
Bram Moolenaar8d043172014-01-23 14:24:41 +01008661 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008662 if lastwinnr == 1
8663 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008664" 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 +02008665 " g:netrw_preview=0: preview window shown in a horizontally split window
8666 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008667 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008668 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008669 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008670" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008671 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008672 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008673 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008674 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008675" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008676 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008677 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008678 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008679" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008680
8681 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008682" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008683 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008684" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008685 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008686" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008687 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008688" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008689 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008690" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008691" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008692" call Decho("COMBAK#12: mod=".&mod)
8693
8694 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8695 " whoops -- user trying to open file in the Lexplore window.
8696 " Use Lexplore's opening-file window instead.
8697" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8698" exe g:netrw_chgwin."wincmd w"
8699 wincmd p
8700 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8701 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008702
8703 " prevwinnr: the window number of the "prev" window
8704 " prevbufnr: the buffer number of the buffer in the "prev" window
8705 " bnrcnt : the qty of windows open on the "prev" buffer
8706 let prevwinnr = winnr()
8707 let prevbufnr = bufnr("%")
8708 let prevbufname = bufname("%")
8709 let prevmod = &mod
8710 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008711" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008712 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008713" 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 +01008714" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008715
8716 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008717 " and it doesn't appear in any other extant window, then ask the
8718 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008719 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008720" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008721 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008722" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008723 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008724" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008725
8726 if bnrcnt == 1 && &hidden == 0
8727 " only one copy of the modified buffer in a window, and
8728 " hidden not set, so overwriting will lose the modified file. Ask first...
8729 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008730" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008731 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008732" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008733
8734 if choice == 1
8735 " Yes -- write file & then browse
8736 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008737 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008738 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008739 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008740 exe origwin."wincmd w"
8741 let &ei = eikeep
8742 let @@ = ykeep
8743" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008744 return choice
8745 endif
8746
8747 elseif choice == 2
8748 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008749" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008750 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008751
8752 else
8753 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008754" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008755 exe origwin."wincmd w"
8756 let &ei= eikeep
8757 let @@ = ykeep
8758" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008759 return choice
8760 endif
8761 endif
8762 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008763 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008764 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008765" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008766
8767 " restore b:netrw_curdir (window split/enew may have lost it)
8768 let b:netrw_curdir= curdir
8769 if a:islocal < 2
8770 if a:islocal
8771 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8772 else
8773 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8774 endif
8775 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008776 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008777" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778 return choice
8779endfun
8780
8781" ---------------------------------------------------------------------
8782" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8783" Always assumed to be local -> remote
8784" call s:NetrwUpload(filename, target)
8785" call s:NetrwUpload(filename, target, fromdirectory)
8786fun! s:NetrwUpload(fname,tgt,...)
8787" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8788
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008789 if a:tgt =~ '^\a\{3,}://'
8790 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008791 else
8792 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8793 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008794" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008795
8796 if a:0 > 0
8797 let fromdir= a:1
8798 else
8799 let fromdir= getcwd()
8800 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008801" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008802
8803 if type(a:fname) == 1
8804 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008805" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008806 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008807" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8808 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8809" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810 if a:tgt =~ '/$'
8811 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008812" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008813 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008814 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008816 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008817" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008818 endif
8819 q!
8820
8821 elseif type(a:fname) == 3
8822 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824 let curdir= getcwd()
8825 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008826 if s:NetrwLcd(fromdir)
8827" call Dret("s:NetrwUpload : lcd failure")
8828 return
8829 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008830 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008831 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832 if exists("g:netrw_port") && g:netrw_port != ""
8833 let useport= " ".g:netrw_scpport." ".g:netrw_port
8834 else
8835 let useport= ""
8836 endif
8837 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8838 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008839 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 +02008840 if s:NetrwLcd(curdir)
8841" call Dret("s:NetrwUpload : lcd failure")
8842 return
8843 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008844
8845 elseif a:tgt =~ '^ftp:'
8846 call s:NetrwMethod(a:tgt)
8847
8848 if b:netrw_method == 2
8849 " handle uploading a list of files via ftp+.netrc
8850 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008851 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008852" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008853
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008854 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008855" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856
8857 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008858 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008859" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008860 endif
8861
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008862 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008863" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008864
Bram Moolenaaradc21822011-04-01 18:03:16 +02008865 if tgtdir == ""
8866 let tgtdir= '/'
8867 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008868 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008869" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008870
8871 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008872 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8873" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008874 endfor
8875
8876 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008877 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 +00008878 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008879" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8880 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008881 endif
8882 " 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 +01008883 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008884 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008885 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8886 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8887 else
8888 bw!|q
8889 endif
8890
8891 elseif b:netrw_method == 3
8892 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8893 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008894 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008895 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008896 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008897
8898 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008899 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008900" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008901 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008902 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008903" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008904 endif
8905
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008906 if exists("g:netrw_uid") && g:netrw_uid != ""
8907 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008908 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008909" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008910 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008911 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008912 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008913" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008914 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008915 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008916" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008917 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008918 endif
8919
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008920 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008921" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008922
8923 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008924 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008925" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008926 endif
8927
8928 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008929 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008930" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008931 endif
8932
8933 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008934 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008935" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008936 endfor
8937
8938 " perform ftp:
8939 " -i : turns off interactive prompting from ftp
8940 " -n unix : DON'T use <.netrc>, even though it exists
8941 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008942 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008943 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008944 " 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 +01008945 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008946 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008947 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8948 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008949 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008950 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8951 let &debug = debugkeep
8952 let mod = 1
8953 else
8954 bw!|q
8955 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008956 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008957" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008958 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008959 endif
8960 else
8961 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8962 endif
8963 endif
8964
8965" call Dret("s:NetrwUpload")
8966endfun
8967
8968" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008969" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008970fun! s:NetrwPreview(path) range
8971" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008972" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8973" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008974 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008975 NetrwKeepj call s:NetrwOptionsSave("s:")
8976 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8977 NetrwKeepj call s:NetrwOptionsSafe(1)
8978 else
8979 NetrwKeepj call s:NetrwOptionsSafe(0)
8980 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008981 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008982" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008983 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008984" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8985 if g:netrw_preview
8986 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008987 let pvhkeep = &pvh
8988 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8989 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008990" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8991 else
8992 " horizontal split
8993 let pvhkeep = &pvh
8994 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8995 let &pvh = winheight(0) - winsz
8996" 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 +02008997 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008998 " g:netrw_preview g:netrw_alto
8999 " 1 : vert 1: top -- preview window is vertically split off and on the left
9000 " 1 : vert 0: bot -- preview window is vertically split off and on the right
9001 " 0 : 1: top -- preview window is horizontally split off and on the top
9002 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
9003 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009004 " 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 +02009005 " the BufEnter event set up in netrwPlugin.vim
9006" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
9007 let eikeep = &ei
9008 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009009 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009010 let &ei= eikeep
9011" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009012 if exists("pvhkeep")
9013 let &pvh= pvhkeep
9014 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009015 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009016 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009017 endif
9018 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009019 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 +00009020 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009021 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009022 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009023" call Dret("NetrwPreview")
9024endfun
9025
9026" ---------------------------------------------------------------------
9027" s:NetrwRefresh: {{{2
9028fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009029" 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 +00009030 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009031 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009032" call Decho("setl ma noro",'~'.expand("<slnum>"))
9033" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009034 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009035 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9036 if !exists("w:netrw_treetop")
9037 if exists("b:netrw_curdir")
9038 let w:netrw_treetop= b:netrw_curdir
9039 else
9040 let w:netrw_treetop= getcwd()
9041 endif
9042 endif
9043 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9044 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009045
9046 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009047 let screenposn = winsaveview()
9048" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009049
9050" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9051" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9052 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009053 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009054 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009055 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009056 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009057 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009058
9059 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009060" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9061 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009062
9063 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009064 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9065 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9066" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9067 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9068 else
9069" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9070 2match none
9071 endif
9072 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009073
Bram Moolenaar97d62492012-11-15 21:28:22 +01009074" restore
9075 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009076" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009077endfun
9078
9079" ---------------------------------------------------------------------
9080" s:NetrwRefreshDir: refreshes a directory by name {{{2
9081" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009082" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009083fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009084" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009085 if g:netrw_fastbrowse == 0
9086 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009087" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009088 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009089" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009090
9091 if tgtwin > 0
9092 " tgtwin is being displayed, so refresh it
9093 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009094" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009095 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009096 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009097 exe curwin."wincmd w"
9098
9099 elseif bufnr(a:dirname) > 0
9100 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009101" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9102 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009103 endif
9104
9105 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009106" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009107 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009108 endif
9109" call Dret("s:NetrwRefreshDir")
9110endfun
9111
9112" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009113" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9114" window number to do its editing in.
9115" Supports [count]C where the count, if present, is used to specify
9116" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009117fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009118" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009119 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009120" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009121 if a:1 == "" " :NetrwC win#
9122 let g:netrw_chgwin= winnr()
9123 else " :NetrwC
9124 let g:netrw_chgwin= a:1
9125 endif
9126 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009127 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009128 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009129 let g:netrw_chgwin= winnr()
9130 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009131 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009132" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009133endfun
9134
9135" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009136" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9137" What this function does is to compute a priority for the patterns
9138" in the g:netrw_sort_sequence. It applies a substitute to any
9139" "files" that satisfy each pattern, putting the priority / in
9140" front. An "*" pattern handles the default priority.
9141fun! s:NetrwSetSort()
9142" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009143 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009144 if w:netrw_liststyle == s:LONGLIST
9145 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9146 else
9147 let seqlist = g:netrw_sort_sequence
9148 endif
9149 " sanity check -- insure that * appears somewhere
9150 if seqlist == ""
9151 let seqlist= '*'
9152 elseif seqlist !~ '\*'
9153 let seqlist= seqlist.',*'
9154 endif
9155 let priority = 1
9156 while seqlist != ""
9157 if seqlist =~ ','
9158 let seq = substitute(seqlist,',.*$','','e')
9159 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9160 else
9161 let seq = seqlist
9162 let seqlist = ""
9163 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009164 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009165 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009166 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009167 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009168 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009169 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009170 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009171" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009172
9173 " sanity check
9174 if w:netrw_bannercnt > line("$")
9175 " apparently no files were left after a Hiding pattern was used
9176" call Dret("SetSort : no files left after hiding")
9177 return
9178 endif
9179 if seq == '*'
9180 let starpriority= spriority
9181 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009182 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009183 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009184 " sometimes multiple sorting patterns will match the same file or directory.
9185 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009186 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9187 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009188 endif
9189 let priority = priority + 1
9190 endwhile
9191 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009192 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9193 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009194 endif
9195
9196 " Following line associated with priority -- items that satisfy a priority
9197 " pattern get prefixed by ###/ which permits easy sorting by priority.
9198 " Sometimes files can satisfy multiple priority patterns -- only the latest
9199 " priority pattern needs to be retained. So, at this point, these excess
9200 " priority prefixes need to be removed, but not directories that happen to
9201 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009202 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9203 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009204 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009205
9206" call Dret("SetSort")
9207endfun
9208
Bram Moolenaarff034192013-04-24 18:51:19 +02009209" ---------------------------------------------------------------------
9210" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9211" Implements [count]Tb (bookhist<b>)
9212" [count]Th (bookhist<h>)
9213" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009214fun! s:NetrwSetTgt(islocal,bookhist,choice)
9215" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009216
9217 if a:bookhist == 'b'
9218 " supports choosing a bookmark as a target using a qb-generated list
9219 let choice= a:choice - 1
9220 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009221 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009222 else
9223 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9224 endif
9225
9226 elseif a:bookhist == 'h'
9227 " supports choosing a history stack entry as a target using a qb-generated list
9228 let choice= (a:choice % g:netrw_dirhistmax) + 1
9229 if exists("g:netrw_dirhist_".choice)
9230 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009231 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009232 else
9233 echomsg "Sorry, history#".a:choice." not available!"
9234 endif
9235 endif
9236
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009237 " refresh the display
9238 if !exists("b:netrw_curdir")
9239 let b:netrw_curdir= getcwd()
9240 endif
9241 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9242
Bram Moolenaarff034192013-04-24 18:51:19 +02009243" call Dret("s:NetrwSetTgt")
9244endfun
9245
Bram Moolenaar446cb832008-06-24 21:56:24 +00009246" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009247" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009248fun! s:NetrwSortStyle(islocal)
9249" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009250 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009251 let svpos= winsaveview()
9252" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009253
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009254 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 +01009255 NetrwKeepj norm! 0
9256 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009257" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9258 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009259
9260" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9261endfun
9262
9263" ---------------------------------------------------------------------
9264" s:NetrwSplit: mode {{{2
9265" =0 : net and o
9266" =1 : net and t
9267" =2 : net and v
9268" =3 : local and o
9269" =4 : local and t
9270" =5 : local and v
9271fun! s:NetrwSplit(mode)
9272" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9273
Bram Moolenaar97d62492012-11-15 21:28:22 +01009274 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009275 call s:SaveWinVars()
9276
9277 if a:mode == 0
9278 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009279 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009280 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009281" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009282 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009283 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009284 NetrwKeepj call s:RestoreWinVars()
9285 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286 unlet s:didsplit
9287
9288 elseif a:mode == 1
9289 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009290 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009291" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009292 tabnew
9293 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009294 NetrwKeepj call s:RestoreWinVars()
9295 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009296 unlet s:didsplit
9297
9298 elseif a:mode == 2
9299 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009300 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009301 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009302" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009303 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009304 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009305 NetrwKeepj call s:RestoreWinVars()
9306 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009307 unlet s:didsplit
9308
9309 elseif a:mode == 3
9310 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009311 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009312 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009313" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009314 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009315 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009316 NetrwKeepj call s:RestoreWinVars()
9317 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009318 unlet s:didsplit
9319
9320 elseif a:mode == 4
9321 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009322 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009323 let eikeep = &ei
9324 let netrw_winnr = winnr()
9325 let netrw_line = line(".")
9326 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009327 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009328 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009329 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009330 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9331 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009332 let &ei = eikeep
9333 let netrw_curdir = s:NetrwTreeDir(0)
9334" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009335 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009336 let b:netrw_curdir = netrw_curdir
9337 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009338 NetrwKeepj call s:RestoreWinVars()
9339 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009340 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009341 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009342 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9343 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009344 let &ei= eikeep
9345 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009346 unlet s:didsplit
9347
9348 elseif a:mode == 5
9349 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009350 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009351 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009352" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009353 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009354 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009355 NetrwKeepj call s:RestoreWinVars()
9356 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009357 unlet s:didsplit
9358
9359 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009360 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009361 endif
9362
Bram Moolenaar97d62492012-11-15 21:28:22 +01009363 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009364" call Dret("s:NetrwSplit")
9365endfun
9366
9367" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009368" s:NetrwTgtMenu: {{{2
9369fun! s:NetrwTgtMenu()
9370 if !exists("s:netrw_menucnt")
9371 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009372 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009373" call Dfunc("s:NetrwTgtMenu()")
9374
9375 " the following test assures that gvim is running, has menus available, and has menus enabled.
9376 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9377 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009378" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009379 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9380 endif
9381 if !exists("s:netrw_initbookhist")
9382 call s:NetrwBookHistRead()
9383 endif
9384
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385 " try to cull duplicate entries
9386 let tgtdict={}
9387
Bram Moolenaarff034192013-04-24 18:51:19 +02009388 " target bookmarked places
9389 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009390" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009391 let cnt= 1
9392 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009393 if has_key(tgtdict,bmd)
9394 let cnt= cnt + 1
9395 continue
9396 endif
9397 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009398 let ebmd= escape(bmd,g:netrw_menu_escape)
9399 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009400" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009401 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 +02009402 let cnt= cnt + 1
9403 endfor
9404 endif
9405
9406 " target directory browsing history
9407 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009408" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009409 let histcnt = 1
9410 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009411 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009412 if exists("g:netrw_dirhist_{histcnt}")
9413 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009414 if has_key(tgtdict,histentry)
9415 let histcnt = histcnt + 1
9416 continue
9417 endif
9418 let tgtdict[histentry] = histcnt
9419 let ehistentry = escape(histentry,g:netrw_menu_escape)
9420" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009421 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 +02009422 endif
9423 let histcnt = histcnt + 1
9424 endwhile
9425 endif
9426 endif
9427" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009428endfun
9429
9430" ---------------------------------------------------------------------
9431" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9432" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009433fun! s:NetrwTreeDir(islocal)
9434" 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 +02009435" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009436" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9437" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9438" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009439" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009440
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009441 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009442 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009443" 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 +01009444 let treedir= s:treedir
9445 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009446 unlet s:prevwinopen
9447" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009448 return treedir
9449 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009450 if exists("s:prevwinopen")
9451 unlet s:prevwinopen
9452 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009453" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009454
Bram Moolenaar8d043172014-01-23 14:24:41 +01009455 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9456 let b:netrw_curdir= getcwd()
9457 endif
9458 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009459" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009460" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009461
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009462 let s:treecurpos= winsaveview()
9463" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009464" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009465
9466 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009467" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9468" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009469" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009470
9471 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009472 let curline= substitute(getline('.'),"\t -->.*$",'','')
9473 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009474" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009475 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009476" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9477 elseif curline =~ '@$'
9478" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
9479 let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
9480" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009481 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009482" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009483 let treedir= ""
9484 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009485" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009486
9487 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009488" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9489" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009490" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009491 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009492" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009493 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009494" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9495 sil! NetrwKeepj %d _
9496" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009497 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009498" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009499" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009501" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009502
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009503" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009504 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9505" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009506" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009507
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009508 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9509" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9510" let newdir = w:netrw_treetop.'/'.potentialdir
9511" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9512" let treedir = s:NetrwTreePath(newdir)
9513" let w:netrw_treetop = newdir
9514" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9515" else
9516" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009517 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009518" endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009519 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009520" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009521
9522 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009523 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009524" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009525" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009526
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009527" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009528 return treedir
9529endfun
9530
9531" ---------------------------------------------------------------------
9532" s:NetrwTreeDisplay: recursive tree display {{{2
9533fun! s:NetrwTreeDisplay(dir,depth)
9534" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9535
9536 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009537 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009538
9539 " install ../ and shortdir
9540 if a:depth == ""
9541 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009542" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009543 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009544 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009545 if a:dir == w:netrw_treetop
9546 let shortdir= a:dir
9547 else
9548 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9549 endif
9550 call setline(line("$")+1,a:depth.shortdir)
9551 else
9552 let shortdir= substitute(a:dir,'^.*/','','e')
9553 call setline(line("$")+1,a:depth.shortdir.'/')
9554 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009555" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009556 " append a / to dir if its missing one
9557 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009558
9559 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009560 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009561" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009562
Bram Moolenaar85850f32019-07-19 22:05:51 +02009563 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9564 if g:netrw_hide == 1
9565 " hide given patterns
9566 let listhide= split(g:netrw_list_hide,',')
9567" call Decho("listhide=".string(listhide))
9568 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009569 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009570 endfor
9571
9572 elseif g:netrw_hide == 2
9573 " show given patterns (only)
9574 let listhide= split(g:netrw_list_hide,',')
9575" call Decho("listhide=".string(listhide))
9576 let entries=[]
9577 for entry in w:netrw_treedict[dir]
9578 for pat in listhide
9579 if entry =~ pat
9580 call add(entries,entry)
9581 break
9582 endif
9583 endfor
9584 endfor
9585 let w:netrw_treedict[dir]= entries
9586 endif
9587 if depth != ""
9588 " always remove "." and ".." entries when there's depth
9589 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9590 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9591 endif
9592
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009593" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009594 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009595 if dir =~ '/$'
9596 let direntry= substitute(dir.entry,'[@/]$','','e')
9597 else
9598 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9599 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009600" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009601 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009602" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009603 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009604 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009605" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9606 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9607 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9608" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009609 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009610 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009611" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009612 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009613 endif
9614 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009615" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009616
Bram Moolenaar446cb832008-06-24 21:56:24 +00009617" call Dret("NetrwTreeDisplay")
9618endfun
9619
9620" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009621" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9622fun! s:NetrwRefreshTreeDict(dir)
9623" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009624 if !exists("w:netrw_treedict")
9625" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9626 return
9627 endif
9628
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009629 for entry in w:netrw_treedict[a:dir]
9630 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9631" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9632
9633 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9634" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9635 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009636 let liststar = s:NetrwGlob(direntry,'*',1)
9637 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009638 let w:netrw_treedict[direntry] = liststar + listdotstar
9639" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9640
9641 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9642" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9643 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009644 let liststar = s:NetrwGlob(direntry.'/','*',1)
9645 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009646 let w:netrw_treedict[direntry]= liststar + listdotstar
9647" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9648
9649 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9650" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9651 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009652 let liststar = s:NetrwGlob(direntry.'/','*',1)
9653 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009654" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9655
9656 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009657" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009658 endif
9659 endfor
9660" call Dret("s:NetrwRefreshTreeDict")
9661endfun
9662
9663" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009664" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009665" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009666fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009667 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009668" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009669" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9670" 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>"))
9671" 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 +00009672
9673 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009674 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009675" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009676 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009677 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009678" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679 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 +02009680" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009681 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009682 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009683" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009684 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009685 if exists("w:netrw_treetop")
9686 let s:netrw_treetop= w:netrw_treetop
9687 else
9688 let w:netrw_treetop= getcwd()
9689 let s:netrw_treetop= w:netrw_treetop
9690 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009691
Bram Moolenaar446cb832008-06-24 21:56:24 +00009692 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009693 " insure that we have a treedict, albeit empty
9694" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009695 let w:netrw_treedict= {}
9696 endif
9697
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009698 " update the dictionary for the current directory
9699" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009700" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009701 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009702 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009703" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009704 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009705
9706 " if past banner, record word
9707 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9708 let fname= expand("<cword>")
9709 else
9710 let fname= ""
9711 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009712" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9713" 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 +00009714
9715 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009716" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009717 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009718" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009719
9720 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9721 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009722" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009723 1d
9724 endwhile
9725
Bram Moolenaar13600302014-05-22 18:26:40 +02009726 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009727
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009728" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009729 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009730 endif
9731endfun
9732
9733" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009734" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009735" Normally, treetop is w:netrw_treetop, but a
9736" user of the function ( netrw#SetTreetop() )
9737" wipes that out prior to calling this function
9738fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009739" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9740 if line(".") < w:netrw_bannercnt + 2
9741 let treedir= a:treetop
9742 if treedir !~ '/$'
9743 let treedir= treedir.'/'
9744 endif
9745" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9746 return treedir
9747 endif
9748
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009749 let svpos = winsaveview()
9750" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009751 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009752" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009753 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009754" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9755 let curline= getline('.')
9756" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9757 if curline =~ '/$'
9758" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9759 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9760" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9761 elseif curline =~ '@\s\+-->'
9762" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9763 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9764 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9765" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009766 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009767" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009768 let treedir= ""
9769 endif
9770 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009771" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9772" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009773 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9774 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9775 let treedir= dirname.treedir
9776 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009777" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009778 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009779" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009780 if a:treetop =~ '/$'
9781 let treedir= a:treetop.treedir
9782 else
9783 let treedir= a:treetop.'/'.treedir
9784 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009785" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009786 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009787" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009788" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9789 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009790" call Dret("s:NetrwTreePath <".treedir.">")
9791 return treedir
9792endfun
9793
9794" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795" s:NetrwWideListing: {{{2
9796fun! s:NetrwWideListing()
9797
9798 if w:netrw_liststyle == s:WIDELIST
9799" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9800 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009801 " cpf: characters per filename
9802 " fpl: filenames per line
9803 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009804 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009805 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009806" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009807 let b:netrw_cpf= 0
9808 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009809 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009810 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9811 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009812 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009813 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009814" call Dret("NetrwWideListing")
9815 return
9816 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009817 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009818 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009819" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009820
9821 " determine qty files per line (fpl)
9822 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9823 if w:netrw_fpl <= 0
9824 let w:netrw_fpl= 1
9825 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009826" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009827
9828 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009829 " fpc: files per column of wide listing
9830 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009831 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009832 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9833 let newcolstart = w:netrw_bannercnt + fpc
9834 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009835" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009836 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009837" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009838 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009839 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009840 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009841 while line("$") >= newcolstart
9842 if newcolend > line("$") | let newcolend= line("$") | endif
9843 let newcolqty= newcolend - newcolstart
9844 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009845 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009846 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009847 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009848 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009849 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009850 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009851 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009852 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009853 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009854 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009855" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009856 if @* != keepregstar | sil! let @* = keepregstar | endif
9857 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009858 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009859 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9860 NetrwKeepj call histdel("/",-1)
9861 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9862 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009863" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009864 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009865 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009866" 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 +00009867" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009868 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009869 else
9870 if hasmapto("w","n")
9871 sil! nunmap <buffer> w
9872 endif
9873 if hasmapto("b","n")
9874 sil! nunmap <buffer> b
9875 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009876 endif
9877
9878endfun
9879
9880" ---------------------------------------------------------------------
9881" s:PerformListing: {{{2
9882fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009883" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9884" 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 +02009885" 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>"))
9886 sil! NetrwKeepj %d _
9887" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009888
Bram Moolenaar15146672011-10-20 22:22:38 +02009889 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009890" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009891 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009892
Bram Moolenaar85850f32019-07-19 22:05:51 +02009893 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009894 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009895" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009896
9897" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009898" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009899" endif " Decho
9900
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009901" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009902 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9903 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009904" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9905 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009906 endif
9907
9908 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009909 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009910
9911 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009912 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009913" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009914 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009915 if exists("g:netrw_pchk")
9916 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9917 " failure detections.
9918 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009919 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009920 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9921 endif
9922 if exists("g:netrw_pchk")
9923 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9924 else
9925 let curdir= b:netrw_curdir
9926 endif
9927 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9928 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9929 else
9930 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009931 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009932 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009933 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009934 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009935" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009936 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009937 let w:netrw_bannercnt= 1
9938 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009939" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9940" 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 +00009941
Bram Moolenaar85850f32019-07-19 22:05:51 +02009942 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009943 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009944 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009945 let sortby= sortby." reversed"
9946 endif
9947
9948 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009949 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009950" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009951 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009952" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009953 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009954 NetrwKeepj put ='\" Sorted by '.sortby
9955 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009956 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9957 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009958" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009959 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009960 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009961 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9962 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009963 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009964" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009965" 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 +00009966 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009967
Bram Moolenaar85850f32019-07-19 22:05:51 +02009968 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009969 if g:netrw_banner
9970 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009971" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009972 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009973 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009974 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009975 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009976 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009977 endif
9978 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009979 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009980" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009981 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009982 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009983 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009984
9985 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009986 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009987" 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 +01009988 if g:netrw_list_hide != "" && g:netrw_hide
9989 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009990 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009991 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009992 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009993 endif
9994 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009995 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009996 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009997
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" 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 +01009999 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010000" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010001 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010002" 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 +010010003 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +010010004 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +010010005" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010006" 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 +000010007 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010008
10009 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +010010010 if g:netrw_banner
10011 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010012 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010013" 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 +010010014" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010015" 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 +010010016 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010017
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010019" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010020 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010021 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010022 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010023 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010024 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010025" 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 +010010026" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10027 return
10028 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010029 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010030
10031 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010032 if !exists("w:netrw_bannercnt")
10033 let w:netrw_bannercnt= 0
10034 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010035" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10036" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10037" 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 +010010038
Bram Moolenaar5c736222010-01-06 20:54:52 +010010039 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010040" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010041" 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 +000010042 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010043 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010044 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010045 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010046" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010047
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010048 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010049 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010050" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010051 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010052
Bram Moolenaar5c736222010-01-06 20:54:52 +010010053 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010054" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010055 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010056 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010057 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010058 else
10059 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010060 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010061 endif
10062 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010063
Bram Moolenaar446cb832008-06-24 21:56:24 +000010064 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010065" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010066 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10067 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010068
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010069 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010070 " exten: sort by extension
10071 " The histdel(...,-1) calls remove the last search from the search history
10072" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010073 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10074 NetrwKeepj call histdel("/",-1)
10075 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10076 NetrwKeepj call histdel("/",-1)
10077 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10078 NetrwKeepj call histdel("/",-1)
10079 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10080" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010081 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010082 " normal direction sorting
10083 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10084 else
10085 " reverse direction sorting
10086 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10087 endif
10088 endif
10089 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10090 NetrwKeepj call histdel("/",-1)
10091
Bram Moolenaar446cb832008-06-24 21:56:24 +000010092 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010093 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010094" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010095 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010096" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010097 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010098 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010100 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010101 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010102" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010103 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10104 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010105 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010106 endif
10107
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010108 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010109" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010110 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010111 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010112 call histdel("/",-1)
10113 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010114 endif
10115 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010116" 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 +000010117
10118 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010119" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10120" 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 +010010121 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010122" 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 +010010123 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010124" 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 +000010125
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010126 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010127 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010128" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010129 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010130 endif
10131
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010132 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010133 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010134" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10135 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010136 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010137" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10138 else
10139" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10140" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10141" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10142" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010143 endif
10144
10145 " record previous current directory
10146 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010147" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010148
10149 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010150" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10151" 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 +010010152 NetrwKeepj call s:SetBufWinVars()
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. " (internal#5)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010154 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010155" 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 +000010156
10157 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010158" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010159 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010160" 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 +010010161 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010162" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010163 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10164 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010165" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010166" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010167
Bram Moolenaar8d043172014-01-23 14:24:41 +010010168 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010169" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10170" 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 +010010171" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10172 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010173 unlet s:treecurpos
10174 endif
10175
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010176" 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>"))
10177" 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 +000010178" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10179endfun
10180
10181" ---------------------------------------------------------------------
10182" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010183fun! s:SetupNetrwStatusLine(statline)
10184" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10185
10186 if !exists("s:netrw_setup_statline")
10187 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010188" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010189
10190 if !exists("s:netrw_users_stl")
10191 let s:netrw_users_stl= &stl
10192 endif
10193 if !exists("s:netrw_users_ls")
10194 let s:netrw_users_ls= &laststatus
10195 endif
10196
10197 " set up User9 highlighting as needed
10198 let keepa= @a
10199 redir @a
10200 try
10201 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010202 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010203 if &bg == "dark"
10204 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10205 else
10206 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10207 endif
10208 endtry
10209 redir END
10210 let @a= keepa
10211 endif
10212
10213 " set up status line (may use User9 highlighting)
10214 " insure that windows have a statusline
10215 " make sure statusline is displayed
10216 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010217 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010218" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010219 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010220
10221" call Dret("SetupNetrwStatusLine : stl=".&stl)
10222endfun
10223
Bram Moolenaar85850f32019-07-19 22:05:51 +020010224" =========================================
10225" Remote Directory Browsing Support: {{{1
10226" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010227
10228" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010229" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10230" This function assumes that a long listing will be received. Size, time,
10231" and reverse sorts will be requested of the server but not otherwise
10232" enforced here.
10233fun! s:NetrwRemoteFtpCmd(path,listcmd)
10234" 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 +010010235" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010236 " sanity check: {{{3
10237 if !exists("w:netrw_method")
10238 if exists("b:netrw_method")
10239 let w:netrw_method= b:netrw_method
10240 else
10241 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10242" call Dret("NetrwRemoteFtpCmd")
10243 return
10244 endif
10245 endif
10246
10247 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10248 let ffkeep= &ff
10249 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010250" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010251
10252 " clear off any older non-banner lines " {{{3
10253 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010254" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10255 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010256
10257 ".........................................
10258 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10259 " ftp + <.netrc>: Method #2
10260 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010261 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010262 endif
10263 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010264 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010265" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010266 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010267 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010268" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010269 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010270" 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>"))
10271 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 +010010272 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010273" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10274 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 +010010275 endif
10276
10277 ".........................................
10278 elseif w:netrw_method == 3 " {{{3
10279 " ftp + machine,id,passwd,filename: Method #3
10280 setl ff=unix
10281 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010282 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010283 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010284 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010285 endif
10286
10287 " handle userid and password
10288 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010289" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010290 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10291 call NetUserPass("ftp:".host)
10292 endif
10293 if exists("g:netrw_uid") && g:netrw_uid != ""
10294 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010295 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010296 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010297 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010298 endif
10299 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010300 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010301 endif
10302 endif
10303
10304 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010305 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010306 endif
10307 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010308 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010309" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010310 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010311 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010312
10313 " perform ftp:
10314 " -i : turns off interactive prompting from ftp
10315 " -n unix : DON'T use <.netrc>, even though it exists
10316 " -n win32: quit being obnoxious about password
10317 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010318" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010319 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010320" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010321" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10322" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010323 endif
10324
10325 ".........................................
10326 elseif w:netrw_method == 9 " {{{3
10327 " sftp username@machine: Method #9
10328 " s:netrw_sftp_cmd
10329 setl ff=unix
10330
10331 " restore settings
10332 let &ff= ffkeep
10333" call Dret("NetrwRemoteFtpCmd")
10334 return
10335
10336 ".........................................
10337 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010338 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010339 endif
10340
10341 " cleanup for Windows " {{{3
10342 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010343 sil! NetrwKeepj %s/\r$//e
10344 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010345 endif
10346 if a:listcmd == "dir"
10347 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010348 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10349 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10350 NetrwKeepj call histdel("/",-1)
10351 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010352 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 +010010353 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10354 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010355 endif
10356 endif
10357
10358 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10359 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010360 exe 'NetrwKeepj '.w:netrw_bannercnt
10361 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010362 endif
10363 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010364 exe 'NetrwKeepj '.w:netrw_bannercnt
10365 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010366 endif
10367
10368 " restore settings " {{{3
10369 let &ff= ffkeep
10370" call Dret("NetrwRemoteFtpCmd")
10371endfun
10372
10373" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010374" s:NetrwRemoteListing: {{{2
10375fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010376" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010377
Bram Moolenaara6878372014-03-22 21:02:50 +010010378 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10379 let w:netrw_bannercnt= s:bannercnt
10380 endif
10381 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
10382 let w:netrw_bannercnt= s:bannercnt
10383 endif
10384
Bram Moolenaar446cb832008-06-24 21:56:24 +000010385 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010386
Bram Moolenaar446cb832008-06-24 21:56:24 +000010387 " sanity check:
10388 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010389" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010390 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010391" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010392 if !exists("g:netrw_quiet")
10393 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10394 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010395 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010396" call Dret("s:NetrwRemoteListing -1")
10397 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010398 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010399
Bram Moolenaar8d043172014-01-23 14:24:41 +010010400 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010401" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010402 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010403 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010404 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 +000010405 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010406 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 +000010407 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010408 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010409
Bram Moolenaar85850f32019-07-19 22:05:51 +020010410 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010411" call Dret("s:NetrwRemoteListing -1")
10412 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010413 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010414" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010415
Bram Moolenaar446cb832008-06-24 21:56:24 +000010416 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010417" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010418 let w:netrw_method= b:netrw_method
10419 endif
10420
Bram Moolenaar13600302014-05-22 18:26:40 +020010421 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010422 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010423" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010424 let s:method = "ftp"
10425 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010426 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010427 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010428 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010429 let listcmd= g:netrw_ftp_sizelist_cmd
10430 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010431" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010432 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010433" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010434
Bram Moolenaara6878372014-03-22 21:02:50 +010010435 " report on missing file or directory messages
10436 if search('[Nn]o such file or directory\|Failed to change directory')
10437 let mesg= getline(".")
10438 if exists("w:netrw_bannercnt")
10439 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010440 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010441 setl noma
10442 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010443 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010444 call netrw#ErrorMsg(s:WARNING,mesg,96)
10445" call Dret("s:NetrwRemoteListing : -1")
10446 return -1
10447 endif
10448
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010449 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 +000010450 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010451" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010452 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010453
10454 " cleanup
10455 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010456 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10457 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010458 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010459 sil! NetrwKeepj %s/\r$//e
10460 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010462 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010463 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010464 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010465 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010466" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010467 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010468" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010469 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010471 exe "sil! NetrwKeepj ".line1
10472 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010473
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010474" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010475 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010476" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010477 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10478 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010481 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10482 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10483 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10484 NetrwKeepj call histdel("/",-1)
10485 NetrwKeepj call histdel("/",-1)
10486 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010487 endif
10488 endif
10489
Bram Moolenaar13600302014-05-22 18:26:40 +020010490 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010491 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010492" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010494" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010495 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010496" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10497 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010498 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010499 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10500 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10501 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10502 NetrwKeepj call histdel("/",-1)
10503 NetrwKeepj call histdel("/",-1)
10504 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010505 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010506 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10507 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010508 endif
10509 else
10510 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010511" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010512 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010513 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010514" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10515 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10516" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010517 endif
10518 endif
10519
10520 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010521 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010522" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010523 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10524 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010525 endif
10526 endif
10527
10528 if w:netrw_liststyle == s:LONGLIST
10529 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010530" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531
10532 if s:method == "ftp"
10533 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010534 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010535 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010536 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010537 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010538 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010539 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010540 sil! NetrwKeepj 1
10541 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010542 let line2= line(".")
10543 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010544 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010545 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010546 endif
10547 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010548 exe "sil! NetrwKeepj ".line1
10549 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010550 endif
10551
10552 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010553" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010554 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 +000010555 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010556" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010557 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010558 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010559 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10560 NetrwKeepj call histdel("/",-1)
10561 NetrwKeepj call histdel("/",-1)
10562 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010563 endif
10564 endif
10565
10566" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010567" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010568" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010569
10570" call Dret("s:NetrwRemoteListing 0")
10571 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010572endfun
10573
Bram Moolenaar446cb832008-06-24 21:56:24 +000010574" ---------------------------------------------------------------------
10575" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10576fun! s:NetrwRemoteRm(usrhost,path) range
10577" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010578" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010579 let svpos= winsaveview()
10580" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581
10582 let all= 0
10583 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10584 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010585" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010586 for fname in s:netrwmarkfilelist_{bufnr("%")}
10587 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010588 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010590 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010591 let all= 1
10592 endif
10593 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010594 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010595
10596 else
10597 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010598" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010599
10600 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010601 let keepsol = &l:sol
10602 setl nosol
10603 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010604
10605 " remove multiple files and directories
10606 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010607 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010608 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010609 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010610 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010611 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010612 let all= 1
10613 endif
10614 let ctr= ctr + 1
10615 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010616 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010617 endif
10618
10619 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010620" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010621 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010622" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10623 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010624
10625" call Dret("s:NetrwRemoteRm")
10626endfun
10627
10628" ---------------------------------------------------------------------
10629" s:NetrwRemoteRmFile: {{{2
10630fun! s:NetrwRemoteRmFile(path,rmfile,all)
10631" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10632
10633 let all= a:all
10634 let ok = ""
10635
10636 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10637 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010638" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010639 if !all
10640 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010641" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010642 call inputsave()
10643 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10644 call inputrestore()
10645 echohl NONE
10646 if ok == ""
10647 let ok="no"
10648 endif
10649 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010650 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010651 let all= 1
10652 endif
10653 endif
10654
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010655 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010656" 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 +000010657 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010658" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010659 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010660 if path =~ '^\a\{3,}://'
10661 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010662 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010663 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010664 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10665 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010666" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010667 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010668" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010669 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010670 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010671 let ok="q"
10672 else
10673 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010674" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10675" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10676" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010677 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010678 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010679 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010680 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010681 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010682" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010683 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010684 if v:shell_error != 0
10685 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +020010686 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 +010010687 else
10688 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10689 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010690 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010691 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010692 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010693" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010694 endif
10695 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010696 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010697" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010698 endif
10699
10700 else
10701 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010702" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010703 if !all
10704 call inputsave()
10705 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10706 call inputrestore()
10707 if ok == ""
10708 let ok="no"
10709 endif
10710 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010711 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010712 let all= 1
10713 endif
10714 endif
10715
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010716 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010717 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010718 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010719 else
10720 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010721 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10722" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010723 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010724" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010725
10726 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010727" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10728 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10729" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010730 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010731" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010732
10733 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010734 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010735 endif
10736 endif
10737 endif
10738
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010739 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010740" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010741 endif
10742 endif
10743
10744" call Dret("s:NetrwRemoteRmFile ".ok)
10745 return ok
10746endfun
10747
10748" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010749" s:NetrwRemoteRename: rename a remote file or directory {{{2
10750fun! s:NetrwRemoteRename(usrhost,path) range
10751" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10752
10753 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010754 let svpos = winsaveview()
10755" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010756 let ctr = a:firstline
10757 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10758
10759 " rename files given by the markfilelist
10760 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10761 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010762" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010763 if exists("subfrom")
10764 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010766 else
10767 call inputsave()
10768 let newname= input("Moving ".oldname." to : ",oldname)
10769 call inputrestore()
10770 if newname =~ '^s/'
10771 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10772 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10773 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010774" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010775 endif
10776 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010777
Bram Moolenaar446cb832008-06-24 21:56:24 +000010778 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010779 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010780 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010781 let oldname= s:ShellEscape(a:path.oldname)
10782 let newname= s:ShellEscape(a:path.newname)
10783" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010784 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010785 endif
10786
10787 endfor
10788 call s:NetrwUnMarkFile(1)
10789
10790 else
10791
10792 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010793 let keepsol= &l:sol
10794 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010795 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010796 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010797
10798 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010799" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010800
10801 call inputsave()
10802 let newname= input("Moving ".oldname." to : ",oldname)
10803 call inputrestore()
10804
10805 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10806 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10807 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010808 let oldname= s:ShellEscape(a:path.oldname)
10809 let newname= s:ShellEscape(a:path.newname)
10810" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010811 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010812 endif
10813
10814 let ctr= ctr + 1
10815 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010816 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010817 endif
10818
10819 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010820 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010821" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10822 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010823
10824" call Dret("NetrwRemoteRename")
10825endfun
10826
Bram Moolenaar85850f32019-07-19 22:05:51 +020010827" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010828" Local Directory Browsing Support: {{{1
10829" ==========================================
10830
10831" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010832" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010833" Should accept: file://localhost/etc/fstab
10834" file:///etc/fstab
10835" file:///c:/WINDOWS/clock.avi
10836" file:///c|/WINDOWS/clock.avi
10837" file://localhost/c:/WINDOWS/clock.avi
10838" file://localhost/c|/WINDOWS/clock.avi
10839" file://c:/foo.txt
10840" file:///c:/foo.txt
10841" 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 +020010842fun! netrw#FileUrlEdit(fname)
10843" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010844 let fname = a:fname
10845 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010846" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010847 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010848" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010849 endif
10850 if (has("win32") || has("win95") || has("win64") || has("win16"))
10851 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010852" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010853 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010854" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010855 endif
10856 endif
10857 let fname2396 = netrw#RFC2396(fname)
10858 let fname2396e= fnameescape(fname2396)
10859 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10860 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010861" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010862 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010863" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010864 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10865 endif
10866 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010867
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010868" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10869" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010870 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010871 exe 'NetrwKeepj keepalt edit '.plainfname
10872 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10873
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010874" 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 +020010875" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010876 exe "sil doau BufReadPost ".fname2396e
10877endfun
10878
10879" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010880" netrw#LocalBrowseCheck: {{{2
10881fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010882 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010883 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10884 "
10885 " unfortunate interaction -- split window debugging can't be used here, must use
10886 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10887 " another call to LocalBrowseCheck() when attempts to write
10888 " to the DBG buffer are made.
10889 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010890 " The &ft == "netrw" test was installed because the BufEnter event
10891 " would hit when re-entering netrw windows, creating unexpected
10892 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010893" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010894" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010895" 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 +010010896 " getting E930: Cannot use :redir inside execute
10897"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010898" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10899" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010900
Bram Moolenaar97d62492012-11-15 21:28:22 +010010901 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010902 if isdirectory(s:NetrwFile(a:dirname))
10903" 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 +010010904
Bram Moolenaar97d62492012-11-15 21:28:22 +010010905 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010906" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10907" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010908 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010909
Bram Moolenaar446cb832008-06-24 21:56:24 +000010910 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010911" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010912 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010913
Bram Moolenaar5c736222010-01-06 20:54:52 +010010914 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010915" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010916 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010917 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010918 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010919" 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 +010010920" call Dret("netrw#LocalBrowseCheck")
10921 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010922 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010923
Bram Moolenaar85850f32019-07-19 22:05:51 +020010924 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010925 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10926 " AND IF the listing style is not a tree listing
10927 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010928" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010929 let ibuf = 1
10930 let buflast = bufnr("$")
10931 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010932 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10933 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010934 endif
10935 let ibuf= ibuf + 1
10936 endwhile
10937 endif
10938 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010939" 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>"))
10940" 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 +000010941 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010942" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010943endfun
10944
10945" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010946" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010947" performed any shell command. The idea is to cause all local-browsing
10948" buffers to be refreshed after a user has executed some shell command,
10949" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010950fun! s:LocalBrowseRefresh()
10951" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010952" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10953" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010954
Bram Moolenaar446cb832008-06-24 21:56:24 +000010955 " determine which buffers currently reside in a tab
10956 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010957" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010958 return
10959 endif
10960 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010961" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010962 return
10963 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010964 if exists("s:netrw_events") && s:netrw_events == 1
10965 " s:LocalFastBrowser gets called (indirectly) from a
10966 let s:netrw_events= 2
10967" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10968 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010969 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010970 let itab = 1
10971 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010972 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010973 while itab <= tabpagenr("$")
10974 let buftablist = buftablist + tabpagebuflist()
10975 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010976 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010977 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010978" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10979" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010980 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10981 " | refresh any netrw window
10982 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010983 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010984 let ibl = 0
10985 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010986" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010987 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10988 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010989 " (ibuf not shown in a current window AND
10990 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010991" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10992 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010993 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010994" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010995 continue
10996 elseif index(tabpagebuflist(),ibuf) != -1
10997 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010998" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010999 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011000 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010011001 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
11002 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
11003 let g:netrw_quickhelp= g:netrw_quickhelp - 1
11004 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011005" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011006 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
11007 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11008 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011009 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011010 endif
11011 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011012" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011013 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011014" call Decho("restore window: win_gotoid(".curwinid.")")
11015 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011016 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011017
Bram Moolenaara6878372014-03-22 21:02:50 +010011018" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011019endfun
11020
11021" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011022" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11023"
11024" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011025" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011026" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11027" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011028" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011029"
11030" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11031" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011032" (re-using a buffer may not be as accurate)
11033"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011034" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011035" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11036" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11037" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11038" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011039fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011040" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11041" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11042" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11043" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011044
11045 " initialize browselist, a list of buffer numbers that the local browser has used
11046 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011047" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011048 let s:netrw_browselist= []
11049 endif
11050
11051 " append current buffer to fastbrowse list
11052 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011053" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011054 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011055" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011056 endif
11057
11058 " enable autocmd events to handle refreshing/removing local browser buffers
11059 " If local browse buffer is currently showing: refresh it
11060 " If local browse buffer is currently hidden : wipe it
11061 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11062 " =1 : medium speed, re-use directory listing for remote only
11063 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011064 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11065 let s:netrw_events= 1
11066 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011067 au!
11068 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011069" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011070 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011071 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011072" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011073 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011074 endif
11075 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011076
11077 " user must have changed fastbrowse to its fast setting, so remove
11078 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011079 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011080" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011081 unlet s:netrw_events
11082 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011083 au!
11084 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011085 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011086 endif
11087
Bram Moolenaar85850f32019-07-19 22:05:51 +020011088" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011089endfun
11090
11091" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011092" s:LocalListing: does the job of "ls" for local directories {{{2
11093fun! s:LocalListing()
11094" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011095" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11096" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11097" 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 +010011098
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011099" 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
11100" 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
11101" 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 +010011102
11103 " get the list of files contained in the current directory
11104 let dirname = b:netrw_curdir
11105 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011106 let filelist = s:NetrwGlob(dirname,"*",0)
11107 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011108" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011109
11110 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011111" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011112 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11113 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011115 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011116" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011117 endif
11118
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011119" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011120" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011121" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011122
11123 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11124 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11125 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011126" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11127" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011128 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011129" 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 +010011130
11131 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011132" call Decho(" ",'~'.expand("<slnum>"))
11133" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011134
11135 if getftype(filename) == "link"
11136 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011137" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011138 let pfile= filename."@"
11139
11140 elseif getftype(filename) == "socket"
11141 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011142" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011143 let pfile= filename."="
11144
11145 elseif getftype(filename) == "fifo"
11146 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011147" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011148 let pfile= filename."|"
11149
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011150 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011151 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011152" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011153 let pfile= filename."/"
11154
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011155 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011156 if (has("win32") || has("win95") || has("win64") || has("win16"))
11157 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11158 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011159" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011160 let pfile= filename."*"
11161 else
11162 " normal file
11163 let pfile= filename
11164 endif
11165 elseif executable(filename)
11166 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011167" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011168 let pfile= filename."*"
11169 else
11170 " normal file
11171 let pfile= filename
11172 endif
11173
11174 else
11175 " normal file
11176 let pfile= filename
11177 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011178" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011179
11180 if pfile =~ '//$'
11181 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011182" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011183 endif
11184 let pfile= strpart(pfile,dirnamelen)
11185 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011186" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11187" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011188
11189 if w:netrw_liststyle == s:LONGLIST
11190 let sz = getfsize(filename)
Bram Moolenaar71badf92023-04-22 22:40:14 +010011191 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11192 let szlen = (szlen > 0) ? szlen : 0
11193 let fsz = printf("%".szlen."S",sz)
11194
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011195 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011196 let sz= s:NetrwHumanReadable(sz)
11197 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +010011198 let longfile= printf("%-".g:netrw_maxfilenamelen."S",pfile)
11199 let pfile = longfile." ".sz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011200" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011201 endif
11202
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011203 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011204 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011205 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011206" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011207" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011208 let t = getftime(filename)
11209 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar91359012019-11-30 17:57:03 +010011210" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011211 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011212 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011213
11214 elseif g:netrw_sort_by =~ "^s"
11215 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011216" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011217" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011218 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011219 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011220 let sz= s:NetrwHumanReadable(sz)
11221 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011222 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011223" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011224 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011225 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011226
11227 else
11228 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011229" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011230" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011231 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011232 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011233" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011234 endfor
11235
11236 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011237 sil! NetrwKeepj g/^$/d
11238 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011239 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011240" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011241 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11242
11243" call Dret("s:LocalListing")
11244endfun
11245
11246" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011247" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11248fun! s:NetrwLocalExecute(cmd)
11249" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11250 let ykeep= @@
11251 " sanity check
11252 if !executable(a:cmd)
11253 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11254 let @@= ykeep
11255" call Dret("s:NetrwLocalExecute")
11256 return
11257 endif
11258
11259 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011260" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011261 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011262" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011263
11264 " strip any ansi escape sequences off
11265 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11266
11267 " show user the result(s)
11268 echomsg result
11269 let @@= ykeep
11270
11271" call Dret("s:NetrwLocalExecute")
11272endfun
11273
11274" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011275" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011276fun! s:NetrwLocalRename(path) range
11277" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11278
11279 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011280 let ykeep = @@
11281 let ctr = a:firstline
11282 let svpos = winsaveview()
11283 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011284" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011285
11286 " rename files given by the markfilelist
11287 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11288 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011289" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011290 if exists("subfrom")
11291 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011292" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011293 else
11294 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011295 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011296 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011297 if newname =~ ''
11298 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11299 let newname = substitute(newname,'^.*','','')
11300 elseif newname =~ ''
11301 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11302 let newname = substitute(newname,'[^/]*','','')
11303 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011304 if newname =~ '^s/'
11305 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11306 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011307" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011308 let newname = substitute(oldname,subfrom,subto,'')
11309 endif
11310 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011311 if !all && filereadable(newname)
11312 call inputsave()
11313 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11314 call inputrestore()
11315 if response == "all"
11316 let all= 1
11317 elseif response != "y" && response != "yes"
11318 " refresh the directory
11319" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11320 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11321" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11322 NetrwKeepj call winrestview(svpos)
11323 let @@= ykeep
11324" call Dret("NetrwLocalRename")
11325 return
11326 endif
11327 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011328 call rename(oldname,newname)
11329 endfor
11330 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011331
Bram Moolenaar97d62492012-11-15 21:28:22 +010011332 else
11333
11334 " attempt to rename files/directories
11335 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011336 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011337
11338 " sanity checks
11339 if line(".") < w:netrw_bannercnt
11340 let ctr= ctr + 1
11341 continue
11342 endif
11343 let curword= s:NetrwGetWord()
11344 if curword == "./" || curword == "../"
11345 let ctr= ctr + 1
11346 continue
11347 endif
11348
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011349 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011350 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011351" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011352
11353 call inputsave()
11354 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11355 call inputrestore()
11356
11357 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011358" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011359
11360 let ctr= ctr + 1
11361 endwhile
11362 endif
11363
11364 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011365" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011366 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011367" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11368 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011369 let @@= ykeep
11370
11371" call Dret("NetrwLocalRename")
11372endfun
11373
11374" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011375" s:NetrwLocalRm: {{{2
11376fun! s:NetrwLocalRm(path) range
11377" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011378" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011379
11380 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011381 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011382 let ret = 0
11383 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011384 let svpos = winsaveview()
11385" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011386
11387 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11388 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011389" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011390 for fname in s:netrwmarkfilelist_{bufnr("%")}
11391 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011392 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011393 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011394 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011395 let all= 1
11396 endif
11397 endfor
11398 call s:NetrwUnMarkFile(1)
11399
11400 else
11401 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011402" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011403
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011404 let keepsol= &l:sol
11405 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011406 let ctr = a:firstline
11407 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011408 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011409
11410 " sanity checks
11411 if line(".") < w:netrw_bannercnt
11412 let ctr= ctr + 1
11413 continue
11414 endif
11415 let curword= s:NetrwGetWord()
11416 if curword == "./" || curword == "../"
11417 let ctr= ctr + 1
11418 continue
11419 endif
11420 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011421 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011422 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011423 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011424 let all= 1
11425 endif
11426 let ctr= ctr + 1
11427 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011428 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011429 endif
11430
11431 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011432" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011433 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011434 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011435" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11436 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011437 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011438 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011439
11440" call Dret("s:NetrwLocalRm")
11441endfun
11442
11443" ---------------------------------------------------------------------
11444" s:NetrwLocalRmFile: remove file fname given the path {{{2
11445" Give confirmation prompt unless all==1
11446fun! s:NetrwLocalRmFile(path,fname,all)
11447" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011448
Bram Moolenaar446cb832008-06-24 21:56:24 +000011449 let all= a:all
11450 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011451 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011452 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11453" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011454
11455 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11456 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011457" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011458 if !all
11459 echohl Statement
11460 call inputsave()
11461 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11462 call inputrestore()
11463 echohl NONE
11464 if ok == ""
11465 let ok="no"
11466 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011467" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011468 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011469" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011470 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011471 let all= 1
11472 endif
11473 endif
11474
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011475 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011476 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011477" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011478 endif
11479
11480 else
11481 " attempt to remove directory
11482 if !all
11483 echohl Statement
11484 call inputsave()
11485 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11486 call inputrestore()
11487 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11488 if ok == ""
11489 let ok="no"
11490 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011491 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011492 let all= 1
11493 endif
11494 endif
11495 let rmfile= substitute(rmfile,'[\/]$','','e')
11496
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011497 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar71badf92023-04-22 22:40:14 +010011498 if delete(rmfile,"d")
11499 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011500 endif
11501 endif
11502 endif
11503
11504" call Dret("s:NetrwLocalRmFile ".ok)
11505 return ok
11506endfun
11507
Bram Moolenaar85850f32019-07-19 22:05:51 +020011508" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011509" Support Functions: {{{1
11510
Bram Moolenaar488c6512005-08-11 20:09:58 +000011511" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011512" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11513" 0: marked file list of current buffer
11514" 1: marked file target
11515fun! netrw#Access(ilist)
11516 if a:ilist == 0
11517 if exists("s:netrwmarkfilelist_".bufnr('%'))
11518 return s:netrwmarkfilelist_{bufnr('%')}
11519 else
11520 return "no-list-buf#".bufnr('%')
11521 endif
11522 elseif a:ilist == 1
11523 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011524 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011525endfun
11526
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011527" ---------------------------------------------------------------------
11528" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11529fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011530 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011531endfun
11532
Bram Moolenaara6878372014-03-22 21:02:50 +010011533" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011534" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11535" I expect this function to be used in
11536" :PChkAssert netrw#Expose("netrwmarkfilelist")
11537" for example.
11538fun! netrw#Expose(varname)
11539" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011540 if exists("s:".a:varname)
11541 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011542" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011543 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011544" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011545 if type(retval) == 3
11546 let retval = copy(retval)
11547 let i = 0
11548 while i < len(retval)
11549 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11550 let i = i + 1
11551 endwhile
11552 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011553" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011554 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011555 else
11556" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011557 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011558 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011559" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011560 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011561 endif
11562
11563" call Dret("netrw#Expose ".string(retval))
11564 return retval
11565endfun
11566
11567" ---------------------------------------------------------------------
11568" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11569fun! netrw#Modify(varname,newvalue)
11570" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11571 exe "let s:".a:varname."= ".string(a:newvalue)
11572" call Dret("netrw#Modify")
11573endfun
11574
11575" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011576" netrw#RFC2396: converts %xx into characters {{{2
11577fun! netrw#RFC2396(fname)
11578" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
11579 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
11580" call Dret("netrw#RFC2396 ".fname)
11581 return fname
11582endfun
11583
11584" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011585" netrw#UserMaps: supports user-specified maps {{{2
11586" see :help function()
11587"
11588" g:Netrw_UserMaps is a List with members such as:
11589" [[keymap sequence, function reference],...]
11590"
11591" The referenced function may return a string,
11592" refresh : refresh the display
11593" -other- : this string will be executed
11594" or it may return a List of strings.
11595"
11596" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011597" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011598" Related functions:
11599" netrw#Expose(varname) -- see s:varname variables
11600" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11601" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11602fun! netrw#UserMaps(islocal)
11603" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11604" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11605
11606 " set up usermaplist
11607 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11608" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11609 for umap in g:Netrw_UserMaps
11610" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11611" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11612 " if umap[0] is a string and umap[1] is a string holding a function name
11613 if type(umap[0]) == 1 && type(umap[1]) == 1
11614" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11615 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11616 else
11617 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11618 endif
11619 endfor
11620 endif
11621" call Dret("netrw#UserMaps")
11622endfun
11623
11624" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011625" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11626fun! netrw#WinPath(path)
11627" call Dfunc("netrw#WinPath(path<".a:path.">)")
11628 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11629 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011630 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011631 " remove trailing slash (Win95)
11632 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11633 " remove escaped spaces
11634 let path = substitute(path, '\ ', ' ', 'g')
11635 " convert slashes to backslashes
11636 let path = substitute(path, '/', '\', 'g')
11637 else
11638 let path= a:path
11639 endif
11640" call Dret("netrw#WinPath <".path.">")
11641 return path
11642endfun
11643
11644" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011645" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11646" cb : bl2mf=0 add marked files to buffer list
11647" cB : bl2mf=1 use bufferlist to mark files
11648" (mnemonic: cb = copy (marked files) to buffer list)
11649fun! s:NetrwBadd(islocal,bl2mf)
11650" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11651 if a:bl2mf
11652 " cB: add buffer list to marked files
11653 redir => bufl
11654 ls
11655 redir END
11656 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11657 for fname in bufl
11658 call s:NetrwMarkFile(a:islocal,fname)
11659 endfor
11660 else
11661 " cb: add marked files to buffer list
11662 for fname in s:netrwmarkfilelist_{bufnr("%")}
11663" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11664 exe "badd ".fnameescape(fname)
11665 endfor
11666 let curbufnr = bufnr("%")
11667 let curdir = s:NetrwGetCurdir(a:islocal)
11668 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11669 endif
11670" call Dret("s:NetrwBadd")
11671endfun
11672
11673" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011674" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11675fun! s:ComposePath(base,subdir)
11676" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11677
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011678 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011679" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011680 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011681 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011682 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011683 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011684 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011685 endif
11686
Bram Moolenaar85850f32019-07-19 22:05:51 +020011687 " COMBAK: test on windows with changing to root directory: :e C:/
11688 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011689" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011690 let ret= a:subdir
11691
Bram Moolenaar85850f32019-07-19 22:05:51 +020011692 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011693" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011694 if a:base =~ '[/\\]$'
11695 let ret= a:base.a:subdir
11696 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011697 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011698 endif
11699
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011700 elseif a:base =~ '^\a\{3,}://'
11701" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011702 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11703 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11704 if a:subdir == '../'
11705 if curpath =~ '[^/]/[^/]\+/$'
11706 let curpath= substitute(curpath,'[^/]\+/$','','')
11707 else
11708 let curpath=""
11709 endif
11710 let ret= urlbase.curpath
11711 else
11712 let ret= urlbase.curpath.a:subdir
11713 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011714" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11715" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11716" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011717
11718 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011719" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011720 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11721 if a:base =~ '^//'
11722 " keeping initial '//' for the benefit of network share listing support
11723 let ret= '/'.ret
11724 endif
11725 let ret= simplify(ret)
11726 endif
11727
11728" call Dret("s:ComposePath ".ret)
11729 return ret
11730endfun
11731
11732" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011733" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11734" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11735fun! s:DeleteBookmark(fname)
11736" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11737 call s:MergeBookmarks()
11738
11739 if exists("g:netrw_bookmarklist")
11740 let indx= index(g:netrw_bookmarklist,a:fname)
11741 if indx == -1
11742 let indx= 0
11743 while indx < len(g:netrw_bookmarklist)
11744 if g:netrw_bookmarklist[indx] =~ a:fname
11745 call remove(g:netrw_bookmarklist,indx)
11746 let indx= indx - 1
11747 endif
11748 let indx= indx + 1
11749 endwhile
11750 else
11751 " remove exact match
11752 call remove(g:netrw_bookmarklist,indx)
11753 endif
11754 endif
11755
11756" call Dret("s:DeleteBookmark")
11757endfun
11758
11759" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011760" s:FileReadable: o/s independent filereadable {{{2
11761fun! s:FileReadable(fname)
11762" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11763
11764 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011765 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011766 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011767 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011768 endif
11769
11770" call Dret("s:FileReadable ".ret)
11771 return ret
11772endfun
11773
11774" ---------------------------------------------------------------------
11775" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11776" Places correct suffix on end of temporary filename,
11777" using the suffix provided with fname
11778fun! s:GetTempfile(fname)
11779" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11780
11781 if !exists("b:netrw_tmpfile")
11782 " get a brand new temporary filename
11783 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011784" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011785
Bram Moolenaarc236c162008-07-13 17:41:49 +000011786 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011787" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011788
Bram Moolenaar9964e462007-05-05 17:54:07 +000011789 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011790 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11791" 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 +010011792 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011793" call Dret("s:GetTempfile getcwd<".getcwd().">")
11794 return ""
11795 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011796
Bram Moolenaar9964e462007-05-05 17:54:07 +000011797 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011798 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011799" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011800
Bram Moolenaar9964e462007-05-05 17:54:07 +000011801 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011802 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011803 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011804 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011805 if !exists("+shellslash") || !&ssl
11806 let tmpfile = substitute(tmpfile,'/','\','g')
11807 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011808 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011809 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011810 endif
11811 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011812" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011813 else
11814 " re-use temporary filename
11815 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011816" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011817 endif
11818
11819 " use fname's suffix for the temporary file
11820 if a:fname != ""
11821 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011822" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011823 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011824 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011825 elseif a:fname =~ '.txz$'
11826 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011827 else
11828 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11829 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011830" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011831 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011832" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011833 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011834" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011835 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11836 endif
11837 endif
11838
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011839" 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 +000011840" call Dret("s:GetTempfile <".tmpfile.">")
11841 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011842endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011843
11844" ---------------------------------------------------------------------
11845" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011846" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011847fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011848" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011849 if s:user == ""
11850 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11851 else
11852 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11853 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011854 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011855 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011856 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011857 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011858 else
11859 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11860 endif
11861" call Dret("s:MakeSshCmd <".sshcmd.">")
11862 return sshcmd
11863endfun
11864
11865" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011866" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11867fun! s:MakeBookmark(fname)
11868" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11869
11870 if !exists("g:netrw_bookmarklist")
11871 let g:netrw_bookmarklist= []
11872 endif
11873
11874 if index(g:netrw_bookmarklist,a:fname) == -1
11875 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011876 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011877 call add(g:netrw_bookmarklist,a:fname.'/')
11878 elseif a:fname !~ '/'
11879 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11880 else
11881 call add(g:netrw_bookmarklist,a:fname)
11882 endif
11883 call sort(g:netrw_bookmarklist)
11884 endif
11885
11886" call Dret("s:MakeBookmark")
11887endfun
11888
11889" ---------------------------------------------------------------------
11890" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11891fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011892" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011893 " get bookmarks from .netrwbook file
11894 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011895 if filereadable(s:NetrwFile(savefile))
11896" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011897 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011898" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011899 NetrwKeepj call delete(savefile)
11900 endif
11901" call Dret("s:MergeBookmarks")
11902endfun
11903
11904" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011905" s:NetrwBMShow: {{{2
11906fun! s:NetrwBMShow()
11907" call Dfunc("s:NetrwBMShow()")
11908 redir => bmshowraw
11909 menu
11910 redir END
11911 let bmshowlist = split(bmshowraw,'\n')
11912 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011913 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011914 if bmshowfuncs != []
11915 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011916 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011917 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011918 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011919 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011920 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011921" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11922endfun
11923
11924" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011925" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011926fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011927 if !exists("w:netrw_liststyle")
11928 let w:netrw_liststyle= g:netrw_liststyle
11929 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011930" 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 +020011931
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011932" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11933
Bram Moolenaaradc21822011-04-01 18:03:16 +020011934 if &ft != "netrw"
11935 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11936 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011937" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011938
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011939 elseif g:netrw_cursor == 8
11940 if w:netrw_liststyle == s:WIDELIST
11941 setl cursorline
11942 setl cursorcolumn
11943 else
11944 setl cursorline
11945 endif
11946 elseif g:netrw_cursor == 7
11947 setl cursorline
11948 elseif g:netrw_cursor == 6
11949 if w:netrw_liststyle == s:WIDELIST
11950 setl cursorline
11951 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011952 elseif g:netrw_cursor == 4
11953 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011954" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011955 setl cursorline
11956 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011957
11958 elseif g:netrw_cursor == 3
11959 " thin-long-tree: cursorline, user's cursorcolumn
11960 " wide : cursorline, cursorcolumn
11961 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011962" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011963 setl cursorline
11964 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011965 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011966" 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 +020011967 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011968 endif
11969
11970 elseif g:netrw_cursor == 2
11971 " thin-long-tree: cursorline, user's cursorcolumn
11972 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011973" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011974 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011975
11976 elseif g:netrw_cursor == 1
11977 " thin-long-tree: user's cursorline, user's cursorcolumn
11978 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011979 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011980" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011981 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011982 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011983" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011984 endif
11985
11986 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011987 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011988" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011989 let &l:cursorline = s:netrw_usercul
11990 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011991 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011992
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011993" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011994" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011995endfun
11996
11997" ---------------------------------------------------------------------
11998" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11999fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012000" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012001 if exists("s:netrw_usercul")
12002 let &l:cursorline = s:netrw_usercul
12003 endif
12004 if exists("s:netrw_usercuc")
12005 let &l:cursorcolumn = s:netrw_usercuc
12006 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012007" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012008" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12009endfun
12010
12011" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012012" s:NetrwDelete: Deletes a file. {{{2
12013" Uses Steve Hall's idea to insure that Windows paths stay
12014" acceptable. No effect on Unix paths.
12015" Examples of use: let result= s:NetrwDelete(path)
12016fun! s:NetrwDelete(path)
12017" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12018
Bram Moolenaar5c736222010-01-06 20:54:52 +010012019 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012020 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
12021 if exists("+shellslash")
12022 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012023 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012024 let result = delete(path)
12025 let &shellslash = sskeep
12026 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012027" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012028 let result= delete(path)
12029 endif
12030 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012031" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012032 let result= delete(path)
12033 endif
12034 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012035 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012036 endif
12037
12038" call Dret("s:NetrwDelete ".result)
12039 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012040endfun
12041
12042" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012043" s:NetrwBufRemover: removes a buffer that: {{{2s
12044" has buffer-id > 1
12045" is unlisted
12046" is unnamed
12047" does not appear in any window
12048fun! s:NetrwBufRemover(bufid)
12049" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12050" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12051" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12052" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12053" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12054
yasuda4dbb2662023-10-04 20:50:35 +020012055 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012056" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012057 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012058 endif
12059
12060" call Dret("s:NetrwBufRemover")
12061endfun
12062
12063" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012064" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012065fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012066" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012067" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012068
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012069 " Clean out the last buffer:
12070 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12071 " If so, delete it.
12072 call s:NetrwBufRemover(bufnr("$"))
12073
Bram Moolenaar446cb832008-06-24 21:56:24 +000012074 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012075" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012076 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12077 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12078 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12079 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12080 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12081 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12082 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12083 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12084 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12085 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12086 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12087 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12088 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12089 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12090 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12091 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12092
Bram Moolenaar85850f32019-07-19 22:05:51 +020012093 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012094" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012095 " when tree listing uses file TreeListing... a new buffer is made.
12096 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012097 " COMBAK: this causes a problem, see P43
12098" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012099 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012100 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012101 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012102" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012103 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012104
Bram Moolenaar446cb832008-06-24 21:56:24 +000012105 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012106" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012107 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12108 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12109 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12110 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12111 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12112 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12113 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12114 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12115 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12116 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12117 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12118 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12119 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12120 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12121 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12122 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12123
Bram Moolenaar5c736222010-01-06 20:54:52 +010012124 if a:0 > 0
12125 let b:netrw_curdir= a:1
12126 if b:netrw_curdir =~ '/$'
12127 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012128 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012129 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012130 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012131 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12132 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012133 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012134 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012135 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012136 endif
12137 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012138 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12139 let &l:bexpr = "netrw#BalloonHelp()"
12140 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012141
Bram Moolenaar8d043172014-01-23 14:24:41 +010012142" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012143endfun
12144
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012145" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012146" s:NetrwExe: executes a string using "!" {{{2
12147fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012148" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012149 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012150" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012151 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12152 set shell& shellcmdflag& shellxquote& shellxescape&
12153 set shellquote& shellpipe& shellredir& shellslash&
12154 exe a:cmd
12155 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12156 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012157" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012158 exe a:cmd
12159 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012160 if v:shell_error
12161 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12162 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012163" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012164endfun
12165
12166" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012167" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12168fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012169 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012170" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012171 let curbuf = bufnr("%")
12172 let curwin = winnr()
12173 let iwin = 1
12174 while iwin <= winnr("$")
12175 exe iwin."wincmd w"
12176 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12177 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12178 let winvars= w:
12179 break
12180 endif
12181 let iwin= iwin + 1
12182 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012183 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012184 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012185" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012186 for k in keys(winvars)
12187 let w:{k}= winvars[k]
12188 endfor
12189 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012190" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012191 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012192endfun
12193
Bram Moolenaara6878372014-03-22 21:02:50 +010012194" ---------------------------------------------------------------------
12195" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012196" Returns: 0=success
12197" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012198fun! s:NetrwLcd(newdir)
12199" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012200" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012201
Bram Moolenaar85850f32019-07-19 22:05:51 +020012202 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012203 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012204 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012205 catch /^Vim\%((\a\+)\)\=:E344/
12206 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12207 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012208 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012209 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12210 " forward slashes by earlier code; so check for both.
12211 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
12212 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12213 let dirname = '\'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012214 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012215 endif
12216 endif
12217 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012218 let err472= 1
12219 endtry
12220
12221 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012222 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12223 if exists("w:netrw_prvdir")
12224 let a:newdir= w:netrw_prvdir
12225 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012226 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012227" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012228 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012229" 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 +010012230 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012231 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012232" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12233 return -1
12234 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012235
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012236" call Decho("getcwd <".getcwd().">")
12237" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012238" call Dret("s:NetrwLcd 0")
12239 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012240endfun
12241
Bram Moolenaar9964e462007-05-05 17:54:07 +000012242" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012243" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12244" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12245fun! s:NetrwSaveWordPosn()
12246" call Dfunc("NetrwSaveWordPosn()")
12247 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12248" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12249endfun
12250
12251" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012252" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12253" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12254fun! s:NetrwHumanReadable(sz)
12255" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12256
12257 if g:netrw_sizestyle == 'h'
12258 if a:sz >= 1000000000
12259 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12260 elseif a:sz >= 10000000
12261 let sz = printf("%d",a:sz/1000000)."m"
12262 elseif a:sz >= 1000000
12263 let sz = printf("%.1f",a:sz/1000000.0)."m"
12264 elseif a:sz >= 10000
12265 let sz = printf("%d",a:sz/1000)."k"
12266 elseif a:sz >= 1000
12267 let sz = printf("%.1f",a:sz/1000.0)."k"
12268 else
12269 let sz= a:sz
12270 endif
12271
12272 elseif g:netrw_sizestyle == 'H'
12273 if a:sz >= 1073741824
12274 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12275 elseif a:sz >= 10485760
12276 let sz = printf("%d",a:sz/1048576)."M"
12277 elseif a:sz >= 1048576
12278 let sz = printf("%.1f",a:sz/1048576.0)."M"
12279 elseif a:sz >= 10240
12280 let sz = printf("%d",a:sz/1024)."K"
12281 elseif a:sz >= 1024
12282 let sz = printf("%.1f",a:sz/1024.0)."K"
12283 else
12284 let sz= a:sz
12285 endif
12286
12287 else
12288 let sz= a:sz
12289 endif
12290
12291" call Dret("s:NetrwHumanReadable ".sz)
12292 return sz
12293endfun
12294
12295" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012296" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12297" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12298fun! s:NetrwRestoreWordPosn()
12299" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012300 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012301" call Dret("NetrwRestoreWordPosn")
12302endfun
12303
12304" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012305" s:RestoreBufVars: {{{2
12306fun! s:RestoreBufVars()
12307" call Dfunc("s:RestoreBufVars()")
12308
12309 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12310 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12311 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12312 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12313 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12314 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12315
12316" call Dret("s:RestoreBufVars")
12317endfun
12318
12319" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012320" s:RemotePathAnalysis: {{{2
12321fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012322" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012323
Bram Moolenaara6878372014-03-22 21:02:50 +010012324 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012325 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012326 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012327 let s:user = substitute(a:dirname,dirpat,'\3','')
12328 let s:machine = substitute(a:dirname,dirpat,'\4','')
12329 let s:port = substitute(a:dirname,dirpat,'\5','')
12330 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012331 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012332 if s:machine =~ '@'
12333 let dirpat = '^\(.*\)@\(.\{-}\)$'
12334 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12335 let s:machine = substitute(s:machine,dirpat,'\2','')
12336 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012337
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012338" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12339" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12340" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12341" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12342" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12343" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012344
12345" call Dret("s:RemotePathAnalysis")
12346endfun
12347
12348" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012349" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12350" Returns status
12351" Runs system() on
12352" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012353" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012354fun! s:RemoteSystem(cmd)
12355" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12356 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012357 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 +000012358 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012359 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012360 else
12361 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12362 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12363 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012364 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012365 else
12366 let cmd= cmd.' '
12367 endif
12368 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012369" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012370 let ret= system(cmd)
12371 endif
12372" call Dret("s:RemoteSystem ".ret)
12373 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012374endfun
12375
12376" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012377" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012378fun! s:RestoreWinVars()
12379" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012380 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012381 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12382 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12383 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12384 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12385 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12386 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12387 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12388 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12389 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12390 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12391 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12392 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012393 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12394 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012395 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12396 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12397 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12398" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012399endfun
12400
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012401" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012402" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12403"
12404" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12405" is true) and a command, :Rexplore, which call this function.
12406"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012407" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012408"
12409" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012410fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012411 if exists("s:netrwdrag")
12412 return
12413 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012414" 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 +010012415" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12416" 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 +010012417
12418 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012419 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012420" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012421 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012422 unlet w:netrw_rexfile
12423" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012424 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012425" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012426" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12427" 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 +020012428 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012429
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012430 " ---------------------------
12431 " :Rex issued while in a file
12432 " ---------------------------
12433
Bram Moolenaara6878372014-03-22 21:02:50 +010012434 " record current file so :Rex can return to it from netrw
12435 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012436" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012437
12438 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012439" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012440 return
12441 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012442" 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 +020012443 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012444 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012445 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012446 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012447 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012448 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012449 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012450 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012451 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012452" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12453 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012454" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12455 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012456 if exists("s:rexposn_".bufnr('%'))
12457 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012458 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012459 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012460" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012461 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012462
Bram Moolenaar85850f32019-07-19 22:05:51 +020012463 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12464 if exists("s:explore_match")
12465 exe "2match netrwMarkFile /".s:explore_match."/"
12466 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012467 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012468
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012469" 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 +010012470" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012471endfun
12472
12473" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012474" s:SaveBufVars: save selected b: variables to s: variables {{{2
12475" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012476fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012477" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012478
12479 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12480 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12481 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12482 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12483 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12484 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12485
12486" call Dret("s:SaveBufVars")
12487endfun
12488
12489" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012490" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12491fun! s:SavePosn(posndict)
12492" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12493
Bram Moolenaar85850f32019-07-19 22:05:51 +020012494 if !exists("a:posndict[bufnr('%')]")
12495 let a:posndict[bufnr("%")]= []
12496 endif
12497" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12498 call add(a:posndict[bufnr("%")],winsaveview())
12499" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012500
12501" call Dret("s:SavePosn posndict")
12502 return a:posndict
12503endfun
12504
12505" ---------------------------------------------------------------------
12506" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12507fun! s:RestorePosn(posndict)
12508" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012509 if exists("a:posndict")
12510 if has_key(a:posndict,bufnr("%"))
12511" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12512 let posnlen= len(a:posndict[bufnr("%")])
12513 if posnlen > 0
12514 let posnlen= posnlen - 1
12515" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12516 call winrestview(a:posndict[bufnr("%")][posnlen])
12517 call remove(a:posndict[bufnr("%")],posnlen)
12518" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12519 endif
12520 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012521 endif
12522" call Dret("s:RestorePosn")
12523endfun
12524
12525" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012526" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012527fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012528" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012529 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12530 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12531 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12532 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12533 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12534 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12535 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12536 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12537 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12538 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12539 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12540 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12541 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12542 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12543 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12544 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12545 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12546 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12547" call Dret("s:SaveWinVars")
12548endfun
12549
12550" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012551" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012552" To allow separate windows to have their own activities, such as
12553" Explore **/pattern, several variables have been made window-oriented.
12554" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012555" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012556" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012557fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012558" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012559 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12560 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12561 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12562 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12563 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12564 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12565 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12566 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12567 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12568 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12569" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012570endfun
12571
12572" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012573" s:SetRexDir: set directory for :Rexplore {{{2
12574fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012575" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012576 let w:netrw_rexdir = a:dirname
12577 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012578 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012579" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12580" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012581" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012582" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012583" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012584endfun
12585
12586" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012587" s:ShowLink: used to modify thin and tree listings to show links {{{2
12588fun! s:ShowLink()
12589" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012590" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12591" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012592 if exists("b:netrw_curdir")
12593 norm! $?\a
12594 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12595 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012596" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12597" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12598" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12599 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012600 let dirlen = strlen(b:netrw_curdir)
12601 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012602" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012603 endif
12604 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012605" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12606" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012607 setl noro ma
12608 call setline(".",modline)
12609 setl ro noma nomod
12610 endif
12611" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12612endfun
12613
12614" ---------------------------------------------------------------------
12615" s:ShowStyle: {{{2
12616fun! s:ShowStyle()
12617 if !exists("w:netrw_liststyle")
12618 let liststyle= g:netrw_liststyle
12619 else
12620 let liststyle= w:netrw_liststyle
12621 endif
12622 if liststyle == s:THINLIST
12623 return s:THINLIST.":thin"
12624 elseif liststyle == s:LONGLIST
12625 return s:LONGLIST.":long"
12626 elseif liststyle == s:WIDELIST
12627 return s:WIDELIST.":wide"
12628 elseif liststyle == s:TREELIST
12629 return s:TREELIST.":tree"
12630 else
12631 return 'n/a'
12632 endif
12633endfun
12634
12635" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012636" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12637" Solution from Nicolai Weibull, vim docs (:help strlen()),
12638" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012639fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012640" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12641
12642 if v:version >= 703 && exists("*strdisplaywidth")
12643 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012644
Bram Moolenaar8d043172014-01-23 14:24:41 +010012645 elseif type(g:Align_xstrlen) == 1
12646 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12647 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012648
Bram Moolenaar8d043172014-01-23 14:24:41 +010012649 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012650 " number of codepoints (Latin a + combining circumflex is two codepoints)
12651 " (comment from TM, solution from NW)
12652 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012653
Bram Moolenaar8d043172014-01-23 14:24:41 +010012654 elseif g:Align_xstrlen == 2
12655 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012656 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12657 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012658 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012659
Bram Moolenaar8d043172014-01-23 14:24:41 +010012660 elseif g:Align_xstrlen == 3
12661 " virtual length (counting, for instance, tabs as anything between 1 and
12662 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012663 " preceded by lam, one otherwise, etc.)
12664 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012665 let modkeep= &l:mod
12666 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012667 call setline(line("."),a:x)
12668 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012669 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012670 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012671 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012672
Bram Moolenaar446cb832008-06-24 21:56:24 +000012673 else
12674 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012675 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012676 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012677" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012678 return ret
12679endfun
12680
12681" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012682" s:ShellEscape: shellescape(), or special windows handling {{{2
12683fun! s:ShellEscape(s, ...)
12684 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12685 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12686 endif
12687 let f = a:0 > 0 ? a:1 : 0
12688 return shellescape(a:s, f)
12689endfun
12690
12691" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012692" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012693fun! s:TreeListMove(dir)
12694" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012695 let curline = getline('.')
12696 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12697 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12698 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12699 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12700 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12701 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12702" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12703" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12704" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12705" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12706" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12707 " COMBAK : need to handle when on a directory
12708 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012709 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012710 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012711 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012712 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012713" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012714 elseif a:dir == '[]' && nxtline != ''
12715 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012716" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012717 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12718 if nl != 0
12719 NetrwKeepj norm! k
12720 else
12721 NetrwKeepj norm! G
12722 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012723" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012724 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012725 endif
12726
12727" call Dret("s:TreeListMove")
12728endfun
12729
12730" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012731" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12732" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12733" can't be called except via emenu. But due to locale, that menu line may not be called
12734" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12735fun! s:UpdateBuffersMenu()
12736" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012737 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012738 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012739 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012740 catch /^Vim\%((\a\+)\)\=:E/
12741 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012742 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012743 endtry
12744 endif
12745" call Dret("s:UpdateBuffersMenu")
12746endfun
12747
12748" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012749" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012750" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012751fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012752" call Dfunc("s:UseBufWinVars()")
12753 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012754 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12755 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12756 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12757 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12758 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12759 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12760 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12761 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12762 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 +000012763" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012764endfun
12765
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012766" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012767" s:UserMaps: supports user-defined UserMaps {{{2
12768" * calls a user-supplied funcref(islocal,curdir)
12769" * interprets result
12770" See netrw#UserMaps()
12771fun! s:UserMaps(islocal,funcname)
12772" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12773
12774 if !exists("b:netrw_curdir")
12775 let b:netrw_curdir= getcwd()
12776 endif
12777 let Funcref = function(a:funcname)
12778 let result = Funcref(a:islocal)
12779
12780 if type(result) == 1
12781 " if result from user's funcref is a string...
12782" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12783 if result == "refresh"
12784" call Decho("refreshing display",'~'.expand("<slnum>"))
12785 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12786 elseif result != ""
12787" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12788 exe result
12789 endif
12790
12791 elseif type(result) == 3
12792 " if result from user's funcref is a List...
12793" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12794 for action in result
12795 if action == "refresh"
12796" call Decho("refreshing display",'~'.expand("<slnum>"))
12797 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12798 elseif action != ""
12799" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12800 exe action
12801 endif
12802 endfor
12803 endif
12804
12805" call Dret("s:UserMaps")
12806endfun
12807
Bram Moolenaar85850f32019-07-19 22:05:51 +020012808" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012809" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012810" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012811let &cpo= s:keepcpo
12812unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012813
Bram Moolenaar85850f32019-07-19 22:05:51 +020012814" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012815" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012816" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012817" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012818" doing autoload/netrw.vim version v172g ~57
12819" varname<g:netrw_dirhistcnt> value=0 ~1
12820" varname<s:THINLIST> value=0 ~1
12821" varname<s:LONGLIST> value=1 ~1
12822" varname<s:WIDELIST> value=2 ~1
12823" varname<s:TREELIST> value=3 ~1
12824" varname<s:MAXLIST> value=4 ~1
12825" varname<g:netrw_use_errorwindow> value=2 ~1
12826" varname<g:netrw_http_xcmd> value=-q -O ~1
12827" varname<g:netrw_http_put_cmd> value=curl -T ~1
12828" varname<g:netrw_keepj> value=keepj ~1
12829" varname<g:netrw_rcp_cmd> value=rcp ~1
12830" varname<g:netrw_rsync_cmd> value=rsync ~1
12831" varname<g:netrw_rsync_sep> value=/ ~1
12832" varname<g:netrw_scp_cmd> value=scp -q ~1
12833" varname<g:netrw_sftp_cmd> value=sftp ~1
12834" varname<g:netrw_ssh_cmd> value=ssh ~1
12835" varname<g:netrw_alto> value=0 ~1
12836" varname<g:netrw_altv> value=1 ~1
12837" varname<g:netrw_banner> value=1 ~1
12838" varname<g:netrw_browse_split> value=0 ~1
12839" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12840" varname<g:netrw_chgwin> value=-1 ~1
12841" varname<g:netrw_clipboard> value=1 ~1
12842" varname<g:netrw_compress> value=gzip ~1
12843" varname<g:netrw_ctags> value=ctags ~1
12844" varname<g:netrw_cursor> value=2 ~1
12845" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12846" varname<g:netrw_cygdrive> value=/cygdrive ~1
12847" varname<s:didstarstar> value=0 ~1
12848" varname<g:netrw_dirhistcnt> value=0 ~1
12849" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12850" varname<g:netrw_dirhistmax> value=10 ~1
12851" varname<g:netrw_errorlvl> value=0 ~1
12852" varname<g:netrw_fastbrowse> value=1 ~1
12853" 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
12854" varname<g:netrw_ftpmode> value=binary ~1
12855" varname<g:netrw_hide> value=1 ~1
12856" varname<g:netrw_keepdir> value=1 ~1
12857" varname<g:netrw_list_hide> value= ~1
12858" varname<g:netrw_localmkdir> value=mkdir ~1
12859" varname<g:netrw_remote_mkdir> value=mkdir ~1
12860" varname<g:netrw_liststyle> value=0 ~1
12861" varname<g:netrw_markfileesc> value=*./[\~ ~1
12862" varname<g:netrw_maxfilenamelen> value=32 ~1
12863" varname<g:netrw_menu> value=1 ~1
12864" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12865" varname<g:netrw_mousemaps> value=1 ~1
12866" varname<g:netrw_retmap> value=0 ~1
12867" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12868" varname<g:netrw_preview> value=0 ~1