blob: 850e5a40f44492dd5094e50be5fa57278faa5b84 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
6" Last Change:
7" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09008" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandtf9ca1392024-02-19 20:37:11 +01009" 2024 Feb 19 by Vim Project (announce adoption)
10" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000011" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000013" Permission is hereby granted to use and distribute this code,
14" with or without modifications, provided that this copyright
15" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000016" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000017" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000018" expressed or implied. By using this plugin, you agree that
19" in no event will the copyright holder be liable for any damages
20" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010021"
22" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
23" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
24"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020025"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000026"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000027" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000028" (James 1:22 RSV)
29" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000030" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000031if &cp || exists("g:loaded_netrw")
32 finish
33endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020034
35" Check that vim has patches that netrw requires.
36" Patches needed for v7.4: 1557, and 213.
37" (netrw will benefit from vim's having patch#656, too)
38let s:needspatches=[1557,213]
39if exists("s:needspatches")
40 for ptch in s:needspatches
41 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
42 if !exists("s:needpatch{ptch}")
43 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
44 endif
45 let s:needpatch{ptch}= 1
46 finish
47 endif
48 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020049endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020050
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010051let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000052if !exists("s:NOTE")
53 let s:NOTE = 0
54 let s:WARNING = 1
55 let s:ERROR = 2
56endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000057
Bram Moolenaar1afcace2005-11-25 19:54:28 +000058let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010059setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020060"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010061"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010062"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000063
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000064" ======================
65" Netrw Variables: {{{1
66" ======================
67
Bram Moolenaar071d4272004-06-13 20:20:40 +000068" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020069" netrw#ErrorMsg: {{{2
70" 0=note = s:NOTE
71" 1=warning = s:WARNING
72" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010073" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
74" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
75" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010076" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020077fun! netrw#ErrorMsg(level,msg,errnum)
78" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
79
80 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020081" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020082 return
83 endif
84
85 if a:level == 1
86 let level= "**warning** (netrw) "
87 elseif a:level == 2
88 let level= "**error** (netrw) "
89 else
90 let level= "**note** (netrw) "
91 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010092" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020093
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020094 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
95 " use popup window
96 if type(a:msg) == 3
97 let msg = [level]+a:msg
98 else
99 let msg= level.a:msg
100 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200101 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200102 let s:popuperr_text= ""
103 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200104 " (default) netrw creates a one-line window to show error/warning
105 " messages (reliably displayed)
106
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100107 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200108 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100109" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200110
111 " getting messages out reliably is just plain difficult!
112 " This attempt splits the current window, creating a one line window.
113 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100114" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200115 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100116" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200117 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100118 if type(a:msg) == 3
119 for msg in a:msg
120 NetrwKeepj call setline(line("$")+1,level.msg)
121 endfor
122 else
123 NetrwKeepj call setline(line("$")+1,level.a:msg)
124 endif
125 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200126 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100127" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200128 bo 1split
129 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200130 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200131 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100132 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100133" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200134 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100135 if type(a:msg) == 3
136 for msg in a:msg
137 NetrwKeepj call setline(line("$")+1,level.msg)
138 endfor
139 else
140 NetrwKeepj call setline(line("$"),level.a:msg)
141 endif
142 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200143 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100144" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200145 if &fo !~ '[ta]'
146 syn clear
147 syn match netrwMesgNote "^\*\*note\*\*"
148 syn match netrwMesgWarning "^\*\*warning\*\*"
149 syn match netrwMesgError "^\*\*error\*\*"
150 hi link netrwMesgWarning WarningMsg
151 hi link netrwMesgError Error
152 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100153" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200154 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200155
156 else
157 " (optional) netrw will show messages using echomsg. Even if the
158 " message doesn't appear, at least it'll be recallable via :messages
159" redraw!
160 if a:level == s:WARNING
161 echohl WarningMsg
162 elseif a:level == s:ERROR
163 echohl Error
164 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100165
166 if type(a:msg) == 3
167 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100168 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100169 endfor
170 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100171 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100172 endif
173
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100174" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200175 echohl None
176 endif
177
178" call Dret("netrw#ErrorMsg")
179endfun
180
181" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100182" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100183" Loosely, varname = value.
184fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100185" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100186 if !exists(a:varname)
187 if type(a:value) == 0
188 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200189 elseif type(a:value) == 1 && a:value =~ '^[{[]'
190 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100191 elseif type(a:value) == 1
192 exe "let ".a:varname."="."'".a:value."'"
193 else
194 exe "let ".a:varname."=".a:value
195 endif
196 endif
197endfun
198
199" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000200" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200201call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000202if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100203 call s:NetrwInit("s:THINLIST",0)
204 call s:NetrwInit("s:LONGLIST",1)
205 call s:NetrwInit("s:WIDELIST",2)
206 call s:NetrwInit("s:TREELIST",3)
207 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000208endif
209
210" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200211" Default option values: {{{2
212let g:netrw_localcopycmdopt = ""
213let g:netrw_localcopydircmdopt = ""
214let g:netrw_localmkdiropt = ""
215let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200216
217" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000218" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200219if (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")
220 call s:NetrwInit("g:netrw_use_errorwindow",2)
221else
222 call s:NetrwInit("g:netrw_use_errorwindow",1)
223endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200224
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000225if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100226 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000227 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100228 elseif executable("curl")
229 let g:netrw_dav_cmd = "curl"
230 else
231 let g:netrw_dav_cmd = ""
232 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000233endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000234if !exists("g:netrw_fetch_cmd")
235 if executable("fetch")
236 let g:netrw_fetch_cmd = "fetch -o"
237 else
238 let g:netrw_fetch_cmd = ""
239 endif
240endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100241if !exists("g:netrw_file_cmd")
242 if executable("elinks")
243 call s:NetrwInit("g:netrw_file_cmd","elinks")
244 elseif executable("links")
245 call s:NetrwInit("g:netrw_file_cmd","links")
246 endif
247endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000248if !exists("g:netrw_ftp_cmd")
249 let g:netrw_ftp_cmd = "ftp"
250endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200251let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200252if !exists("g:netrw_ftp_options")
253 let g:netrw_ftp_options= "-i -n"
254endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000255if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100256 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100257 let g:netrw_http_cmd = "wget"
258 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100259 elseif executable("curl")
260 let g:netrw_http_cmd = "curl"
261 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200262 elseif executable("elinks")
263 let g:netrw_http_cmd = "elinks"
264 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000265 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100266 let g:netrw_http_cmd = "fetch"
267 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200268 elseif executable("links")
269 let g:netrw_http_cmd = "links"
270 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000271 else
272 let g:netrw_http_cmd = ""
273 endif
274endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100275call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100276call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100277call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
278call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200279call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200280if !exists("g:netrw_scp_cmd")
281 if executable("scp")
282 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
283 elseif executable("pscp")
284 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
285 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
286 else
287 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
288 endif
289 else
290 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
291 endif
292endif
293
Bram Moolenaar5c736222010-01-06 20:54:52 +0100294call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
295call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000296
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000297if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000298 \ && exists("g:netrw_use_nt_rcp")
299 \ && g:netrw_use_nt_rcp
300 \ && executable( $SystemRoot .'/system32/rcp.exe')
301 let s:netrw_has_nt_rcp = 1
302 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000303else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000304 let s:netrw_has_nt_rcp = 0
305 let s:netrw_rcpmode = ''
306endif
307
308" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000309" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000310" Cygwin Detection ------- {{{3
311if !exists("g:netrw_cygwin")
312 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100313 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000314 let g:netrw_cygwin= 1
315 else
316 let g:netrw_cygwin= 0
317 endif
318 else
319 let g:netrw_cygwin= 0
320 endif
321endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000322" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100323call s:NetrwInit("g:netrw_alto" , &sb)
324call s:NetrwInit("g:netrw_altv" , &spr)
325call s:NetrwInit("g:netrw_banner" , 1)
326call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200327call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100328call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200329call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100330call s:NetrwInit("g:netrw_compress" , "gzip")
331call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200332if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
333 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
334 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000335endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200336call s:NetrwInit("g:netrw_cursor" , 2)
337let s:netrw_usercul = &cursorline
338let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200339"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100340call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000341" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200342call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200343call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200344call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100345call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200346call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100347call s:NetrwInit("g:netrw_fastbrowse" , 1)
348call 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 +0000349if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000350 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
351 let g:netrw_ftp_list_cmd = "ls -lF"
352 let g:netrw_ftp_timelist_cmd = "ls -tlF"
353 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000354 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000355 let g:netrw_ftp_list_cmd = "dir"
356 let g:netrw_ftp_timelist_cmd = "dir"
357 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000358 endif
359endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100360call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000361" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100362call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000363if !exists("g:netrw_ignorenetrc")
364 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
365 let g:netrw_ignorenetrc= 1
366 else
367 let g:netrw_ignorenetrc= 0
368 endif
369endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100370call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000371if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000372 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000373 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200374 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000375 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
376 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100377 if exists("g:netrw_list_cmd_options")
378 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
379 else
380 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
381 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000382 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200383 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100384 if exists("g:netrw_list_cmd_options")
385 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
386 else
387 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
388 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000389 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100390" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000391 let g:netrw_list_cmd= ""
392 endif
393endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100394call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000395" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200396if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200397 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200398 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
399endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100400if !exists("g:netrw_localcmdshell")
401 let g:netrw_localcmdshell= ""
402endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000403if !exists("g:netrw_localcopycmd")
404 if has("win32") || has("win95") || has("win64") || has("win16")
405 if g:netrw_cygwin
406 let g:netrw_localcopycmd= "cp"
407 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000408 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200409 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000410 endif
411 elseif has("unix") || has("macunix")
412 let g:netrw_localcopycmd= "cp"
413 else
414 let g:netrw_localcopycmd= ""
415 endif
416endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100417if !exists("g:netrw_localcopydircmd")
418 if has("win32") || has("win95") || has("win64") || has("win16")
419 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200420 let g:netrw_localcopydircmd = "cp"
421 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100422 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000423 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200424 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100425 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200426 elseif has("unix")
427 let g:netrw_localcopydircmd = "cp"
428 let g:netrw_localcopydircmdopt= " -R"
429 elseif has("macunix")
430 let g:netrw_localcopydircmd = "cp"
431 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100432 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200433 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100434 endif
435endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200436if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100437 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200438 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
439endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200440if has("win32") || has("win95") || has("win64") || has("win16")
441 if g:netrw_cygwin
442 call s:NetrwInit("g:netrw_localmkdir","mkdir")
443 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000444 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200445 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200446 endif
447else
448 call s:NetrwInit("g:netrw_localmkdir","mkdir")
449endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200450call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200451if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200452 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200453 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
454endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000455if !exists("g:netrw_localmovecmd")
456 if has("win32") || has("win95") || has("win64") || has("win16")
457 if g:netrw_cygwin
458 let g:netrw_localmovecmd= "mv"
459 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000460 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200461 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000462 endif
463 elseif has("unix") || has("macunix")
464 let g:netrw_localmovecmd= "mv"
465 else
466 let g:netrw_localmovecmd= ""
467 endif
468endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100469" following serves as an example for how to insert a version&patch specific test
470"if v:version < 704 || (v:version == 704 && !has("patch1107"))
471"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100472call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
473" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000474if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000475 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000476endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000477if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000478 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
479endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000480" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100481call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
482call s:NetrwInit("g:netrw_maxfilenamelen", 32)
483call s:NetrwInit("g:netrw_menu" , 1)
484call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200485call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100486call s:NetrwInit("g:netrw_retmap" , 0)
487if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
488 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
489elseif has("win32") || has("win95") || has("win64") || has("win16")
490 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
491else
492 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000493endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100494call s:NetrwInit("g:netrw_preview" , 0)
495call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100496call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100497call s:NetrwInit("g:netrw_sshport" , "-p")
498call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
499call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
500call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100501call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
502" Default values - q-s ---------- {{{3
503call s:NetrwInit("g:netrw_quickhelp",0)
504let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100505 \ "(create new) %:file d:directory",
506 \ "(windows split&open) o:horz v:vert p:preview",
507 \ "i:style qf:file info O:obtain r:reverse",
508 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
509 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
510 \ "(history) qb:list u:go up U:go down",
511 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100512" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
513call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100514if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
515 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
516else
517 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
518endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100519call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
520call s:NetrwInit("g:netrw_sort_options" , "")
521call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000522if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100523 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200524 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100525 else
526 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000527 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000528endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100529call s:NetrwInit("g:netrw_special_syntax" , 0)
530call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200531call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100532call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100533call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000534" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100535call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200536if !exists("g:netrw_xstrlen")
537 if exists("g:Align_xstrlen")
538 let g:netrw_xstrlen= g:Align_xstrlen
539 elseif exists("g:drawit_xstrlen")
540 let g:netrw_xstrlen= g:drawit_xstrlen
541 elseif &enc == "latin1" || !has("multi_byte")
542 let g:netrw_xstrlen= 0
543 else
544 let g:netrw_xstrlen= 1
545 endif
546endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100547call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100548call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200549call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100550call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200551if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000552" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000553" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100554call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200555if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200556 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200557else
Bram Moolenaarff034192013-04-24 18:51:19 +0200558 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200559endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200560call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100561call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
562call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100563if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100564 let s:treedepthstring= "│ "
565else
566 let s:treedepthstring= "| "
567endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200568call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000569
570" BufEnter event ignored by decho when following variable is true
571" Has a side effect that doau BufReadPost doesn't work, so
572" files read by network transfer aren't appropriately highlighted.
573"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574
Bram Moolenaaradc21822011-04-01 18:03:16 +0200575" ======================
576" Netrw Initialization: {{{1
577" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200578if 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 +0100579" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100580 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200581" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100582 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100583 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
584 au VimEnter * let s:initbeval= &beval
585"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100586" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
587" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
588" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
589" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
590" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
591" 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 +0200592endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200593au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200594
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200595if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100596 com! -nargs=* NetrwKeepj keepj <args>
597else
598 let g:netrw_keepj= ""
599 com! -nargs=* NetrwKeepj <args>
600endif
601
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000602" ==============================
603" Netrw Utility Functions: {{{1
604" ==============================
605
Bram Moolenaaradc21822011-04-01 18:03:16 +0200606" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100607" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100608if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100609" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100610 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100611 if &ft != "netrw"
612 return ""
613 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200614 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
615 " popup error window is still showing
616 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
617 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
618 " text under mouse hasn't changed; only close window when it changes
619 call popup_close(s:popuperr_id)
620 unlet s:popuperr_text
621 else
622 let s:popuperr_text= v:beval_text
623 endif
624 let mesg= ""
625 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 +0100626 let mesg= ""
627 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
628 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
629 elseif getline(v:beval_lnum) =~ '^"\s*/'
630 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
631 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100632 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100633 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
634 let mesg = "S: edit sorting sequence"
635 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
636 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
637 elseif v:beval_text == "Quick" || v:beval_text == "Help"
638 let mesg = "Help: press <F1>"
639 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
640 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
641 else
642 let mesg= ""
643 endif
644 return mesg
645 endfun
646"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100647" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
648" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
649" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
650" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
651" 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 +0200652endif
653
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200655" netrw#Explore: launch the local browser in the directory of the current file {{{2
656" indx: == -1: Nexplore
657" == -2: Pexplore
658" == +: this is overloaded:
659" * If Nexplore/Pexplore is in use, then this refers to the
660" indx'th item in the w:netrw_explore_list[] of items which
661" matched the */pattern **/pattern *//pattern **//pattern
662" * If Hexplore or Vexplore, then this will override
663" g:netrw_winsize to specify the qty of rows or columns the
664" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100665" 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 +0200666" dosplit==1: the window will be split before running the local browser
667" style == 0: Explore style == 1: Explore!
668" == 2: Hexplore style == 3: Hexplore!
669" == 4: Vexplore style == 5: Vexplore!
670" == 6: Texplore
671fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100672" 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 +0100673" 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 +0200674 if !exists("b:netrw_curdir")
675 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100676" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200677 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100678
679 " record current file for Rexplore's benefit
680 if &ft != "netrw"
681 let w:netrw_rexfile= expand("%:p")
682 endif
683
684 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200685 let curdir = simplify(b:netrw_curdir)
686 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200687 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
688 let curdir= substitute(curdir,'\','/','g')
689 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100690" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100691
692 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
693 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
694 " try Explore again.
695 if a:0 > 0
696" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100697 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
698 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
699 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
700 \ '~'.expand("<slnum>"))
701 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
702" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100703 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
704" call Dret("netrw#Explore : returning from retry")
705 return
706" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100707" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100708 endif
709 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200710
711 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200712 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100713" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100714 sil! let keepregstar = @*
715 sil! let keepregplus = @+
716 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200717 sil! let keepregslash= @/
718
Bram Moolenaar8d043172014-01-23 14:24:41 +0100719 " if dosplit
720 " -or- file has been modified AND file not hidden when abandoned
721 " -or- Texplore used
722 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100723" 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 +0200724 call s:SaveWinVars()
725 let winsz= g:netrw_winsize
726 if a:indx > 0
727 let winsz= a:indx
728 endif
729
730 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100731" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200732 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200733 if winsz == 0|let winsz= ""|endif
734 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100735" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200736
737 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100738" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200739 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200740 if winsz == 0|let winsz= ""|endif
741 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100742" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200743
744 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100745" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200746 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200747 if winsz == 0|let winsz= ""|endif
748 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100749" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200750
751 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100752" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200753 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200754 if winsz == 0|let winsz= ""|endif
755 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100756" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200757
758 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100759" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200760 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200761 if winsz == 0|let winsz= ""|endif
762 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100763" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200764
765 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100766" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200767 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200768 if winsz == 0|let winsz= ""|endif
769 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100770" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200771
772 elseif a:style == 6 " Texplore
773 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100774" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100776" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 call s:RestoreBufVars()
778 endif
779 call s:RestoreWinVars()
780" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" 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 +0200782 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100783 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200784
785 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
794 if dirname !~ '/$'
795 let dirname= dirname."/"
796 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200800 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200802 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100803" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100805" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200806 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100807" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200808 let dirname= a:1
809 endif
810 else
811 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100812" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200813 call s:NetrwClearExplore()
814" call Dret("netrw#Explore : cleared list")
815 return
816 endif
817
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100818" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200819 if dirname =~ '\.\./\=$'
820 let dirname= simplify(fnamemodify(dirname,':p:h'))
821 elseif dirname =~ '\.\.' || dirname == '.'
822 let dirname= simplify(fnamemodify(dirname,':p'))
823 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100824" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200825
826 if dirname =~ '^\*//'
827 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100828" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200829 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
830 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100831" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200832 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
833
834 elseif dirname =~ '^\*\*//'
835 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100836" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200837 let pattern= substitute(dirname,'^\*\*//','','')
838 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100839" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200840
841 elseif dirname =~ '/\*\*/'
842 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100843" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200844 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
845 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
846 let b:netrw_curdir = prefixdir
847 else
848 let b:netrw_curdir= getcwd().'/'.prefixdir
849 endif
850 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
851 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100852" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
853" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200854
855 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200856 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200857 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100858" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200859
860 elseif dirname=~ '^\*\*/'
861 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
862 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100863" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200864
865 else
866 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100867" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200868 endif
869
870 if starpat == 0 && a:indx >= 0
871 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100872" 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 +0200873 if dirname == ""
874 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100875" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200876 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200877 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200878 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200879 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200880 if dirname == ""
881 let dirname= getcwd()
882 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100883 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100884 " depending on whether backslashes have been converted to forward slashes by earlier code).
885 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200886 let dirname= b:netrw_curdir."/".dirname
887 endif
888 elseif dirname !~ '^/'
889 let dirname= b:netrw_curdir."/".dirname
890 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100891" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200892 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100893" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
894" 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 +0200895 endif
896 if exists("w:netrw_bannercnt")
897 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
898 " If one wants to return the same place in the netrw window, use :Rex instead.
899 exe w:netrw_bannercnt
900 endif
901
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100902" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200903 " ---------------------------------------------------------------------
904 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
905" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100906" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200907" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100908" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200909" endif
910 " ---------------------------------------------------------------------
911
912 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
913 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
914 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
915 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
916 elseif a:indx <= 0
917 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100918" 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 +0200919 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100920" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200921 let s:didstarstar= 1
922 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
923 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
924 endif
925
926 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100927" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200928 if !exists("w:netrw_explore_indx")
929 let w:netrw_explore_indx= 0
930 endif
931
932 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100933" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200934
935 if indx == -1
936 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100937" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200938 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100939 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 +0200940 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100941" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100942 if @* != keepregstar | sil! let @* = keepregstar | endif
943 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100944 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200945 sil! let @/ = keepregslash
946" call Dret("netrw#Explore")
947 return
948 endif
949 let indx= w:netrw_explore_indx
950 if indx < 0 | let indx= 0 | endif
951 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
952 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100953" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200954 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
955 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100956" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200957 endwhile
958 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100959" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200960
961 elseif indx == -2
962 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100963" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200964 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100965 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 +0200966 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100967" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100968 if @* != keepregstar | sil! let @* = keepregstar | endif
969 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100970 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200971 sil! let @/ = keepregslash
972" call Dret("netrw#Explore")
973 return
974 endif
975 let indx= w:netrw_explore_indx
976 if indx < 0 | let indx= 0 | endif
977 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
978 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100979" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200980 while indx >= 0 && curfile == w:netrw_explore_list[indx]
981 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100982" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200983 endwhile
984 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100985" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200986
987 else
988 " Explore -- initialize
989 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100990" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100991 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200992 let w:netrw_explore_indx= 0
993 if !exists("b:netrw_curdir")
994 let b:netrw_curdir= getcwd()
995 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100996" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200997
998 " switch on starpat to build the w:netrw_explore_list of files
999 if starpat == 1
1000 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001001" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
1002" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001003 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001004 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001005 catch /^Vim\%((\a\+)\)\=:E480/
1006 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1007" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1008 return
1009 endtry
1010 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1011 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1012
1013 elseif starpat == 2
1014 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001015" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1016" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001017 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001018 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001019 catch /^Vim\%((\a\+)\)\=:E480/
1020 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1021 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001022 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001023" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001024 if @* != keepregstar | sil! let @* = keepregstar | endif
1025 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001026 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001027 sil! let @/ = keepregslash
1028" call Dret("netrw#Explore : no files matched pattern")
1029 return
1030 endtry
1031 let s:netrw_curdir = b:netrw_curdir
1032 let w:netrw_explore_list = getqflist()
1033 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1034 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1035
1036 elseif starpat == 3
1037 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001038" 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 +02001039 let filepat= substitute(dirname,'^\*/','','')
1040 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001041" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1042" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001043 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1044 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1045
1046 elseif starpat == 4
1047 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001048" 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 +02001049 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1050 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1051 endif " switch on starpat to build w:netrw_explore_list
1052
1053 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001054" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1055" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001056
1057 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001058 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001059 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001060" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001061 if @* != keepregstar | sil! let @* = keepregstar | endif
1062 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001063 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001064 sil! let @/ = keepregslash
1065" call Dret("netrw#Explore : no files matched")
1066 return
1067 endif
1068 endif " if indx ... endif
1069
1070 " NetrwStatusLine support - for exploring support
1071 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001072" 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 +02001073
1074 " wrap the indx around, but issue a note
1075 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001076" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001077 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1078 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001079 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001080 endif
1081
1082 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001083" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001084 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001085" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001086
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001087" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001088 call netrw#LocalBrowseCheck(newdir)
1089 if !exists("w:netrw_liststyle")
1090 let w:netrw_liststyle= g:netrw_liststyle
1091 endif
1092 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001093 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001094 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001095 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001096 endif
1097 let w:netrw_explore_mtchcnt = indx + 1
1098 let w:netrw_explore_bufnr = bufnr("%")
1099 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001100 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001101" 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 +02001102
1103 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001104" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001105 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001106 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 +02001107 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001108 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001109" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001110 if @* != keepregstar | sil! let @* = keepregstar | endif
1111 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001112 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001113 sil! let @/ = keepregslash
1114" call Dret("netrw#Explore : missing +path_extra")
1115 return
1116 endif
1117
1118 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001119" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001120 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1121 sil! unlet w:netrw_treedict
1122 sil! unlet w:netrw_treetop
1123 endif
1124 let newdir= dirname
1125 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001126 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001127 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001128 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001129 endif
1130 endif
1131
1132 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001133" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1134" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001135 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001136" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001137 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001138 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001139" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001140 let s:explore_prvdir = b:netrw_curdir
1141 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001142 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001143 if b:netrw_curdir !~ '/$'
1144 let dirlen= dirlen + 1
1145 endif
1146 let prvfname= ""
1147 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001148" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001149 if fname =~ '^'.b:netrw_curdir
1150 if s:explore_match == ""
1151 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1152 else
1153 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1154 endif
1155 elseif fname !~ '^/' && fname != prvfname
1156 if s:explore_match == ""
1157 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1158 else
1159 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1160 endif
1161 endif
1162 let prvfname= fname
1163 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001164" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001165 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1166 exe "2match netrwMarkFile /".s:explore_match."/"
1167 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001168 endif
1169 echo "<s-up>==Pexplore <s-down>==Nexplore"
1170 else
1171 2match none
1172 if exists("s:explore_match") | unlet s:explore_match | endif
1173 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001174" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001175 endif
1176
Bram Moolenaara6878372014-03-22 21:02:50 +01001177 " since Explore may be used to initialize netrw's browser,
1178 " there's no danger of a late FocusGained event on initialization.
1179 " Consequently, set s:netrw_events to 2.
1180 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001181 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001182" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001183 if @* != keepregstar | sil! let @* = keepregstar | endif
1184 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001185 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001186 sil! let @/ = keepregslash
1187" call Dret("netrw#Explore : @/<".@/.">")
1188endfun
1189
1190" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001191" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001192" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1193" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1194" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1195" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1196" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001197fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001198" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001199 let curwin= winnr()
1200
Bram Moolenaara6878372014-03-22 21:02:50 +01001201 if a:0 > 0 && a:1 != ""
1202 " if a netrw window is already on the left-side of the tab
1203 " and a directory has been specified, explore with that
1204 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001205" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001206 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001207" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001208 exe "1wincmd w"
1209 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001210" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001211 exe "Explore ".fnameescape(a1)
1212 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001213 let s:lexplore_win= curwin
1214 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001215 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001216" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001217 unlet t:netrw_lexposn
1218 endif
1219" call Dret("netrw#Lexplore")
1220 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001221 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001222 exe curwin."wincmd w"
1223 else
1224 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001225" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001226 endif
1227
Bram Moolenaar8d043172014-01-23 14:24:41 +01001228 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001229 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001230 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001231" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001232 else
1233 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001234" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001235 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001236" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001237
1238 if lexwinnr > 0
1239 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001240" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001241 exe lexwinnr."wincmd w"
1242 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001243 let t:netrw_lexposn = winsaveview()
1244" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001245" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001246 close
1247 if lexwinnr < curwin
1248 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001249 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001250 if lexwinnr != curwin
1251 exe curwin."wincmd w"
1252 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001253 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001254" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001255
1256 else
1257 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001258" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001259 exe "1wincmd w"
1260 let keep_altv = g:netrw_altv
1261 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262 if a:count != 0
1263 let netrw_winsize = g:netrw_winsize
1264 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001265 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001267" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 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 +02001269" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001270 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001271" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001272 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001273 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001274 elseif curfile =~ '^\a\{3,}://'
1275" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001276 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001277 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001278" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001279 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001280 endif
1281 if a:count != 0
1282 let g:netrw_winsize = netrw_winsize
1283 endif
1284 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001285 let g:netrw_altv = keep_altv
1286 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001287 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1288 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001289 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001290 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001291" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1292" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001293 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001294" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001295" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1296 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001297 unlet t:netrw_lexposn
1298 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001299 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001300
1301 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001302 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001303 if a:rightside
1304 let g:netrw_chgwin= 1
1305 else
1306 let g:netrw_chgwin= 2
1307 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001308" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001309 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001310
Bram Moolenaar8d043172014-01-23 14:24:41 +01001311" call Dret("netrw#Lexplore")
1312endfun
1313
1314" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001315" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001316" supports :NetrwClean -- remove netrw from first directory on runtimepath
1317" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001318fun! netrw#Clean(sys)
1319" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001320
1321 if a:sys
1322 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1323 else
1324 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1325 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001326" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001327 let diddel= 0
1328 let diddir= ""
1329
1330 if choice == 1
1331 for dir in split(&rtp,',')
1332 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001333" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001334 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1335 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1336 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1337 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1338 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1339 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 +00001340 let diddir= dir
1341 let diddel= diddel + 1
1342 if !a:sys|break|endif
1343 endif
1344 endfor
1345 endif
1346
1347 echohl WarningMsg
1348 if diddel == 0
1349 echomsg "netrw is either not installed or not removable"
1350 elseif diddel == 1
1351 echomsg "removed one copy of netrw from <".diddir.">"
1352 else
1353 echomsg "removed ".diddel." copies of netrw"
1354 endif
1355 echohl None
1356
Bram Moolenaara6878372014-03-22 21:02:50 +01001357" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001358endfun
1359
Bram Moolenaar5c736222010-01-06 20:54:52 +01001360" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001361" netrw#MakeTgt: make a target out of the directory name provided {{{2
1362fun! netrw#MakeTgt(dname)
1363" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1364 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001365 let svpos = winsaveview()
1366" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001367 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1368" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001369 if s:netrwmftgt_islocal
1370 let netrwmftgt= simplify(a:dname)
1371 else
1372 let netrwmftgt= a:dname
1373 endif
1374 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1375 " re-selected target, so just clear it
1376 unlet s:netrwmftgt s:netrwmftgt_islocal
1377 else
1378 let s:netrwmftgt= netrwmftgt
1379 endif
1380 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001381 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001382 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001383" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1384 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001385" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001386endfun
1387
Bram Moolenaara6878372014-03-22 21:02:50 +01001388" ---------------------------------------------------------------------
1389" netrw#Obtain: {{{2
1390" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001391" islocal=0 obtain from remote source
1392" =1 obtain from local source
1393" fname : a filename or a list of filenames
1394" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001395fun! netrw#Obtain(islocal,fname,...)
1396" 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 +02001397 " NetrwStatusLine support - for obtaining support
1398
1399 if type(a:fname) == 1
1400 let fnamelist= [ a:fname ]
1401 elseif type(a:fname) == 3
1402 let fnamelist= a:fname
1403 else
1404 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 +01001405" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001406 return
1407 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001408" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001409 if a:0 > 0
1410 let tgtdir= a:1
1411 else
1412 let tgtdir= getcwd()
1413 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001414" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001415
1416 if exists("b:netrw_islocal") && b:netrw_islocal
1417 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001418" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001419 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1420 let topath= s:ComposePath(tgtdir,"")
1421 if (has("win32") || has("win95") || has("win64") || has("win16"))
1422 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001423" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001424 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001425" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001426 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001427 if v:shell_error != 0
1428 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 +01001429" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001430 return
1431 endif
1432 endfor
1433 else
1434 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001435" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1436 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1437" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001438 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001439 if v:shell_error != 0
1440 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 +01001441" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001442 return
1443 endif
1444 endif
1445 elseif !exists("b:netrw_curdir")
1446 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1447 else
1448 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1449 endif
1450
1451 else
1452 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001453" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001454 if type(a:fname) == 1
1455 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1456 endif
1457 call s:NetrwMethod(b:netrw_curdir)
1458
1459 if b:netrw_method == 4
1460 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001461" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001462 if exists("g:netrw_port") && g:netrw_port != ""
1463 let useport= " ".g:netrw_scpport." ".g:netrw_port
1464 else
1465 let useport= ""
1466 endif
1467 if b:netrw_fname =~ '/'
1468 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1469 else
1470 let path= ""
1471 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001472 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001473 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 +02001474
1475 elseif b:netrw_method == 2
1476 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001477" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001478 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001479 let tmpbufnr= bufnr("%")
1480 setl ff=unix
1481 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001482 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001483" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001484 endif
1485
1486 if exists("b:netrw_fname") && b:netrw_fname != ""
1487 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001488" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001489 endif
1490
1491 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001492 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001493" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001494 endif
1495 for fname in fnamelist
1496 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001497" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001498 endfor
1499 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001500 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001501 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001502 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001503 endif
1504 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1505 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1506 let debugkeep= &debug
1507 setl debug=msg
1508 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1509 let &debug= debugkeep
1510 endif
1511
1512 elseif b:netrw_method == 3
1513 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001514" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001515 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001516 let tmpbufnr= bufnr("%")
1517 setl ff=unix
1518
1519 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001520 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001521" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001522 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001523 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001524" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001525 endif
1526
1527 if exists("g:netrw_uid") && g:netrw_uid != ""
1528 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001529 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001530" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001531 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001532 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001533 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001534" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001535 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001536 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001537" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001538 endif
1539 endif
1540
1541 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001542 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001543" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001544 endif
1545
1546 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001547 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001548" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001549 endif
1550
1551 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001552 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001553" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001554 endif
1555
1556 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001557 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001558" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001559 endif
1560 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001561 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001562 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001563" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001564
1565 " perform ftp:
1566 " -i : turns off interactive prompting from ftp
1567 " -n unix : DON'T use <.netrc>, even though it exists
1568 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001569 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1570 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001571 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001572 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1573 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001574" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001575 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001576 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001577 endif
1578 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001579
1580 elseif b:netrw_method == 9
1581 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001582" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001583 if a:fname =~ '/'
1584 let localfile= substitute(a:fname,'^.*/','','')
1585 else
1586 let localfile= a:fname
1587 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001588 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 +02001589
Bram Moolenaarff034192013-04-24 18:51:19 +02001590 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001591 " probably a badly formed url; protocol not recognized
1592" call Dret("netrw#Obtain : unsupported method")
1593 return
1594
1595 else
1596 " protocol recognized but not supported for Obtain (yet?)
1597 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001598 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001599 endif
1600" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001601 return
1602 endif
1603
1604 " restore status line
1605 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001606 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001607 endif
1608
1609 endif
1610
1611 " cleanup
1612 if exists("tmpbufnr")
1613 if bufnr("%") != tmpbufnr
1614 exe tmpbufnr."bw!"
1615 else
1616 q!
1617 endif
1618 endif
1619
Bram Moolenaara6878372014-03-22 21:02:50 +01001620" call Dret("netrw#Obtain")
1621endfun
1622
1623" ---------------------------------------------------------------------
1624" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1625fun! netrw#Nread(mode,fname)
1626" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001627 let svpos= winsaveview()
1628" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001629 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001630" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1631 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001632
1633 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1634 if exists("w:netrw_bannercnt")
1635 " start with cursor just after the banner
1636 exe w:netrw_bannercnt
1637 endif
1638 endif
1639" call Dret("netrw#Nread")
1640endfun
1641
1642" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001643" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1644" Options get restored by s:NetrwOptionsRestore()
1645"
1646" Option handling:
1647" * save user's options (s:NetrwOptionsSave)
1648" * set netrw-safe options (s:NetrwOptionsSafe)
1649" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1650" * restore user's options (s:netrwOPtionsRestore)
1651" - restore a user option when != safe option (s:NetrwRestoreSetting)
1652" vt: (variable type) normally its either "w:" or "s:"
1653fun! s:NetrwOptionsSave(vt)
1654" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1655" 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 +02001656" 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>"))
1657" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001658
1659 if !exists("{a:vt}netrw_optionsave")
1660 let {a:vt}netrw_optionsave= 1
1661 else
1662" call Dret("s:NetrwOptionsSave : options already saved")
1663 return
1664 endif
1665" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1666
1667 " Save current settings and current directory
1668" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1669 let s:yykeep = @@
1670 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1671 let {a:vt}netrw_aikeep = &l:ai
1672 let {a:vt}netrw_awkeep = &l:aw
1673 let {a:vt}netrw_bhkeep = &l:bh
1674 let {a:vt}netrw_blkeep = &l:bl
1675 let {a:vt}netrw_btkeep = &l:bt
1676 let {a:vt}netrw_bombkeep = &l:bomb
1677 let {a:vt}netrw_cedit = &cedit
1678 let {a:vt}netrw_cikeep = &l:ci
1679 let {a:vt}netrw_cinkeep = &l:cin
1680 let {a:vt}netrw_cinokeep = &l:cino
1681 let {a:vt}netrw_comkeep = &l:com
1682 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001683 let {a:vt}netrw_cuckeep = &l:cuc
1684 let {a:vt}netrw_culkeep = &l:cul
1685" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001686 let {a:vt}netrw_diffkeep = &l:diff
1687 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001688 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1689 let {a:vt}netrw_ffkeep = &l:ff
1690 endif
1691 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1692 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001693 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001694 let {a:vt}netrw_hidkeep = &l:hidden
1695 let {a:vt}netrw_imkeep = &l:im
1696 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001697 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001698 let {a:vt}netrw_lskeep = &l:ls
1699 let {a:vt}netrw_makeep = &l:ma
1700 let {a:vt}netrw_magickeep = &l:magic
1701 let {a:vt}netrw_modkeep = &l:mod
1702 let {a:vt}netrw_nukeep = &l:nu
1703 let {a:vt}netrw_rnukeep = &l:rnu
1704 let {a:vt}netrw_repkeep = &l:report
1705 let {a:vt}netrw_rokeep = &l:ro
1706 let {a:vt}netrw_selkeep = &l:sel
1707 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001708 if !g:netrw_use_noswf
1709 let {a:vt}netrw_swfkeep = &l:swf
1710 endif
1711 let {a:vt}netrw_tskeep = &l:ts
1712 let {a:vt}netrw_twkeep = &l:tw " textwidth
1713 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1714 let {a:vt}netrw_wrapkeep = &l:wrap
1715 let {a:vt}netrw_writekeep = &l:write
1716
1717 " save a few selected netrw-related variables
1718" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1719 if g:netrw_keepdir
1720 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001721" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001722 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001723 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001724 sil! let {a:vt}netrw_starkeep = @*
1725 sil! let {a:vt}netrw_pluskeep = @+
1726 endif
1727 sil! let {a:vt}netrw_slashkeep= @/
1728
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001729" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001730" 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>"))
1731" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1732endfun
1733
1734" ---------------------------------------------------------------------
1735" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1736" Use s:NetrwSaveOptions() to save user settings
1737" Use s:NetrwOptionsRestore() to restore user settings
1738fun! s:NetrwOptionsSafe(islocal)
1739" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1740" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1741" 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>"))
1742 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1743 call s:NetrwSetSafeSetting("&l:ai",0)
1744 call s:NetrwSetSafeSetting("&l:aw",0)
1745 call s:NetrwSetSafeSetting("&l:bl",0)
1746 call s:NetrwSetSafeSetting("&l:bomb",0)
1747 if a:islocal
1748 call s:NetrwSetSafeSetting("&l:bt","nofile")
1749 else
1750 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1751 endif
1752 call s:NetrwSetSafeSetting("&l:ci",0)
1753 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001754 if g:netrw_fastbrowse > a:islocal
1755 call s:NetrwSetSafeSetting("&l:bh","hide")
1756 else
1757 call s:NetrwSetSafeSetting("&l:bh","delete")
1758 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001759 call s:NetrwSetSafeSetting("&l:cino","")
1760 call s:NetrwSetSafeSetting("&l:com","")
1761 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1762 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1763 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001764 if &go =~ 'a' | set go-=a | endif
1765 if &go =~ 'A' | set go-=A | endif
1766 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001767 call s:NetrwSetSafeSetting("&l:hid",0)
1768 call s:NetrwSetSafeSetting("&l:im",0)
1769 setl isk+=@ isk+=* isk+=/
1770 call s:NetrwSetSafeSetting("&l:magic",1)
1771 if g:netrw_use_noswf
1772 call s:NetrwSetSafeSetting("swf",0)
1773 endif
1774 call s:NetrwSetSafeSetting("&l:report",10000)
1775 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1776 call s:NetrwSetSafeSetting("&l:spell",0)
1777 call s:NetrwSetSafeSetting("&l:tw",0)
1778 call s:NetrwSetSafeSetting("&l:wig","")
1779 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001780
1781 " set up cuc and cul based on g:netrw_cursor and listing style
1782 " COMBAK -- cuc cul related
1783 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001784
1785 " allow the user to override safe options
1786" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1787 if &ft == "netrw"
1788" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1789 keepalt NetrwKeepj doau FileType netrw
1790 endif
1791
1792" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1793" 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>"))
1794" call Dret("s:NetrwOptionsSafe")
1795endfun
1796
1797" ---------------------------------------------------------------------
1798" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1799fun! s:NetrwOptionsRestore(vt)
1800" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001801" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001802" 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 +01001803 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001804" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01001805 if filereadable(expand("%"))
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001806" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001807 filetype detect
1808" call Decho("..settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
1809 else
1810 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001811 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001812" call Decho("..ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001813" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001814 return
1815 endif
1816 unlet {a:vt}netrw_optionsave
1817
1818 if exists("+acd")
1819 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001820" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001821 let curdir = getcwd()
1822 let &l:acd = {a:vt}netrw_acdkeep
1823 unlet {a:vt}netrw_acdkeep
1824 if &l:acd
1825 call s:NetrwLcd(curdir)
1826 endif
1827 endif
1828 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001829" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001830 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1831 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1832 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1833 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1834 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001835" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001836 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1837 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1838 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1839 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1840 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001841" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001842 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1843 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1844 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1845 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1846 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001847 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001848" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1849 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1850 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001851 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001852 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1853" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1854 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1855 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1856" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1857 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1858" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1859 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1860 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001861 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001862 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1863 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1864" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1865 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1866 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1867 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1868 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1869" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001870 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001871 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1872 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1873 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001874 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001875" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001876 call s:NetrwRestoreSetting("s:yykeep","@@")
1877 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1878 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1879 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1880 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1881
Bram Moolenaara6878372014-03-22 21:02:50 +01001882 if exists("{a:vt}netrw_swfkeep")
1883 if &directory == ""
1884 " user hasn't specified a swapfile directory;
1885 " netrw will temporarily set the swapfile directory
1886 " to the current directory as returned by getcwd().
1887 let &l:directory= getcwd()
1888 sil! let &l:swf = {a:vt}netrw_swfkeep
1889 setl directory=
1890 unlet {a:vt}netrw_swfkeep
1891 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001892 if !g:netrw_use_noswf
1893 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1894 sil! let &l:swf= {a:vt}netrw_swfkeep
1895 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001896 unlet {a:vt}netrw_swfkeep
1897 endif
1898 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001899 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001900 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1901 if exists("{a:vt}netrw_dirkeep")
1902 call s:NetrwLcd(dirkeep)
1903 unlet {a:vt}netrw_dirkeep
1904 endif
1905 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001906 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001907" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001908 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1909 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001910 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001911 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001912
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001913" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1914" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1915" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1916" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1917" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001918 " Moved the filetype detect here from NetrwGetFile() because remote files
1919 " were having their filetype detect-generated settings overwritten by
1920 " NetrwOptionRestore.
1921 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001922" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1923 filetype detect
1924" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001925 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001926" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001927" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001928" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001929endfun
1930
1931" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001932" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1933" but only when the options' value and the safe setting differ
1934" Doing this means that netrw will not come up as having changed a
1935" setting last when it really didn't actually change it.
1936"
1937" Called from s:NetrwOptionsSafe
1938" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1939fun! s:NetrwSetSafeSetting(setting,safesetting)
1940" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001941
Bram Moolenaar85850f32019-07-19 22:05:51 +02001942 if a:setting =~ '^&'
1943" call Decho("fyi: a:setting starts with &")
1944 exe "let settingval= ".a:setting
1945" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001946
Bram Moolenaar85850f32019-07-19 22:05:51 +02001947 if settingval != a:safesetting
1948" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1949 if type(a:safesetting) == 0
1950 exe "let ".a:setting."=".a:safesetting
1951 elseif type(a:safesetting) == 1
1952 exe "let ".a:setting."= '".a:safesetting."'"
1953 else
1954 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1955 endif
1956 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001957 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001958
Bram Moolenaar85850f32019-07-19 22:05:51 +02001959" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001960endfun
1961
1962" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001963" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1964" but only if the setting value differs from the associated keepvar.
1965" Doing this means that netrw will not come up as having changed a
1966" setting last when it really didn't actually change it.
1967"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001968" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001969" keepvars are set up by s:NetrwOptionsSave
1970fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001971""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001972
Bram Moolenaar85850f32019-07-19 22:05:51 +02001973 " typically called from s:NetrwOptionsRestore
1974 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1975 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001976 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001977 if exists(a:keepvar)
1978 exe "let keepvarval= ".a:keepvar
1979 exe "let setting= ".a:setting
1980
1981"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1982"" call Decho("fyi: keepvarval=".keepvarval)
1983"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1984
1985 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001986"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001987 if type(a:setting) == 0
1988 exe "let ".a:setting."= ".keepvarval
1989 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001990 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001991 else
1992 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1993 endif
1994 endif
1995
1996 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001997 endif
1998
Bram Moolenaar85850f32019-07-19 22:05:51 +02001999"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02002000endfun
2001
2002" ---------------------------------------------------------------------
2003" NetrwStatusLine: {{{2
2004fun! NetrwStatusLine()
2005
2006" vvv NetrwStatusLine() debugging vvv
2007" let g:stlmsg=""
2008" if !exists("w:netrw_explore_bufnr")
2009" let g:stlmsg="!X<explore_bufnr>"
2010" elseif w:netrw_explore_bufnr != bufnr("%")
2011" let g:stlmsg="explore_bufnr!=".bufnr("%")
2012" endif
2013" if !exists("w:netrw_explore_line")
2014" let g:stlmsg=" !X<explore_line>"
2015" elseif w:netrw_explore_line != line(".")
2016" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2017" endif
2018" if !exists("w:netrw_explore_list")
2019" let g:stlmsg=" !X<explore_list>"
2020" endif
2021" ^^^ NetrwStatusLine() debugging ^^^
2022
2023 if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr("%") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list")
2024 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002025 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002026 let &laststatus = s:netrw_users_ls
2027 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2028 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2029 return ""
2030 else
2031 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2032 endif
2033endfun
2034
Bram Moolenaar85850f32019-07-19 22:05:51 +02002035" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002036" Netrw Transfer Functions: {{{1
2037" ===============================
2038
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002040" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002041" mode: =0 read remote file and insert before current line
2042" =1 read remote file and insert after current line
2043" =2 replace with remote file
2044" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002045fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002046" call Dfunc("netrw#NetRead(mode=".a:mode.",...) a:0=".a:0." ".g:loaded_netrw.((a:0 > 0)? " a:1<".a:1.">" : ""))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002047
Bram Moolenaar5c736222010-01-06 20:54:52 +01002048 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002049 call s:NetrwOptionsSave("w:")
2050 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002051 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002052 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2053 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2054 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002055" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056
Bram Moolenaar5c736222010-01-06 20:54:52 +01002057 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002058 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002059 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002060 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002061 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002062 elseif a:mode == 2 " replace with remote file
2063 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002064 elseif a:mode == 3 " skip read of file (leave as temporary)
2065 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002066 else
2067 exe a:mode
2068 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002069 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002070 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002071" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002072
Bram Moolenaar5c736222010-01-06 20:54:52 +01002073 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002074 let tmpfile= s:GetTempfile("")
2075 if tmpfile == ""
2076" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002077 return
2078 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002079
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002080 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002081
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002082 " attempt to repeat with previous host-file-etc
2083 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002084" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002085 let choice = b:netrw_lastfile
2086 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002087
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002088 else
2089 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002090" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002091
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002092 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002093 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002094 echomsg 'NetRead Usage:'
2095 echomsg ':Nread machine:path uses rcp'
2096 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2097 echomsg ':Nread "machine id password path" uses ftp'
2098 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2099 echomsg ':Nread fetch://machine/path uses fetch'
2100 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2101 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002102 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002103 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002104 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2105 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2106 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2107 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002108 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002109 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002110
Bram Moolenaar9964e462007-05-05 17:54:07 +00002111 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002112 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002113" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002114 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002115 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002116 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002117 else
2118 " case "... ... ..."
2119 let choice = strpart(choice,1,strlen(choice)-1)
2120 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002121
Bram Moolenaar9964e462007-05-05 17:54:07 +00002122 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002123 let wholechoice = wholechoice . " " . choice
2124 let ichoice = ichoice + 1
2125 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002126 if !exists("g:netrw_quiet")
2127 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2128 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002129" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002130 return
2131 endif
2132 let choice= a:{ichoice}
2133 endwhile
2134 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2135 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 endif
2137 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002139" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002140 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002141
Bram Moolenaar5c736222010-01-06 20:54:52 +01002142 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002143 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002144 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002145" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002146 return
2147 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002148 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002149
Bram Moolenaar8d043172014-01-23 14:24:41 +01002150 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002151" call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02002152 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002153" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002154 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002155" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002157 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002158
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002159 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002160 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002161 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002162 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2163 echo "(netrw) Processing your read request..."
2164 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002165
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002167 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002168 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002169" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002170 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002172 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002173 " ER: the tmpfile is full path: rcp sees C:\... as host C
2174 if s:netrw_has_nt_rcp == 1
2175 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2176 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2177 else
2178 " Any way needed it machine contains a '.'
2179 let uid_machine = g:netrw_machine .'.'. $USERNAME
2180 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002181 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002182 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2183 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2184 else
2185 let uid_machine = g:netrw_machine
2186 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002188 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".s:ShellEscape(uid_machine.":".b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002189 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002190 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002191
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002192 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002193 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002194 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002195" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002196 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002197 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002198 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002199 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002200 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002201" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002202 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002203 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002205 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002206 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002207" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002208 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002209 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002210 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002211 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002212 endif
2213 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar83bab712005-08-01 21:58:57 +00002214 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002215 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002216 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002217 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002218 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002219 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002220 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002221 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002222 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2223 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002224 q!
2225 endif
2226 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002227 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002229
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002231 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002232 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2233 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002234" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002235 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002236 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002237 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002238 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002239 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002242 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002243 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002244" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002245 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002246
Bram Moolenaar97d62492012-11-15 21:28:22 +01002247 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002248 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002249 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002250" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002251 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002252 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002253 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002255 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002256 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002257" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002258 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002259 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002260
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002261 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002262 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002263" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002264 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002265 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002266 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002267" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002268 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002269 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002270" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002271
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 " perform ftp:
2273 " -i : turns off interactive prompting from ftp
2274 " -n unix : DON'T use <.netrc>, even though it exists
2275 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002276 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002277 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2279 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002280" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002281 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002282 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002283 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002285 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002286 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002287 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002288
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002289 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002290 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002291 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002292" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002293 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002294 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002295 else
2296 let useport= ""
2297 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002298 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2299 " This is workaround to avoid mis-handle windows local-path:
2300 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2301 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2302 else
2303 let tmpfile_get = tmpfile
2304 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002305 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".escape(s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1),' ')." ".s:ShellEscape(tmpfile_get,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002306 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002307 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002308
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002309 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002310 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002311 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002312" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002313 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002314 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002315 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002316 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002317" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002318 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002319 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002320
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002321 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2322 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002323" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002324 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002325 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".s:ShellEscape(tmpfile,1))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002326 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002327 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002328 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002329 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002330
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002331 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002332 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002333" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002334 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2335 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002336" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2337" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2338 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.netrw_html,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002339 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002340" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002341 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002342 endif
2343 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002344" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002345 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002346
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002347 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002348 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002349 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002350" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002351
Bram Moolenaar5c736222010-01-06 20:54:52 +01002352 if !executable(g:netrw_dav_cmd)
2353 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2354" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2355 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002356 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002357 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002358 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_dav_cmd." ".s:ShellEscape("dav://".g:netrw_machine.b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002359 else
2360 " Construct execution string (four lines) which will be passed through filter
2361 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2362 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002363 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002364 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002365 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002366 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002367 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002368 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002369 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002370 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002371 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002372 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2373 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002374
Bram Moolenaar5c736222010-01-06 20:54:52 +01002375 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002376 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002377 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002378 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002379 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002380 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002382
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002383 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002384 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002385 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002386" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002387 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".s:ShellEscape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002388 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002390
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002392 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002394 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002395" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002396 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002397 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002398 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002399 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002400" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002401 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002402 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002403 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002404 let netrw_option= "http"
2405 else
2406 let netrw_option= "ftp"
2407 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002408" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002409
Bram Moolenaar446cb832008-06-24 21:56:24 +00002410 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002411 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002412 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002413 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002414 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002415
Bram Moolenaar446cb832008-06-24 21:56:24 +00002416 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002417 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002418" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002419 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002420
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002421 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002422 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002423 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002424" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2425 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002426 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002427 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002428
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002429 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002430 " NetRead: (file) NetRead Method #10 {{{3
2431 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002432" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2433 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002434 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2435 let b:netrw_lastfile = choice
2436
2437 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002438 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002439 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002440 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002441 endif
2442 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002443
Bram Moolenaar5c736222010-01-06 20:54:52 +01002444 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002446" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002447 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002448 unlet b:netrw_fname
2449 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002450 if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002451" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002452 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002453 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002454 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002455
Bram Moolenaar9964e462007-05-05 17:54:07 +00002456" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002457endfun
2458
2459" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002460" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002461fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002462" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002463
Bram Moolenaar5c736222010-01-06 20:54:52 +01002464 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002465 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002466 call s:NetrwOptionsSave("w:")
2467 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002468
Bram Moolenaar5c736222010-01-06 20:54:52 +01002469 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002470 let tmpfile= s:GetTempfile("")
2471 if tmpfile == ""
2472" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002473 return
2474 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002475
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002476 if a:0 == 0
2477 let ichoice = 0
2478 else
2479 let ichoice = 1
2480 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002481
Bram Moolenaar9964e462007-05-05 17:54:07 +00002482 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002483" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002484 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002485 " For binary writes, always write entire file.
2486 " (line numbers don't really make sense for that).
2487 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002488" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002489 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002490 elseif g:netrw_cygwin
2491 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002492 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002493" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002494 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002495 else
2496 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002497" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002498 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002499 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002500
Bram Moolenaar9964e462007-05-05 17:54:07 +00002501 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002502 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002503 " on the temporary file's name. Deletion of the temporary file during
2504 " cleanup then causes an error message.
2505 0file!
2506 endif
2507
Bram Moolenaar5c736222010-01-06 20:54:52 +01002508 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002509 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002510
Bram Moolenaar9964e462007-05-05 17:54:07 +00002511 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002512 " attempt to repeat with previous host-file-etc
2513 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002514" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002515 let choice = b:netrw_lastfile
2516 let ichoice= ichoice + 1
2517 else
2518 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002519
Bram Moolenaar8d043172014-01-23 14:24:41 +01002520 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002521 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002522 echomsg 'NetWrite Usage:"'
2523 echomsg ':Nwrite machine:path uses rcp'
2524 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2525 echomsg ':Nwrite "machine id password path" uses ftp'
2526 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2527 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2528 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2529 echomsg ':Nwrite rcp://machine/path uses rcp'
2530 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2531 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2532 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002533 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002534 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002535
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002536 elseif match(choice,"^\"") != -1
2537 if match(choice,"\"$") != -1
2538 " case "..."
2539 let choice=strpart(choice,1,strlen(choice)-2)
2540 else
2541 " case "... ... ..."
2542 let choice = strpart(choice,1,strlen(choice)-1)
2543 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002544
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002545 while match(choice,"\"$") == -1
2546 let wholechoice= wholechoice . " " . choice
2547 let ichoice = ichoice + 1
2548 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002549 if !exists("g:netrw_quiet")
2550 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2551 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002552" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002553 return
2554 endif
2555 let choice= a:{ichoice}
2556 endwhile
2557 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2558 endif
2559 endif
2560 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002561 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002562" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002563
Bram Moolenaar9964e462007-05-05 17:54:07 +00002564 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002565 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002566 if !exists("b:netrw_method") || b:netrw_method < 0
2567" call Dfunc("netrw#NetWrite : unsupported method")
2568 return
2569 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002570
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002571 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002572 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002573 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002574 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2575 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002576" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002577 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002578
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002579 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002580 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002581 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002582" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002583 if s:netrw_has_nt_rcp == 1
2584 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2585 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2586 else
2587 let uid_machine = g:netrw_machine .'.'. $USERNAME
2588 endif
2589 else
2590 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2591 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2592 else
2593 let uid_machine = g:netrw_machine
2594 endif
2595 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002596 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(uid_machine.":".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002597 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002598
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002599 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002600 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002601 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002602" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002603 let netrw_fname = b:netrw_fname
2604
2605 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2606 let bhkeep = &l:bh
2607 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002608 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002610
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002612 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002613 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002614" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002615 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002616 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002618 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002619 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002620" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002622 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002624" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2625 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 endif
2627 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2628 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002629 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002630 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002631 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002632 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002634
2635 " remove enew buffer (quietly)
2636 let filtbuf= bufnr("%")
2637 exe curbuf."b!"
2638 let &l:bh = bhkeep
2639 exe filtbuf."bw!"
2640
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002642
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002643 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002645 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002646 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002647" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002648 let netrw_fname = b:netrw_fname
2649 let bhkeep = &l:bh
2650
2651 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2652 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002653 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002654 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002655 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002656
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002657 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002658 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002660 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002661 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002663 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002664 if exists("g:netrw_uid") && g:netrw_uid != ""
2665 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002666 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002667" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002668 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002669 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002670 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002672 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002673 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002674" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002675 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002676 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002677 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002678" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002679 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002680 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002681" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002682 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002683 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002684" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002685 " save choice/id/password for future use
2686 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002687
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002688 " perform ftp:
2689 " -i : turns off interactive prompting from ftp
2690 " -n unix : DON'T use <.netrc>, even though it exists
2691 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002692 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002693 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002694 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2695 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002696 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002697 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002698 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002699 let mod=1
2700 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002701
2702 " remove enew buffer (quietly)
2703 let filtbuf= bufnr("%")
2704 exe curbuf."b!"
2705 let &l:bh= bhkeep
2706 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002707
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002708 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002709 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002710 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002711" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002712 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002713 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002714 else
2715 let useport= ""
2716 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002717 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002718 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002719
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002720 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002721 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002722 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002723" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002724 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2725 if executable(curl)
2726 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002727 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_put_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(url,1) )
Bram Moolenaar8d043172014-01-23 14:24:41 +01002728 elseif !exists("g:netrw_quiet")
Bram Moolenaar85850f32019-07-19 22:05:51 +02002729 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002730 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002731
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002732 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002733 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002734 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002735" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002736
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002737 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002738 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2739 let bhkeep = &l:bh
2740
2741 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2742 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002743 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002744 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002745
Bram Moolenaarff034192013-04-24 18:51:19 +02002746 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002747 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002748 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002749 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002750 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002751 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002752 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002753 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002754 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002755 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002756
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002757 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002758 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002759 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002760
2761 " remove enew buffer (quietly)
2762 let filtbuf= bufnr("%")
2763 exe curbuf."b!"
2764 let &l:bh = bhkeep
2765 exe filtbuf."bw!"
2766
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002767 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002768
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002769 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002770 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002771 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002772" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002773 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002774 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002775
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002776 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002777 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002778 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002779" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002780 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2782 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2783 else
2784 let uid_machine = g:netrw_machine
2785 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002786
2787 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2788 let bhkeep = &l:bh
2789 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002790 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002791 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002792
Bram Moolenaarff034192013-04-24 18:51:19 +02002793 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002794 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002795" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002796 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002797 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002798 let filtbuf= bufnr("%")
2799 exe curbuf."b!"
2800 let &l:bh = bhkeep
2801 exe filtbuf."bw!"
2802 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002803
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002804 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002805 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002806 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002807 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002808 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002810 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002811
Bram Moolenaar5c736222010-01-06 20:54:52 +01002812 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002813" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002814 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002815" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002816 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002817 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002818 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002819
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002820 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002821 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002822 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002823" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02002824 elseif !exists("leavemod")
2825 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002826" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002827 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002828" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002829 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002830
Bram Moolenaar9964e462007-05-05 17:54:07 +00002831" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002832endfun
2833
2834" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002835" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002836" uses NetRead to get a copy of the file into a temporarily file,
2837" then sources that file,
2838" then removes that file.
2839fun! netrw#NetSource(...)
2840" call Dfunc("netrw#NetSource() a:0=".a:0)
2841 if a:0 > 0 && a:1 == '?'
2842 " give help
2843 echomsg 'NetSource Usage:'
2844 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2845 echomsg ':Nsource fetch://machine/path uses fetch'
2846 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002847 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002848 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2849 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2850 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2851 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2852 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002853 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002854 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002855 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002856 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002857" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002858 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002859" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002860 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002861" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002862 if delete(s:netrw_tmpfile)
2863 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2864 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002865 unlet s:netrw_tmpfile
2866 else
2867 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2868 endif
2869 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002870 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002871 endif
2872" call Dret("netrw#NetSource")
2873endfun
2874
Bram Moolenaar8d043172014-01-23 14:24:41 +01002875" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002876" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2877" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002878fun! netrw#SetTreetop(iscmd,...)
2879" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2880" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002881
Bram Moolenaar85850f32019-07-19 22:05:51 +02002882 " iscmd==0: netrw#SetTreetop called using gn mapping
2883 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2884" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002885 " clear out the current tree
2886 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002887" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002888 let inittreetop= w:netrw_treetop
2889 unlet w:netrw_treetop
2890 endif
2891 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002892" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002893 unlet w:netrw_treedict
2894 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002895" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002896
Bram Moolenaar85850f32019-07-19 22:05:51 +02002897 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002898 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002899" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002900 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002901 if isdirectory(s:NetrwFile(a:1))
2902" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002903 let treedir = a:1
2904 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002905 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002906 let treedir = b:netrw_curdir."/".a:1
2907 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002908" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002909 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002910 " normally the cursor is left in the message window.
2911 " However, here this results in the directory being listed in the message window, which is not wanted.
2912 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002913 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002914 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002915 let treedir = "."
2916 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002917 endif
2918 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002919" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002920
2921 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002922 let islocal= expand("%") !~ '^\a\{3,}://'
2923" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002924
2925 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002926 if islocal
2927 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2928 else
2929 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2930 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002931
Bram Moolenaara6878372014-03-22 21:02:50 +01002932" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002933endfun
2934
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002936" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002937" readcmd == %r : replace buffer with newly read file
2938" == 0r : read file at top of buffer
2939" == r : read file after current line
2940" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002941fun! s:NetrwGetFile(readcmd, tfile, method)
2942" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002943
2944 " readcmd=='t': simply do nothing
2945 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002946" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01002947" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002948 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002949 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002950
Bram Moolenaar9964e462007-05-05 17:54:07 +00002951 " get name of remote filename (ie. url and all)
2952 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002953" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002954
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955 if exists("*NetReadFixup")
2956 " for the use of NetReadFixup (not otherwise used internally)
2957 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002958 endif
2959
Bram Moolenaar9964e462007-05-05 17:54:07 +00002960 if a:readcmd[0] == '%'
2961 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002962" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002963
2964 " rename the current buffer to the temp file (ie. tfile)
2965 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002966 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002967 else
2968 let tfile= a:tfile
2969 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002970 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971
2972 " edit temporary file (ie. read the temporary file in)
2973 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002974" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002975 call zip#Browse(tfile)
2976 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002978 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002979 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002981 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002982 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002983" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002984 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002985 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002986" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002987 call tar#Browse(tfile)
2988 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002989" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002990 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002991 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002992" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002993 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002994 endif
2995
2996 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002997 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002998
Bram Moolenaar71badf92023-04-22 22:40:14 +01002999 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01003000 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003001 " Note that isk must not include a "/" for scripts.vim
3002 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01003003" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
3004" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003005" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003006" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3007 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003008 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003009 filetype detect
3010" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003011 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003012" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003013 let line1 = 1
3014 let line2 = line("$")
3015
Bram Moolenaar8d043172014-01-23 14:24:41 +01003016 elseif !&ma
3017 " attempting to read a file after the current line in the file, but the buffer is not modifiable
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003018 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003019" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003020 return
3021
Bram Moolenaar9964e462007-05-05 17:54:07 +00003022 elseif s:FileReadable(a:tfile)
3023 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003024" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003025 let curline = line(".")
3026 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003027" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003028 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003029 let line1= curline + 1
3030 let line2= line("$") - lastline + 1
3031
3032 else
3033 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003034" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3035" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003036 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003037" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003038 return
3039 endif
3040
3041 " User-provided (ie. optional) fix-it-up command
3042 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003043" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003044 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003045" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003046" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003047 endif
3048
Bram Moolenaaradc21822011-04-01 18:03:16 +02003049 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003050 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003051 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003052 endif
3053
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003054" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003055
3056 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003057" redraw!
3058
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003059" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003060" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003061endfun
3062
Bram Moolenaar9964e462007-05-05 17:54:07 +00003063" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003064" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003065" Input:
3066" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3067" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003068" b:netrw_method= 1: rcp
3069" 2: ftp + <.netrc>
3070" 3: ftp + machine, id, password, and [path]filename
3071" 4: scp
3072" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003073" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003074" 7: rsync
3075" 8: fetch
3076" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003077" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003078" g:netrw_machine= hostname
3079" b:netrw_fname = filename
3080" g:netrw_port = optional port number (for ftp)
3081" g:netrw_choice = copy of input url (choice)
3082fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003083" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003084
Bram Moolenaar251e1912011-06-19 05:09:16 +02003085 " sanity check: choice should have at least three slashes in it
3086 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3087 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3088 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003089" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003090 return
3091 endif
3092
Bram Moolenaar5c736222010-01-06 20:54:52 +01003093 " record current g:netrw_machine, if any
3094 " curmachine used if protocol == ftp and no .netrc
3095 if exists("g:netrw_machine")
3096 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003097" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003098 else
3099 let curmachine= "N O T A HOST"
3100 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003101 if exists("g:netrw_port")
3102 let netrw_port= g:netrw_port
3103 endif
3104
3105 " insure that netrw_ftp_cmd starts off every method determination
3106 " with the current g:netrw_ftp_cmd
3107 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003108
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 " initialization
3110 let b:netrw_method = 0
3111 let g:netrw_machine = ""
3112 let b:netrw_fname = ""
3113 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003114 let g:netrw_choice = a:choice
3115
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003117 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003118 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3119 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003120 " rcpurm : rcp://[user@]host/filename Use rcp
3121 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003122 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003123 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003124 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003125 " rsyncurm : rsync://host[:port]/path Use rsync
3126 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3127 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003128 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3130 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003131 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3132 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003133 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003134 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003135 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003136 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003137 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003138 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003140 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003141
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003142" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003143 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003144 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003145 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003146" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003147 let b:netrw_method = 1
3148 let userid = substitute(a:choice,rcpurm,'\1',"")
3149 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3150 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003151 if userid != ""
3152 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003154
Bram Moolenaaradc21822011-04-01 18:03:16 +02003155 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003156 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003157" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003158 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003159 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3160 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3161 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003162
Bram Moolenaar15146672011-10-20 22:22:38 +02003163 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003164 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003165" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003166 let b:netrw_method = 5
3167 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3168 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003169 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003170
Bram Moolenaaradc21822011-04-01 18:03:16 +02003171 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003172 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003173" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003174 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003175 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003176 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3177 else
3178 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3179 endif
3180 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003181
Bram Moolenaaradc21822011-04-01 18:03:16 +02003182 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003183 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003184" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003185 let b:netrw_method = 7
3186 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3187 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003188
Bram Moolenaaradc21822011-04-01 18:03:16 +02003189 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003190 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003191" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003192 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003193 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3194 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3195 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003196" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003197 if userid != ""
3198 let g:netrw_uid= userid
3199 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003200
Bram Moolenaaradc21822011-04-01 18:03:16 +02003201 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003202 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003203 call NetUserPass("ftp:".g:netrw_machine)
3204 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003205 " if there's a change in hostname, require password re-entry
3206 unlet s:netrw_passwd
3207 endif
3208 if exists("netrw_port")
3209 unlet netrw_port
3210 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003211 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003212
Bram Moolenaar446cb832008-06-24 21:56:24 +00003213 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003214 let b:netrw_method = 3
3215 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003216 let host= substitute(g:netrw_machine,'\..*$','','')
3217 if exists("s:netrw_hup[host]")
3218 call NetUserPass("ftp:".host)
3219
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003220 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003221" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3222" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003223 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003224 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003225" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003226 endif
3227 let b:netrw_method= 2
3228 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003229" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003230 let b:netrw_method= 2
3231 else
3232 if !exists("g:netrw_uid") || g:netrw_uid == ""
3233 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003234 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003235 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003236 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003237 endif
3238 let b:netrw_method= 3
3239 endif
3240 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003241
Bram Moolenaaradc21822011-04-01 18:03:16 +02003242 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003243 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003244" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003245 let b:netrw_method = 8
3246 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3247 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3248 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3249 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003250
Bram Moolenaaradc21822011-04-01 18:03:16 +02003251 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003252 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003253" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003255 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3256 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003257 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003258 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003259 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003260
Bram Moolenaaradc21822011-04-01 18:03:16 +02003261 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003262 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003263" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003264 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003265 let b:netrw_method = 3
3266 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3267 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003268
Bram Moolenaar9964e462007-05-05 17:54:07 +00003269 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003270 let b:netrw_method = 2
3271 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3272 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3273 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003274
Bram Moolenaaradc21822011-04-01 18:03:16 +02003275 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003276 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003277" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003278 let b:netrw_method = 9
3279 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3280 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003281
Bram Moolenaaradc21822011-04-01 18:03:16 +02003282 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003283 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003284" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003285 let b:netrw_method = 1
3286 let userid = substitute(a:choice,rcphf,'\2',"")
3287 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3288 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003289" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3290" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3291" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3292" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003293 if userid != ""
3294 let g:netrw_uid= userid
3295 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003296
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003297 " Method#10: file://user@hostname/...path-to-file {{{3
3298 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003299" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003300 let b:netrw_method = 10
3301 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003302" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003303
Bram Moolenaaradc21822011-04-01 18:03:16 +02003304 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003305 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003306 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003307 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003308 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003309 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003311 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003312
Bram Moolenaar81695252004-12-29 20:58:21 +00003313 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003314 " remove any leading [:#] from port number
3315 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3316 elseif exists("netrw_port")
3317 " retain port number as implicit for subsequent ftp operations
3318 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003319 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003320
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003321" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3322" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3323" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3324" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003325" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003326" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003327" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003328" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003329" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003330" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003331" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003332" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334
3335" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003336" NetReadFixup: this sort of function is typically written by the user {{{2
3337" to handle extra junk that their system's ftp dumps
3338" into the transfer. This function is provided as an
3339" example and as a fix for a Windows 95 problem: in my
3340" experience, win95's ftp always dumped four blank lines
3341" at the end of the transfer.
3342if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3343 fun! NetReadFixup(method, line1, line2)
3344" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003345
3346 " sanity checks -- attempt to convert inputs to integers
3347 let method = a:method + 0
3348 let line1 = a:line1 + 0
3349 let line2 = a:line2 + 0
3350 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3351" call Dret("NetReadFixup")
3352 return
3353 endif
3354
Bram Moolenaar9964e462007-05-05 17:54:07 +00003355 if method == 3 " ftp (no <.netrc>)
3356 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003357 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003358 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003359 call histdel("/",-1)
3360 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003361 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003362
Bram Moolenaar9964e462007-05-05 17:54:07 +00003363" call Dret("NetReadFixup")
3364 endfun
3365endif
3366
3367" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003368" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003369" Usage: :call NetUserPass() -- will prompt for userid and password
3370" :call NetUserPass("uid") -- will prompt for password
3371" :call NetUserPass("uid","password") -- sets global userid and password
3372" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3373" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374fun! NetUserPass(...)
3375
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003376" call Dfunc("NetUserPass() a:0=".a:0)
3377
3378 if !exists('s:netrw_hup')
3379 let s:netrw_hup= {}
3380 endif
3381
Bram Moolenaar071d4272004-06-13 20:20:40 +00003382 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003383 " case: no input arguments
3384
3385 " change host and username if not previously entered; get new password
3386 if !exists("g:netrw_machine")
3387 let g:netrw_machine= input('Enter hostname: ')
3388 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003390 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003391 let g:netrw_uid= input('Enter username: ')
3392 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003393 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003394 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003395
3396 " set up hup database
3397 let host = substitute(g:netrw_machine,'\..*$','','')
3398 if !exists('s:netrw_hup[host]')
3399 let s:netrw_hup[host]= {}
3400 endif
3401 let s:netrw_hup[host].uid = g:netrw_uid
3402 let s:netrw_hup[host].passwd = s:netrw_passwd
3403
3404 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003405 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003406
3407 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003408 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003409 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003410" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003411 let host = substitute(a:1,'^ftp:','','')
3412 let host = substitute(host,'\..*','','')
3413 if exists("s:netrw_hup[host]")
3414 let g:netrw_uid = s:netrw_hup[host].uid
3415 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003416" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3417" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003418 else
3419 let g:netrw_uid = input("Enter UserId: ")
3420 let s:netrw_passwd = inputsecret("Enter Password: ")
3421 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003422
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003423 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003424 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003425" 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 +02003426 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003427 if g:netrw_machine =~ '[0-9.]\+'
3428 let host= g:netrw_machine
3429 else
3430 let host= substitute(g:netrw_machine,'\..*$','','')
3431 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003432 else
3433 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003434 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003435 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003436" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003437 if exists("g:netrw_passwd")
3438 " ask for password if one not previously entered
3439 let s:netrw_passwd= g:netrw_passwd
3440 else
3441 let s:netrw_passwd = inputsecret("Enter Password: ")
3442 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003443 endif
3444
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003445" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003446 if exists("host")
3447 if !exists('s:netrw_hup[host]')
3448 let s:netrw_hup[host]= {}
3449 endif
3450 let s:netrw_hup[host].uid = g:netrw_uid
3451 let s:netrw_hup[host].passwd = s:netrw_passwd
3452 endif
3453
3454 elseif a:0 == 2
3455 let g:netrw_uid = a:1
3456 let s:netrw_passwd = a:2
3457
3458 elseif a:0 == 3
3459 " enter hostname, user-id, and password into the hup dictionary
3460 let host = substitute(a:1,'^\a\+:','','')
3461 let host = substitute(host,'\..*$','','')
3462 if !exists('s:netrw_hup[host]')
3463 let s:netrw_hup[host]= {}
3464 endif
3465 let s:netrw_hup[host].uid = a:2
3466 let s:netrw_hup[host].passwd = a:3
3467 let g:netrw_uid = s:netrw_hup[host].uid
3468 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003469" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3470" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003472
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003473" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003474endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475
Bram Moolenaar85850f32019-07-19 22:05:51 +02003476" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003477" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003478" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003480" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003481" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3482fun! s:ExplorePatHls(pattern)
3483" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3484 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003485" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003486 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003487" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003488 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3489" call Dret("s:ExplorePatHls repat<".repat.">")
3490 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003491endfun
3492
3493" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003494" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003495" 0: (user: <mb>) bookmark current directory
3496" 1: (user: <gb>) change to the bookmarked directory
3497" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003498" 3: (browsing) records current directory history
3499" 4: (user: <u>) go up (previous) directory, using history
3500" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003501" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003502fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003503" 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 +02003504 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3505" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3506 return
3507 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003508
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003509 let ykeep = @@
3510 let curbufnr = bufnr("%")
3511
Bram Moolenaar9964e462007-05-05 17:54:07 +00003512 if a:chg == 0
3513 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003514" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003515 if exists("s:netrwmarkfilelist_{curbufnr}")
3516 call s:NetrwBookmark(0)
3517 echo "bookmarked marked files"
3518 else
3519 call s:MakeBookmark(a:curdir)
3520 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003521 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003522
KSR-Yasudaf4498252023-10-06 03:34:17 +09003523 try
3524 call s:NetrwBookHistSave()
3525 catch
3526 endtry
3527
Bram Moolenaar9964e462007-05-05 17:54:07 +00003528 elseif a:chg == 1
3529 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003530" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003531 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003532" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003533 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003534 else
3535 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3536 endif
3537
3538 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003539" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003540 let didwork= 0
3541 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003542" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003543 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003544" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003545 let cnt= 1
3546 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003547" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003548 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003549 let didwork = 1
3550 let cnt = cnt + 1
3551 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003552 endif
3553
3554 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003555 " Note: history is saved only when PerformListing is done;
3556 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3557 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003558 let first = 1
3559 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003560 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003561 while ( first || cnt != g:netrw_dirhistcnt )
3562" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003563 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003564" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003565 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003566 let didwork= 1
3567 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003568 let histcnt = histcnt + 1
3569 let first = 0
3570 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003571 if cnt < 0
3572 let cnt= cnt + g:netrw_dirhistmax
3573 endif
3574 endwhile
3575 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003576 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003577 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003578 if didwork
3579 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3580 endif
3581
3582 elseif a:chg == 3
3583 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003584" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003585 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 +02003586 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003587 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3588 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003589 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003590" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003591 endif
3592
3593 elseif a:chg == 4
3594 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003595" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003596 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003597 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3598 if g:netrw_dirhistcnt < 0
3599 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003600 endif
3601 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003602 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003603 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003604 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3605" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003606 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003607 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003608" call Decho("setl ma noro",'~'.expand("<slnum>"))
3609 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003610 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003611" call Decho("setl nomod",'~'.expand("<slnum>"))
3612" 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 +00003613 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003614" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3615 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003616 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003617 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003618 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003619 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003620 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003621 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003622 echo "Sorry, no predecessor directory exists yet"
3623 endif
3624
3625 elseif a:chg == 5
3626 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003627" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003628 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003629 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3630 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3631" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003632 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003633" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003634 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003635 sil! NetrwKeepj %d _
3636" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3637" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003638 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003639" 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 +02003640 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003641" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3642 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003643 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003644 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3645 if g:netrw_dirhistcnt < 0
3646 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003647 endif
3648 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003649 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003650 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003651 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003652 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003653 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003654
3655 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003656" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003657 if exists("s:netrwmarkfilelist_{curbufnr}")
3658 call s:NetrwBookmark(1)
3659 echo "removed marked files from bookmarks"
3660 else
3661 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003662 let iremove = v:count
3663 let dremove = g:netrw_bookmarklist[iremove - 1]
3664" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003665 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003666" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3667 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3668 echo "removed ".dremove." from g:netrw_bookmarklist"
3669" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003670 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003671" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003672
3673 try
3674 call s:NetrwBookHistSave()
3675 catch
3676 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003677 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003678 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003679 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003680 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003681" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003682endfun
3683
3684" ---------------------------------------------------------------------
3685" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003686" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003687" Sister function: s:NetrwBookHistSave()
3688fun! s:NetrwBookHistRead()
3689" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003690 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003691" 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 +02003692 return
3693 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003694 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003695
3696 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003697 if !exists("s:netrw_initbookhist")
3698 let home = s:NetrwHome()
3699 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003700 if filereadable(s:NetrwFile(savefile))
3701" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003702 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003703 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003704
3705 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003706 if g:netrw_dirhistmax > 0
3707 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003708 if filereadable(s:NetrwFile(savefile))
3709" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003710 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003711 endif
3712 let s:netrw_initbookhist= 1
3713 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003714 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003715 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003716
Bram Moolenaar97d62492012-11-15 21:28:22 +01003717 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003718" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3719" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003720" call Dret("s:NetrwBookHistRead")
3721endfun
3722
3723" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003724" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003725" Sister function: s:NetrwBookHistRead()
3726" I used to do this via viminfo but that appears to
3727" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003728" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3729" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003730" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003731fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003732" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003733 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003734" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003735 return
3736 endif
3737
Bram Moolenaar5c736222010-01-06 20:54:52 +01003738 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003739" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003740 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003741
3742 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003743 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003744" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003745 if g:netrw_use_noswf
3746 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3747 else
3748 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3749 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003750 setl nocin noai noci magic nospell nohid wig= noaw
3751 setl ma noro write
3752 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003753 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003754
Bram Moolenaar85850f32019-07-19 22:05:51 +02003755 " rename enew'd file: .netrwhist -- no attempt to merge
3756 " record dirhistmax and current dirhistcnt
3757 " save history
3758" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003759 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003760 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003761 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3762 if g:netrw_dirhistmax > 0
3763 let lastline = line("$")
3764 let cnt = g:netrw_dirhistcnt
3765 let first = 1
3766 while ( first || cnt != g:netrw_dirhistcnt )
3767 let lastline= lastline + 1
3768 if exists("g:netrw_dirhist_{cnt}")
3769 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3770" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3771 endif
3772 let first = 0
3773 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3774 if cnt < 0
3775 let cnt= cnt + g:netrw_dirhistmax
3776 endif
3777 endwhile
3778 exe "sil! w! ".savefile
3779" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3780 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003781
Bram Moolenaar85850f32019-07-19 22:05:51 +02003782 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003783 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003784 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003785" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003786 " merge and write .netrwbook
3787 let savefile= s:NetrwHome()."/.netrwbook"
3788
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003789 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003790 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003791 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003792 for bdm in booklist
3793 if index(g:netrw_bookmarklist,bdm) == -1
3794 call add(g:netrw_bookmarklist,bdm)
3795 endif
3796 endfor
3797 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003798 endif
3799
3800 " construct and save .netrwbook
3801 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003802 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003803" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003804 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003805
3806 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003807 let bgone= bufnr("%")
3808 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003809 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003810
3811" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003812endfun
3813
3814" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003815" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3816" list of the contents of a local or remote directory. It is assumed that the
3817" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3818" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003819" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003820fun! s:NetrwBrowse(islocal,dirname)
3821 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003822" 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 +02003823" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3824" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3825" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003826
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003827 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3828 " This is useful when one edits a local file, then :e ., then :Rex
3829 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3830 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003831" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003832 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003833
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003834 " s:NetrwBrowse : initialize history {{{3
3835 if !exists("s:netrw_initbookhist")
3836 NetrwKeepj call s:NetrwBookHistRead()
3837 endif
3838
3839 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003840 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003841 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003842" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003843 else
3844 let dirname= a:dirname
3845 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003846
Bram Moolenaar85850f32019-07-19 22:05:51 +02003847 " repoint t:netrw_lexbufnr if appropriate
3848 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3849" call Decho("set repointlexbufnr to true!")
3850 let repointlexbufnr= 1
3851 endif
3852
3853 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003854 if exists("s:netrw_skipbrowse")
3855 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003856" 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 +01003857" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003858 return
3859 endif
3860 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003861 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003862" call Dret("s:NetrwBrowse : missing shellescape()")
3863 return
3864 endif
3865 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003866 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003867" call Dret("s:NetrwBrowse : missing fnameescape()")
3868 return
3869 endif
3870
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003871 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003872 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003873
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003874 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003875 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3876 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3877" call Decho("clearing marked files",'~'.expand("<slnum>"))
3878 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3879 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003880 endif
3881
3882 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003883 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003884" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3885" 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 +02003886 if s:NetrwLcd(dirname)
3887" call Dret("s:NetrwBrowse : lcd failure")
3888 return
3889 endif
3890 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003891" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003892
Bram Moolenaar5c736222010-01-06 20:54:52 +01003893 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003894 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003895" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003896 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003897" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003898 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003899 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003900 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003901" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003902
3903 " remove any filetype indicator from end of dirname, except for the
3904 " "this is a directory" indicator (/).
3905 " There shouldn't be one of those here, anyway.
3906 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003907" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003908 call s:RemotePathAnalysis(dirname)
3909
3910 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3911 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003912 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003913 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003914" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003915 let b:netrw_curdir = dirname
3916 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003917 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003918 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3919 sil call netrw#NetRead(2,url)
3920 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003921" call Decho("url<".url.">",'~'.expand("<slnum>"))
3922" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3923" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003924 if s:path =~ '.bz2'
3925 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3926 elseif s:path =~ '.gz'
3927 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3928 elseif s:path =~ '.gz'
3929 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3930 else
3931 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3932 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003933 endif
3934
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003935 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003936 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003937 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003938" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003939 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003940" 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 +00003941
Bram Moolenaar446cb832008-06-24 21:56:24 +00003942" call Dret("s:NetrwBrowse : file<".s:fname.">")
3943 return
3944 endif
3945
Bram Moolenaaradc21822011-04-01 18:03:16 +02003946 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003947 call s:UseBufWinVars()
3948
3949 " set up some variables {{{3
3950 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003951 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003952 let s:last_sort_by = g:netrw_sort_by
3953
3954 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003955 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003956
Bram Moolenaar97d62492012-11-15 21:28:22 +01003957 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003958" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003959 let svpos = winsaveview()
3960" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003961 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003962
Bram Moolenaar446cb832008-06-24 21:56:24 +00003963 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003964 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3965 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3966" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3967" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3968 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3969 else
3970" " call Decho("2match none",'~'.expand("<slnum>"))
3971 2match none
3972 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003973 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003974 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003975 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003976" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003977 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003978" 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 +01003979" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003980 return
3981 endif
3982
3983 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003984" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003985 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003986 if b:netrw_curdir =~ '[/\\]$'
3987 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3988 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003989 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3990 let b:netrw_curdir= b:netrw_curdir."/"
3991 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003992 if b:netrw_curdir == ''
3993 if has("amiga")
3994 " On the Amiga, the empty string connotes the current directory
3995 let b:netrw_curdir= getcwd()
3996 else
3997 " under unix, when the root directory is encountered, the result
3998 " from the preceding substitute is an empty string.
3999 let b:netrw_curdir= '/'
4000 endif
4001 endif
4002 if !a:islocal && b:netrw_curdir !~ '/$'
4003 let b:netrw_curdir= b:netrw_curdir.'/'
4004 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004005" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004006
4007 " ------------
4008 " (local only) {{{3
4009 " ------------
4010 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004011" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004012
4013 " Set up ShellCmdPost handling. Append current buffer to browselist
4014 call s:LocalFastBrowser()
4015
4016 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
4017 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004018" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
4019" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004020 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004021 if s:NetrwLcd(b:netrw_curdir)
4022" call Dret("s:NetrwBrowse : lcd failure")
4023 return
4024 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004025 endif
4026 endif
4027
4028 " --------------------------------
4029 " remote handling: {{{3
4030 " --------------------------------
4031 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004032" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004033
Bram Moolenaar97d62492012-11-15 21:28:22 +01004034 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004035" 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 +02004036 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004037 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004038" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004039 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4040 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4041 if dirname !~ '/$'
4042 let dirname= dirname.'/'
4043 endif
4044 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004045" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004046 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004047 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004048" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004049 endif
4050
4051 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4052 if dirname !~ dirpat
4053 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004054 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004055 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004056 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004057" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004058 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004059" 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 +00004060" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4061 return
4062 endif
4063 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004064" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004065 endif " (additional remote handling)
4066
Bram Moolenaar85850f32019-07-19 22:05:51 +02004067 " -------------------------------
4068 " Perform Directory Listing: {{{3
4069 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004070 NetrwKeepj call s:NetrwMaps(a:islocal)
4071 NetrwKeepj call s:NetrwCommands(a:islocal)
4072 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004073
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004074 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004075 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004076" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4077
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004078 " If there is a rexposn: restore position with rexposn
4079 " Otherwise : set rexposn
4080 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004081" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4082 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4083 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4084 NetrwKeepj exe w:netrw_bannercnt
4085 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004086 else
4087 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4088 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004089 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004090 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004091" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004092 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004093 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004094
Bram Moolenaar85850f32019-07-19 22:05:51 +02004095 " repoint t:netrw_lexbufnr if appropriate
4096 if exists("repointlexbufnr")
4097 let t:netrw_lexbufnr= bufnr("%")
4098" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4099 endif
4100
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004101 " restore position
4102 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004103" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4104 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004105 endif
4106
Bram Moolenaara6878372014-03-22 21:02:50 +01004107 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004108 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4109 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004110" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4111" 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 +02004112" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004113 return
4114endfun
4115
4116" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004117" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4118" may not apply correctly; ie. netrw's idea of the current directory may
4119" differ from vim's. This function insures that netrw's idea of the current
4120" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004121" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004122fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004123" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4124" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4125" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4126" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4127" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004128
4129 " clean up any leading treedepthstring
4130 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4131 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004132" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004133 else
4134 let fname= a:fname
4135 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004136
4137 if g:netrw_keepdir
4138 " vim's idea of the current directory possibly may differ from netrw's
4139 if !exists("b:netrw_curdir")
4140 let b:netrw_curdir= getcwd()
4141 endif
4142
4143 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004144 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004145 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004146 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004147" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004148 else
4149 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004150 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004151" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004152 endif
4153
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004154 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004155 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004156 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004157" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004158 else
4159 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004160 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004161" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004162 endif
4163 else
4164 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004165 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004166" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4167" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4168" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004169 endif
4170
Bram Moolenaar85850f32019-07-19 22:05:51 +02004171" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004172 return ret
4173endfun
4174
4175" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004176" s:NetrwFileInfo: supports qf (query for file information) {{{2
4177fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004178" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004179 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004180 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004181 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004182 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004183 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004184 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004185 let lsopt= "-lsadh --si"
4186 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004187" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004188 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004189
4190 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004191 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004192" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004193
Bram Moolenaara6878372014-03-22 21:02:50 +01004194 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004195 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004196" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004197
4198 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004199 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004200" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004201
Bram Moolenaar446cb832008-06-24 21:56:24 +00004202 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004203" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004204 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004205" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004206 endif
4207 else
4208 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004209" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4210 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004211 let fname= substitute(a:fname,".$","","")
4212 else
4213 let fname= a:fname
4214 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004215 let t = getftime(s:NetrwFile(fname))
4216 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004217 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004218 let sz= s:NetrwHumanReadable(sz)
4219 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004220 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4221" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004222 endif
4223 else
4224 echo "sorry, \"qf\" not supported yet for remote files"
4225 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004226 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004227" call Dret("s:NetrwFileInfo")
4228endfun
4229
4230" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004231" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4232fun! s:NetrwFullPath(filename)
4233" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4234 let filename= a:filename
4235 if filename !~ '^/'
4236 let filename= resolve(getcwd().'/'.filename)
4237 endif
4238 if filename != "/" && filename =~ '/$'
4239 let filename= substitute(filename,'/$','','')
4240 endif
4241" " call Dret("s:NetrwFullPath <".filename.">")
4242 return filename
4243endfun
4244
4245" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004246" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004247" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004248" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004249" 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 +00004250fun! s:NetrwGetBuffer(islocal,dirname)
4251" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004252" 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 +02004253" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4254" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004255 let dirname= a:dirname
4256
4257 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004258" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004259 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004260" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004261 let s:netrwbuf= {}
4262 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004263" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4264" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4265
4266 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4267 let bufnum = -1
4268
4269 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4270 if has_key(s:netrwbuf,"NetrwTreeListing")
4271 let bufnum= s:netrwbuf["NetrwTreeListing"]
4272 else
4273 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4274 endif
4275" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4276 if !bufexists(bufnum)
4277 call remove(s:netrwbuf,"NetrwTreeListing"])
4278 let bufnum= -1
4279 endif
4280 elseif bufnr("NetrwTreeListing") != -1
4281 let bufnum= bufnr("NetrwTreeListing")
4282" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4283 else
4284" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4285 let bufnum= -1
4286 endif
4287
4288 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004289 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004290" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004291 if !bufexists(bufnum)
4292 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4293 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004294 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004295
Bram Moolenaar446cb832008-06-24 21:56:24 +00004296 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004297" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004298 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004299 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004300" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4301
Bram Moolenaar71badf92023-04-22 22:40:14 +01004302 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004303 " IF the buffer already has the desired name
4304 " AND it is empty
4305 let curbuf = bufname("%")
4306 if curbuf == '.'
4307 let curbuf = getcwd()
4308 endif
4309" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004310" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004311" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4312" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4313" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4314" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4315 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004316" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4317 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004318 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004319" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004320 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004321 " 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 +00004322
4323 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004324 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004325" 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 +00004326 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004327" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004328 " name the buffer
4329 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4330 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004331" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004332 let w:netrw_treebufnr = bufnr("%")
4333 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004334 if g:netrw_use_noswf
4335 setl nobl bt=nofile noswf
4336 else
4337 setl nobl bt=nofile
4338 endif
4339 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4340 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4341 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4342 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004343" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004344 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004345 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004346 " enter the new buffer into the s:netrwbuf dictionary
4347 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4348" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4349" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004350 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004351" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004352
4353 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004354" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004355 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004356 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004357 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004358
4359 if &ft == "netrw"
4360" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4361 exe "sil! NetrwKeepj noswapfile b ".bufnum
4362" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004363 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004364" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4365 call s:NetrwEditBuf(bufnum)
4366" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004368" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004369 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004370 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004371 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004372
4373 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004374 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004375
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004376 if line("$") <= 1 && getline(1) == ""
4377 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004378 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004379" 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>"))
4380" 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 +01004381" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4382 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004383
Bram Moolenaar97d62492012-11-15 21:28:22 +01004384 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004385" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004386 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004387 sil NetrwKeepj %d _
4388" 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>"))
4389" 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 +01004390" 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 +00004391 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004392
Bram Moolenaar446cb832008-06-24 21:56:24 +00004393 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004394" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4395" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004396 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004397 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004398 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004399" 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>"))
4400" 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 +01004401" 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 +00004402 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004403
Bram Moolenaar446cb832008-06-24 21:56:24 +00004404 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004405" 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>"))
4406" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4407" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004408 return 1
4409 endif
4410 endif
4411
4412 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4413 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4414 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4415 " med 1 D H
4416 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004417" 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 +00004418 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004419 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004420 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004421
4422 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004423" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4424" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4425 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004426
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004427" 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>"))
4428" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4429" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004430 return 0
4431endfun
4432
4433" ---------------------------------------------------------------------
4434" s:NetrwGetcwd: get the current directory. {{{2
4435" Change backslashes to forward slashes, if any.
4436" If doesc is true, escape certain troublesome characters
4437fun! s:NetrwGetcwd(doesc)
4438" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4439 let curdir= substitute(getcwd(),'\\','/','ge')
4440 if curdir !~ '[\/]$'
4441 let curdir= curdir.'/'
4442 endif
4443 if a:doesc
4444 let curdir= fnameescape(curdir)
4445 endif
4446" call Dret("NetrwGetcwd <".curdir.">")
4447 return curdir
4448endfun
4449
4450" ---------------------------------------------------------------------
4451" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4452fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004453" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4454" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4455 let keepsol= &l:sol
4456 setl nosol
4457
Bram Moolenaar446cb832008-06-24 21:56:24 +00004458 call s:UseBufWinVars()
4459
4460 " insure that w:netrw_liststyle is set up
4461 if !exists("w:netrw_liststyle")
4462 if exists("g:netrw_liststyle")
4463 let w:netrw_liststyle= g:netrw_liststyle
4464 else
4465 let w:netrw_liststyle= s:THINLIST
4466 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004467" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004468 endif
4469
4470 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4471 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004472" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004473 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004474 let dirname= "./"
4475 let curline= getline('.')
4476
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004477 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004478 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004479 let s:netrw_skipbrowse= 1
4480 echo 'Pressing "s" also works'
4481
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004482 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004483 let s:netrw_skipbrowse= 1
4484 echo 'Press "S" to edit sorting sequence'
4485
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004486 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004487 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004488 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004490 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004491 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004492 let s:netrw_skipbrowse= 1
4493 echo 'Pressing "a" also works'
4494
4495 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004496 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004497 endif
4498
4499 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004500" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004501 NetrwKeepj norm! 0
4502 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004503
4504 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004505" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004506 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004507 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4508
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004509 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004510" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004511 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004512 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004513
4514 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004515" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004516 let dirname= getline('.')
4517
4518 if !exists("b:netrw_cpf")
4519 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004520 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 +01004521 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004522" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004523 endif
4524
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004525" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004526 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004527" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4528" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004529 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004530 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004531 else
4532 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004533 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004534 endif
4535 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004536 let eofname= filestart + b:netrw_cpf + 1
4537 if eofname <= col("$")
4538 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004539 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004540 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004541 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004542 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004543 let dirname = @a
4544 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004545" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004546 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004547" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004548 endif
4549
4550 " symlinks are indicated by a trailing "@". Remove it before further processing.
4551 let dirname= substitute(dirname,"@$","","")
4552
4553 " executables are indicated by a trailing "*". Remove it before further processing.
4554 let dirname= substitute(dirname,"\*$","","")
4555
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004556 let &l:sol= keepsol
4557
Bram Moolenaar446cb832008-06-24 21:56:24 +00004558" call Dret("s:NetrwGetWord <".dirname.">")
4559 return dirname
4560endfun
4561
4562" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004563" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4564" g:netrw_bufsettings will be used after the listing is produced.
4565" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004566fun! s:NetrwListSettings(islocal)
4567" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004568" 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 +00004569 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004570" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4571 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4572 setl bt=nofile nobl ma nonu nowrap noro nornu
4573 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004574 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004575 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004576 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004577" call Dredir("ls!","s:NetrwListSettings")
4578" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004579 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004580 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004581 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004582 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004583 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004584 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004585 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004586" 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 +00004587" call Dret("s:NetrwListSettings")
4588endfun
4589
4590" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004591" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004592" islocal=0: remote browsing
4593" =1: local browsing
4594fun! s:NetrwListStyle(islocal)
4595" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004596
Bram Moolenaar97d62492012-11-15 21:28:22 +01004597 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004598 let fname = s:NetrwGetWord()
4599 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004600 let svpos = winsaveview()
4601" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004602 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004603" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4604" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4605" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004606
Bram Moolenaar85850f32019-07-19 22:05:51 +02004607 " repoint t:netrw_lexbufnr if appropriate
4608 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4609" call Decho("set repointlexbufnr to true!")
4610 let repointlexbufnr= 1
4611 endif
4612
Bram Moolenaar446cb832008-06-24 21:56:24 +00004613 if w:netrw_liststyle == s:THINLIST
4614 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004615" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004616 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4617
4618 elseif w:netrw_liststyle == s:LONGLIST
4619 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004620" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004621 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4622
4623 elseif w:netrw_liststyle == s:WIDELIST
4624 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004625" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004626 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4627
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004628 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004629" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004630 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4631
4632 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004633 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004634 let g:netrw_liststyle = s:THINLIST
4635 let w:netrw_liststyle = g:netrw_liststyle
4636 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4637 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004638 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004639" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004640
4641 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004642" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4643 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004644 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004645" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004646 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004647" 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 +00004648
4649 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004650" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004651 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004652 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004653
Bram Moolenaar85850f32019-07-19 22:05:51 +02004654 " repoint t:netrw_lexbufnr if appropriate
4655 if exists("repointlexbufnr")
4656 let t:netrw_lexbufnr= bufnr("%")
4657" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4658 endif
4659
Bram Moolenaar13600302014-05-22 18:26:40 +02004660 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004661" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4662 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004663 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004664
4665" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4666endfun
4667
4668" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004669" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4670fun! s:NetrwBannerCtrl(islocal)
4671" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4672
Bram Moolenaar97d62492012-11-15 21:28:22 +01004673 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004674 " toggle the banner (enable/suppress)
4675 let g:netrw_banner= !g:netrw_banner
4676
4677 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004678 let svpos= winsaveview()
4679" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004680 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4681
4682 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004683 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4684 let fname= s:NetrwGetWord()
4685 sil NetrwKeepj $
4686 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4687" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4688 if result <= 0 && exists("w:netrw_bannercnt")
4689 exe "NetrwKeepj ".w:netrw_bannercnt
4690 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004691 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004692 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004693" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4694endfun
4695
4696" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004697" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4698"
4699" No bang: enters files/directories into Netrw's bookmark system
4700" No argument and in netrw buffer:
4701" if there are marked files: bookmark marked files
4702" otherwise : bookmark file/directory under cursor
4703" No argument and not in netrw buffer: bookmarks current open file
4704" Has arguments: globs them individually and bookmarks them
4705"
4706" With bang: deletes files/directories from Netrw's bookmark system
4707fun! s:NetrwBookmark(del,...)
4708" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4709 if a:0 == 0
4710 if &ft == "netrw"
4711 let curbufnr = bufnr("%")
4712
4713 if exists("s:netrwmarkfilelist_{curbufnr}")
4714 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004715" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004716 let svpos = winsaveview()
4717" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004718 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004719 for fname in s:netrwmarkfilelist_{curbufnr}
4720 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4721 endfor
4722 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4723 call s:NetrwUnmarkList(curbufnr,curdir)
4724 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004725" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4726 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004727 else
4728 let fname= s:NetrwGetWord()
4729 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4730 endif
4731
4732 else
4733 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004734" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004735 let fname= expand("%")
4736 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4737 endif
4738
4739 else
4740 " bookmark specified files
4741 " attempts to infer if working remote or local
4742 " by deciding if the current file begins with an url
4743 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004744 let islocal= expand("%") !~ '^\a\{3,}://'
4745" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004746 let i = 1
4747 while i <= a:0
4748 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004749 if v:version > 704 || (v:version == 704 && has("patch656"))
4750 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004751 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004752 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004753 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004754 else
4755 let mbfiles= [a:{i}]
4756 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004757" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004758 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004759" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004760 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4761 endfor
4762 let i= i + 1
4763 endwhile
4764 endif
4765
4766 " update the menu
4767 call s:NetrwBookmarkMenu()
4768
4769" call Dret("s:NetrwBookmark")
4770endfun
4771
4772" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004773" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4774" .2.[cnt] for bookmarks, and
4775" .3.[cnt] for history
4776" (see s:NetrwMenu())
4777fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004778 if !exists("s:netrw_menucnt")
4779 return
4780 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004781" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004782
4783 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004784 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004785 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004786" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004787 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4788 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004789 endif
4790 if !exists("s:netrw_initbookhist")
4791 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004792 endif
4793
4794 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004795 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004796 let cnt= 1
4797 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004798" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004799 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004800
4801 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004802 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004803
4804 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004805 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 +01004806 let cnt= cnt + 1
4807 endfor
4808
4809 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004810
4811 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004812 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004813 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004814 let first = 1
4815 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004816 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004817 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004818 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004819 if exists("g:netrw_dirhist_{cnt}")
4820 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004821" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004822 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4823 endif
4824 let first = 0
4825 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4826 if cnt < 0
4827 let cnt= cnt + g:netrw_dirhistmax
4828 endif
4829 endwhile
4830 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004831
Bram Moolenaar9964e462007-05-05 17:54:07 +00004832 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004833" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004834endfun
4835
4836" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004837" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4838" directory and a new directory name. Also, if the
4839" "new directory name" is actually a file,
4840" NetrwBrowseChgDir() edits the file.
4841fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004842" 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 +01004843" 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 +00004844
Bram Moolenaar97d62492012-11-15 21:28:22 +01004845 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004846 if !exists("b:netrw_curdir")
4847 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4848 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004849 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004850" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4851" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004852" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004853" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004854 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004855 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004856" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004857
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004858 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004859" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004860 call s:SavePosn(s:netrw_posn)
4861 NetrwKeepj call s:NetrwOptionsSave("s:")
4862 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004863 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004864 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004865 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004866 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004867 endif
4868 let newdir = a:newdir
4869 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004870 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004871" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004872" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004873" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004874
4875 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004876" 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 +01004877 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004878" 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 +01004879 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004880 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004881" 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 +01004882 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004883" 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 +02004884 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004885 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004886 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004887 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004888" 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 +01004889 endif
4890 endif
4891" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004892" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004893 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004894
Bram Moolenaar446cb832008-06-24 21:56:24 +00004895 " set up o/s-dependent directory recognition pattern
4896 if has("amiga")
4897 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004898 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004899 let dirpat= '[\/]$'
4900 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004901" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004902
4903 if dirname !~ dirpat
4904 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004905 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004907" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004908 endif
4909
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004910" 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 +01004911 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004912 " ------------------------------
4913 " NetrwBrowseChgDir: edit a file {{{3
4914 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004915" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004916
Bram Moolenaar97d62492012-11-15 21:28:22 +01004917 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004918 let s:rexposn_{bufnr("%")}= winsaveview()
4919" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004920" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4921" 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 +01004922
Bram Moolenaar446cb832008-06-24 21:56:24 +00004923 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004924" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4925" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004926" let newdir = s:NetrwTreePath(s:netrw_treetop)
4927" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004928 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004929 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4930" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4931 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004932 if dirname =~ '/$'
4933 let dirname= dirname.newdir
4934 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004935 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004936 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004937" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4938" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004939 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004940" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004941 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004942 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004943 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004944 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004945" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004946 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004947 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004948" 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 +02004949 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004950 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004951 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004952" " 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 +01004953 if type(g:netrw_browse_split) == 3
4954 " open file in server
4955 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004956" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004957 call s:NetrwServerEdit(a:islocal,dirname)
4958" call Dret("s:NetrwBrowseChgDir")
4959 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004960
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004961 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004962 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004963" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004964 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4965 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004966 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004967 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004968 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004969 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004970
Bram Moolenaar446cb832008-06-24 21:56:24 +00004971 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004972 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004973" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004974 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4975 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004976 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004977 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004978 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004979 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004980
Bram Moolenaar446cb832008-06-24 21:56:24 +00004981 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004982 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004983" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004984 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004985 if !exists("b:netrw_curdir")
4986 let b:netrw_curdir= getcwd()
4987 endif
4988 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004989
Bram Moolenaar446cb832008-06-24 21:56:24 +00004990 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004991 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004992" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004993 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004994 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004995" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004996 return
4997 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004998 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004999
Bram Moolenaar9964e462007-05-05 17:54:07 +00005000 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00005001 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005002" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005003 call s:NetrwMenu(0)
5004 " optional change to window
5005 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005006" 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 +02005007 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09005008 " if g:netrw_chgwin is set to one more than the last window, then
5009 " vertically split the last window to make that window available.
5010 let curwin= winnr()
5011 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
5012 vs
5013 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02005014 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005015 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00005016 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005017 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00005018 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005019
Bram Moolenaar9964e462007-05-05 17:54:07 +00005020 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005021
Bram Moolenaar446cb832008-06-24 21:56:24 +00005022 " the point where netrw actually edits the (local) file
5023 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01005024 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005025 if !&mod
5026 " if e the new file would fail due to &mod, then don't change any of the flags
5027 let dolockout= 1
5028 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005029 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005030" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005031 " some like c-^ to return to the last edited file
5032 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005033 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5034 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005035 call s:NetrwEditFile("e","",dirname)
5036" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005037 " COMBAK -- cuc cul related
5038 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005039 if &hidden || &bufhidden == "hide"
5040 " file came from vim's hidden storage. Don't "restore" options with it.
5041 let dorestore= 0
5042 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005043 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005044" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005045 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005046
5047 " handle g:Netrw_funcref -- call external-to-netrw functions
5048 " This code will handle g:Netrw_funcref as an individual function reference
5049 " or as a list of function references. It will ignore anything that's not
5050 " a function reference. See :help Funcref for information about function references.
5051 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005052" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005053 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005054" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005055 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005056 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005057" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005058 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005059 if type(Fncref) == 2
5060 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005061 endif
5062 endfor
5063 endif
5064 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005065 endif
5066
5067 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005068 " ----------------------------------------------------
5069 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5070 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005071" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005072 let dirname = newdir
5073 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005074 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005075 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005076
5077 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005078 " ---------------------------------------------
5079 " NetrwBrowseChgDir: refresh the directory list {{{3
5080 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005081" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005082 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005083 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005084
5085 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005086 " --------------------------------------
5087 " NetrwBrowseChgDir: go up one directory {{{3
5088 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005089" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005090
5091 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5092 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005093" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5094" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005095 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005096 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005097 endif
5098
5099 if has("amiga")
5100 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005101" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005102 if a:islocal
5103 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5104 let dirname= substitute(dirname,'/$','','')
5105 else
5106 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5107 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005108" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005109
Bram Moolenaar8d043172014-01-23 14:24:41 +01005110 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
5111 " windows
5112 if a:islocal
5113 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5114 if dirname == ""
5115 let dirname= '/'
5116 endif
5117 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005118 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005119 endif
5120 if dirname =~ '^\a:$'
5121 let dirname= dirname.'/'
5122 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005123" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005124
Bram Moolenaar446cb832008-06-24 21:56:24 +00005125 else
5126 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005127" 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 +00005128 if a:islocal
5129 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5130 if dirname == ""
5131 let dirname= '/'
5132 endif
5133 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005134 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005135 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005136" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005137 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005138 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005139 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005140
5141 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005142 " --------------------------------------
5143 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5144 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005145" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005146 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5147" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005148 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005149 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005150" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5151 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005152 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005153 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005154" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005155 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005156 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005157" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005158
5159 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005160" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005161 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005162" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005163 let haskey= 1
5164 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005165" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005166 endif
5167
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005168 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005169" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005170 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171 if has_key(w:netrw_treedict,treedir."/")
5172 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005173" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005174 let haskey = 1
5175 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005176" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005177 endif
5178 endif
5179
5180 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005181" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005182 if !haskey && treedir =~ '/$'
5183 let treedir= substitute(treedir,'/$','','')
5184 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005185" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005186 let haskey = 1
5187 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005188" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005189 endif
5190 endif
5191
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005192" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005193 if haskey
5194 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005195" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005196 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005197" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5198" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005199 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005200 else
5201 " go down one directory
5202 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005203" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5204" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005205 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005206 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005207" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005208 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005209
5210 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005211 " ----------------------------------------
5212 " NetrwBrowseChgDir: Go down one directory {{{3
5213 " ----------------------------------------
5214 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005215" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005216 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005217 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005218 endif
5219
Bram Moolenaar97d62492012-11-15 21:28:22 +01005220 " --------------------------------------
5221 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5222 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005223 if dorestore
5224 " dorestore is zero'd when a local file was hidden or bufhidden;
5225 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005226" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005227 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005228" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005229" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005230 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005231 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005232" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005233 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005234" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5235" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005236 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005237" 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 +02005238 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005239" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5240" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005241 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005242" 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 +02005243 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005244 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005245 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005246 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005247
Bram Moolenaar446cb832008-06-24 21:56:24 +00005248" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5249 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005250endfun
5251
5252" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005253" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5254" for thin, long, and wide: cursor placed just after banner
5255" for tree, keeps cursor on current filename
5256fun! s:NetrwBrowseUpDir(islocal)
5257" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005258 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5259 " this test needed because occasionally this function seems to be incorrectly called
5260 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005261 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005262 " directories.
5263" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5264 return
5265 endif
5266
Bram Moolenaara6878372014-03-22 21:02:50 +01005267 norm! 0
5268 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005269" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005270 let curline= getline(".")
5271 let swwline= winline() - 1
5272 if exists("w:netrw_treetop")
5273 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005274 elseif exists("b:netrw_curdir")
5275 let w:netrw_treetop= b:netrw_curdir
5276 else
5277 let w:netrw_treetop= getcwd()
5278 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005279 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005280 let curfile = getline(".")
5281 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005282 if a:islocal
5283 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5284 else
5285 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5286 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005287" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5288" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5289 if w:netrw_treetop == '/'
5290 keepj call search('^\M'.curfile,"w")
5291 elseif curfile == '../'
5292 keepj call search('^\M'.curfile,"wb")
5293 else
5294" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5295 while 1
5296 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5297 let treepath= s:NetrwTreePath(w:netrw_treetop)
5298" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5299 if treepath == curpath
5300 break
5301 endif
5302 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005303 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005304
Bram Moolenaara6878372014-03-22 21:02:50 +01005305 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005306" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005307 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005308 if exists("b:netrw_curdir")
5309 let curdir= b:netrw_curdir
5310 else
5311 let curdir= expand(getcwd())
5312 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005313 if a:islocal
5314 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5315 else
5316 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5317 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005318 call s:RestorePosn(s:netrw_posn)
5319 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005320 let curdir= '\<'. escape(curdir, '~'). '/'
5321 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005322 endif
5323" call Dret("s:NetrwBrowseUpDir")
5324endfun
5325
5326" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005327" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005328" given filename; typically this means given their extension.
5329" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005330fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005331 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005332" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005333
Bram Moolenaar91359012019-11-30 17:57:03 +01005334 if a:remote == 0 && isdirectory(a:fname)
5335 " if its really just a local directory, then do a "gf" instead
5336" 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 +01005337" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5338 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005339" call Dret("netrw#BrowseX")
5340 return
5341 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5342 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5343" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5344" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5345" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5346" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5347 norm! gf
5348" call Dret("netrw#BrowseX")
5349 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005350 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005351" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005352
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005353 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5354 let remote = a:remote
5355 else
5356 let remote = 0
5357 endif
5358
Bram Moolenaar97d62492012-11-15 21:28:22 +01005359 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005360 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005361" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005362
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005363 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5364 let awkeep = &aw
5365 set noaw
5366
Bram Moolenaar5c736222010-01-06 20:54:52 +01005367 " special core dump handler
5368 if a:fname =~ '/core\(\.\d\+\)\=$'
5369 if exists("g:Netrw_corehandler")
5370 if type(g:Netrw_corehandler) == 2
5371 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005372" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005373 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005374 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005375 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005376" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005377 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005378 if type(Fncref) == 2
5379 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005380 endif
5381 endfor
5382 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005383" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005384 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005385 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005386 let &aw= awkeep
5387" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005388 return
5389 endif
5390 endif
5391
Bram Moolenaar446cb832008-06-24 21:56:24 +00005392 " set up the filename
5393 " (lower case the extension, make a local copy of a remote file)
5394 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5395 if has("win32") || has("win95") || has("win64") || has("win16")
5396 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005397 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005398 if exten =~ "[\\/]"
5399 let exten= ""
5400 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005401" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005402
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005403 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005404 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005405" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005406 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005407 call netrw#NetRead(3,a:fname)
5408 " attempt to rename tempfile
5409 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005410 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005411" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5412" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005413 if s:netrw_tmpfile != newname && newname != ""
5414 if rename(s:netrw_tmpfile,newname) == 0
5415 " renaming succeeded
5416" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5417 let fname= newname
5418 else
5419 " renaming failed
5420" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5421 let fname= s:netrw_tmpfile
5422 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005423 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005424 let fname= s:netrw_tmpfile
5425 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005426 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005427" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005428 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005429 " special ~ handler for local
5430 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005431" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5432 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005433 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005434 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005435" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5436" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005437
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005438 " set up redirection (avoids browser messages)
5439 " by default, g:netrw_suppress_gx_mesg is true
5440 if g:netrw_suppress_gx_mesg
5441 if &srr =~ "%s"
5442 if (has("win32") || has("win95") || has("win64") || has("win16"))
5443 let redir= substitute(&srr,"%s","nul","")
5444 else
5445 let redir= substitute(&srr,"%s","/dev/null","")
5446 endif
5447 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5448 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005449 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005450 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005451 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005452 else
5453 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005454 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005455" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005456
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005457 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005458 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005459" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005460 if g:netrw_browsex_viewer =~ '\s'
5461 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5462 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5463 let oviewer = ''
5464 let cnt = 1
5465 while !executable(viewer) && viewer != oviewer
5466 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5467 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5468 let cnt = cnt + 1
5469 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005470" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005471 endwhile
5472 else
5473 let viewer = g:netrw_browsex_viewer
5474 let viewopt = ""
5475 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005476" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005477 endif
5478
5479 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005480" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005481 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005482" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005483 let ret= netrwFileHandlers#Invoke(exten,fname)
5484
5485 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005486" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005487 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005488 let ret= v:shell_error
5489
5490 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005491" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005492 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005493 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005494 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005495 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005496 else
5497 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5498 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005499 let ret= v:shell_error
5500
Bram Moolenaar97d62492012-11-15 21:28:22 +01005501 elseif has("win32unix")
5502 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005503" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005504 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005505" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005506 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005507 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005508" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005509 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005510 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005511" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005512 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005513 else
5514 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5515 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005516 let ret= v:shell_error
5517
Bram Moolenaar85850f32019-07-19 22:05:51 +02005518 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005519" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5520 if a:fname =~ '^https\=://'
5521 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5522 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005523" call Decho("fname<".fname.">")
5524" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005525 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5526
5527 else
5528 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5529 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005530 let ret= v:shell_error
5531
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005532 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5533" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5534 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5535 let ret= v:shell_error
5536
5537 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5538" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5539 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5540 let ret= v:shell_error
5541
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005542 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005543" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005544 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005545 let ret= v:shell_error
5546
5547 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005548" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005549 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005550 let ret= v:shell_error
5551
5552 else
5553 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005554" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005555 let ret= netrwFileHandlers#Invoke(exten,fname)
5556 endif
5557
5558 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5559 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005560" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005561 let ret= netrwFileHandlers#Invoke(exten,fname)
5562 endif
5563
Bram Moolenaarc236c162008-07-13 17:41:49 +00005564 " restoring redraw! after external file handlers
5565 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005566
5567 " cleanup: remove temporary file,
5568 " delete current buffer if success with handler,
5569 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005570 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005571 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005572" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005573"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005574" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005575" endif
5576
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005577 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005578 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005579 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005580 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005581 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005582 if use_ctrlo
5583 exe "sil! NetrwKeepj norm! \<c-o>"
5584 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005585 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005586" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005587 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005588 let @@ = ykeep
5589 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005590
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005591" call Dret("netrw#BrowseX")
5592endfun
5593
5594" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005595" netrw#GX: gets word under cursor for gx support {{{2
5596" See also: netrw#BrowseXVis
5597" netrw#BrowseX
5598fun! netrw#GX()
5599" call Dfunc("netrw#GX()")
5600 if &ft == "netrw"
5601 let fname= s:NetrwGetWord()
5602 else
5603 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5604 endif
5605" call Dret("netrw#GX <".fname.">")
5606 return fname
5607endfun
5608
5609" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005610" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5611fun! netrw#BrowseXVis()
5612" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005613 let akeep = @a
5614 norm! gv"ay
5615 let gxfile= @a
5616 let @a = akeep
5617 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005618" call Dret("netrw#BrowseXVis")
5619endfun
5620
5621" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005622" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5623" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5624" to become an unlisted buffer, so in that case don't bwipe it.
5625fun! s:NetrwBufRename(newname)
5626" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5627" call Dredir("ls!","s:NetrwBufRename (before rename)")
5628 let oldbufname= bufname(bufnr("%"))
5629" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5630
5631 if oldbufname != a:newname
5632" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5633 let b:junk= 1
5634" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5635 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005636" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005637 let oldbufnr= bufnr(oldbufname)
5638" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5639" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5640 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5641" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5642 exe "bwipe! ".oldbufnr
5643" else " Decho
5644" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005645" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5646" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5647" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005648 endif
5649" call Dredir("ls!","s:NetrwBufRename (after rename)")
5650" else " Decho
5651" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5652 endif
5653
5654" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5655endfun
5656
5657" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005658" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005659fun! netrw#CheckIfRemote(...)
5660" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5661 if a:0 > 0
5662 let curfile= a:1
5663 else
5664 let curfile= expand("%")
5665 endif
5666" call Decho("curfile<".curfile.">")
5667 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005668" call Dret("netrw#CheckIfRemote 1")
5669 return 1
5670 else
5671" call Dret("netrw#CheckIfRemote 0")
5672 return 0
5673 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005674endfun
5675
5676" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005677" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5678fun! s:NetrwChgPerm(islocal,curdir)
5679" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005680 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005681 call inputsave()
5682 let newperm= input("Enter new permission: ")
5683 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005684 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5685 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5686" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005687 call system(chgperm)
5688 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005689 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005690 endif
5691 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005692 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005693 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005694 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005695" call Dret("s:NetrwChgPerm")
5696endfun
5697
5698" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005699" s:CheckIfKde: checks if kdeinit is running {{{2
5700" Returns 0: kdeinit not running
5701" 1: kdeinit is running
5702fun! s:CheckIfKde()
5703" call Dfunc("s:CheckIfKde()")
5704 " seems kde systems often have gnome-open due to dependencies, even though
5705 " gnome-open's subsidiary display tools are largely absent. Kde systems
5706 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5707 if !exists("s:haskdeinit")
5708 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005709 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005710 if v:shell_error
5711 let s:haskdeinit = 0
5712 endif
5713 else
5714 let s:haskdeinit= 0
5715 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005716" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005717 endif
5718
5719" call Dret("s:CheckIfKde ".s:haskdeinit)
5720 return s:haskdeinit
5721endfun
5722
5723" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005724" s:NetrwClearExplore: clear explore variables (if any) {{{2
5725fun! s:NetrwClearExplore()
5726" call Dfunc("s:NetrwClearExplore()")
5727 2match none
5728 if exists("s:explore_match") |unlet s:explore_match |endif
5729 if exists("s:explore_indx") |unlet s:explore_indx |endif
5730 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5731 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5732 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5733 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5734 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5735 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5736 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5737" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005738" call Dret("s:NetrwClearExplore")
5739endfun
5740
5741" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005742" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5743fun! s:NetrwEditBuf(bufnum)
5744" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5745 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5746" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5747 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5748 else
5749" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005750 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005751 endif
5752" call Dret("s:NetrwEditBuf")
5753endfun
5754
5755" ---------------------------------------------------------------------
5756" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5757" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5758fun! s:NetrwEditFile(cmd,opt,fname)
5759" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5760 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5761" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5762 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5763 else
5764" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5765 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5766 endif
5767" call Dret("s:NetrwEditFile")
5768endfun
5769
5770" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005771" s:NetrwExploreListUniq: {{{2
5772fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005773" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005774
5775 " this assumes that the list is already sorted
5776 let newexplist= []
5777 for member in a:explist
5778 if !exists("uniqmember") || member != uniqmember
5779 let uniqmember = member
5780 let newexplist = newexplist + [ member ]
5781 endif
5782 endfor
5783
Bram Moolenaar15146672011-10-20 22:22:38 +02005784" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005785 return newexplist
5786endfun
5787
5788" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005789" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5790fun! s:NetrwForceChgDir(islocal,newdir)
5791" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005792 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005793 if a:newdir !~ '/$'
5794 " ok, looks like force is needed to get directory-style treatment
5795 if a:newdir =~ '@$'
5796 let newdir= substitute(a:newdir,'@$','/','')
5797 elseif a:newdir =~ '[*=|\\]$'
5798 let newdir= substitute(a:newdir,'.$','/','')
5799 else
5800 let newdir= a:newdir.'/'
5801 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005802" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005803 else
5804 " should already be getting treatment as a directory
5805 let newdir= a:newdir
5806 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005807 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005808 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005809 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005810" call Dret("s:NetrwForceChgDir")
5811endfun
5812
5813" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005814" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005815" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5816" expr : this is the expression to follow the directory. Will use s:ComposePath()
5817" pare =1: remove the current directory from the resulting glob() filelist
5818" =0: leave the current directory in the resulting glob() filelist
5819fun! s:NetrwGlob(direntry,expr,pare)
5820" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005821 if netrw#CheckIfRemote()
5822 keepalt 1sp
5823 keepalt enew
5824 let keep_liststyle = w:netrw_liststyle
5825 let w:netrw_liststyle = s:THINLIST
5826 if s:NetrwRemoteListing() == 0
5827 keepj keepalt %s@/@@
5828 let filelist= getline(1,$)
5829 q!
5830 else
5831 " remote listing error -- leave treedict unchanged
5832 let filelist= w:netrw_treedict[a:direntry]
5833 endif
5834 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005835 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5836 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5837 if a:pare
5838 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5839 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005840 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005841 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5842 if a:pare
5843 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5844 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005845 endif
5846" call Dret("s:NetrwGlob ".string(filelist))
5847 return filelist
5848endfun
5849
5850" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005851" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5852fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005853" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005854 if a:newfile =~ '[/@*=|\\]$'
5855 let newfile= substitute(a:newfile,'.$','','')
5856 else
5857 let newfile= a:newfile
5858 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005859 if a:islocal
5860 call s:NetrwBrowseChgDir(a:islocal,newfile)
5861 else
5862 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5863 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005864" call Dret("s:NetrwForceFile")
5865endfun
5866
5867" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005868" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5869" and switches the hiding mode. The actual hiding is done by
5870" s:NetrwListHide().
5871" g:netrw_hide= 0: show all
5872" 1: show not-hidden files
5873" 2: show hidden files only
5874fun! s:NetrwHide(islocal)
5875" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005876 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005877 let svpos= winsaveview()
5878" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005879
5880 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005881" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5882" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005883
5884 " hide the files in the markfile list
5885 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005886" 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 +00005887 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5888 " remove fname from hiding list
5889 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5890 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5891 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005892" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005893 else
5894 " append fname to hiding list
5895 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5896 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5897 else
5898 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5899 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005900" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005901 endif
5902 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005903 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005904 let g:netrw_hide= 1
5905
5906 else
5907
5908 " switch between show-all/show-not-hidden/show-hidden
5909 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005910 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005911 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005912 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005913 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005914" call Dret("NetrwHide")
5915 return
5916 endif
5917 endif
5918
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005919 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005920" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5921 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005922 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005923" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005924endfun
5925
5926" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005927" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5928fun! s:NetrwHideEdit(islocal)
5929" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5930
5931 let ykeep= @@
5932 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005933 let svpos= winsaveview()
5934" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005935
5936 " get new hiding list from user
5937 call inputsave()
5938 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5939 call inputrestore()
5940 let g:netrw_list_hide= newhide
5941" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5942
5943 " refresh the listing
5944 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5945
5946 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005947" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5948 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005949 let @@= ykeep
5950
5951" call Dret("NetrwHideEdit")
5952endfun
5953
5954" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005955" s:NetrwHidden: invoked by "gh" {{{2
5956fun! s:NetrwHidden(islocal)
5957" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005958 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005959 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005960 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005961" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005962
5963 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005964 " remove .file pattern from hiding list
5965" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005966 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005967 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005968" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005969 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5970 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005971" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005972 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5973 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005974 if g:netrw_list_hide =~ '^,'
5975 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5976 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005977
5978 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005979 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005980" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5981 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005982 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005983" call Dret("s:NetrwHidden")
5984endfun
5985
5986" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005987" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5988fun! s:NetrwHome()
5989 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005990 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005991 else
5992 " go to vim plugin home
5993 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005994 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005995 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005996 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005997 let home= basehome."/.vim"
5998 break
5999 endif
6000 endfor
6001 if home == ""
6002 " just pick the first directory
6003 let home= substitute(&rtp,',.*$','','')
6004 endif
6005 if (has("win32") || has("win95") || has("win64") || has("win16"))
6006 let home= substitute(home,'/','\\','g')
6007 endif
6008 endif
6009 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006010 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006011" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006012 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02006013" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006014 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01006015 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006016" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006017 call mkdir(home)
6018 endif
6019 endif
6020 let g:netrw_home= home
6021 return home
6022endfun
6023
6024" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006025" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6026fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006027 if exists("s:netrwdrag")
6028 return
6029 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006030 if &ft != "netrw"
6031 return
6032 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006033" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006034
Bram Moolenaar97d62492012-11-15 21:28:22 +01006035 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006036 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006037 while getchar(0) != 0
6038 "clear the input stream
6039 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006040 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006041 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006042 let mouse_lnum = v:mouse_lnum
6043 let wlastline = line('w$')
6044 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006045" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6046" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006047 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6048 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006049 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006050" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6051 return
6052 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006053 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006054 " 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 +01006055 " without this test when its disabled.
6056 " 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 +01006057" 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 +01006058 if v:mouse_col > virtcol('.')
6059 let @@= ykeep
6060" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6061 return
6062 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006063
Bram Moolenaar446cb832008-06-24 21:56:24 +00006064 if a:islocal
6065 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006066 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006067 endif
6068 else
6069 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006070 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006071 endif
6072 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006073 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006074" call Dret("s:NetrwLeftmouse")
6075endfun
6076
6077" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006078" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6079fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006080 if &ft != "netrw"
6081 return
6082 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006083" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6084 call s:NetrwMarkFileTgt(a:islocal)
6085" call Dret("s:NetrwCLeftmouse")
6086endfun
6087
6088" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006089" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6090" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006091" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006092" a:islocal=2 : <c-r> used, remote
6093" a:islocal=3 : <c-r> used, local
6094fun! s:NetrwServerEdit(islocal,fname)
6095" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6096 let islocal = a:islocal%2 " =0: remote =1: local
6097 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006098" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006099
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006100 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006101 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006102 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006103" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006104 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006105 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006106 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6107 unlet s:netrw_browse_split_{winnr()}
6108 endif
6109 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6110" call Dret("s:NetrwServerEdit")
6111 return
6112 endif
6113
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006114" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006115 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006116" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006117
6118 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006119" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006120 let srvrname = g:netrw_browse_split[0]
6121 let tabnum = g:netrw_browse_split[1]
6122 let winnum = g:netrw_browse_split[2]
6123
6124 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006125" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006126
6127 if !ctrlr
6128 " user must have closed the server window and the user did not use <c-r>, but
6129 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006130" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006131 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006132 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006133 endif
6134 let g:netrw_browse_split= 0
6135 if exists("s:netrw_browse_split_".winnr())
6136 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6137 endif
6138 call s:NetrwBrowseChgDir(islocal,a:fname)
6139" call Dret("s:NetrwServerEdit")
6140 return
6141
6142 elseif has("win32") && executable("start")
6143 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006144" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006145 call system("start gvim --servername ".srvrname)
6146
6147 else
6148 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006149" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006150 call system("gvim --servername ".srvrname)
6151 endif
6152 endif
6153
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006154" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006155 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6156 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006157 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006158
6159 else
6160
6161 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6162
6163 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006164" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006165 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006166 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006167 endif
6168 let g:netrw_browse_split= 0
6169 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6170" call Dret("s:NetrwServerEdit")
6171 return
6172
6173 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006174" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006175 if has("win32") && executable("start")
6176 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006177" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006178 call system("start gvim --servername ".g:netrw_servername)
6179 else
6180 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006181" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006182 call system("gvim --servername ".g:netrw_servername)
6183 endif
6184 endif
6185 endif
6186
6187 while 1
6188 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006189" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6190 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006191 break
6192 catch /^Vim\%((\a\+)\)\=:E241/
6193 sleep 200m
6194 endtry
6195 endwhile
6196
6197 if exists("g:netrw_browse_split")
6198 if type(g:netrw_browse_split) != 3
6199 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6200 endif
6201 unlet g:netrw_browse_split
6202 endif
6203 let g:netrw_browse_split= [g:netrw_servername,1,1]
6204 endif
6205
6206 else
6207 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6208 endif
6209
6210" call Dret("s:NetrwServerEdit")
6211endfun
6212
6213" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006214" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6215fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006216 if &ft != "netrw"
6217 return
6218 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006219" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006220
Bram Moolenaar8d043172014-01-23 14:24:41 +01006221 let s:ngw= s:NetrwGetWord()
6222 call s:NetrwMarkFile(a:islocal,s:ngw)
6223
6224" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006225endfun
6226
6227" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006228" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6229" Used to mark multiple files.
6230fun! s:NetrwSLeftdrag(islocal)
6231" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6232 if !exists("s:netrwdrag")
6233 let s:netrwdrag = winnr()
6234 if a:islocal
6235 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006236 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006237 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006238 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006239 endif
6240 let ngw = s:NetrwGetWord()
6241 if !exists("s:ngw") || s:ngw != ngw
6242 call s:NetrwMarkFile(a:islocal,ngw)
6243 endif
6244 let s:ngw= ngw
6245" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6246endfun
6247
6248" ---------------------------------------------------------------------
6249" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6250fun! s:NetrwSLeftrelease(islocal)
6251" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6252 if exists("s:netrwdrag")
6253 nunmap <s-leftrelease>
6254 let ngw = s:NetrwGetWord()
6255 if !exists("s:ngw") || s:ngw != ngw
6256 call s:NetrwMarkFile(a:islocal,ngw)
6257 endif
6258 if exists("s:ngw")
6259 unlet s:ngw
6260 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006261 unlet s:netrwdrag
6262 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006263" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006264endfun
6265
6266" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006267" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6268" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006269fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006270" 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 +02006271" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006272 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006273
6274 " 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 +02006275 " How-it-works: take the hiding command, convert it into a range.
6276 " Duplicate characters don't matter.
6277 " Remove all such characters from the '/~@#...890' string.
6278 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006279" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006280 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006281 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006282" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006283
6284 while listhide != ""
6285 if listhide =~ ','
6286 let hide = substitute(listhide,',.*$','','e')
6287 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6288 else
6289 let hide = listhide
6290 let listhide = ""
6291 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006292" 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 +01006293 if g:netrw_sort_by =~ '^[ts]'
6294 if hide =~ '^\^'
6295" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6296 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6297 elseif hide =~ '^\\(\^'
6298 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6299 endif
6300" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6301 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006302
6303 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006304" 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 +00006305 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006306" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006307 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006308 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006309" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006310 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006311 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006312" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006313 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006314
Bram Moolenaar446cb832008-06-24 21:56:24 +00006315 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006316 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006317" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006318 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006319" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006320 endif
6321
Bram Moolenaaradc21822011-04-01 18:03:16 +02006322 " remove any blank lines that have somehow remained.
6323 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006324 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006325
Bram Moolenaar97d62492012-11-15 21:28:22 +01006326 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006327" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006328endfun
6329
6330" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006331" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006332" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006333fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006334" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335
Bram Moolenaar97d62492012-11-15 21:28:22 +01006336 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006337 " get name of new directory from user. A bare <CR> will skip.
6338 " if its currently a directory, also request will be skipped, but with
6339 " a message.
6340 call inputsave()
6341 let newdirname= input("Please give directory name: ")
6342 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006343" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006344
6345 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006346 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006347" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006348 return
6349 endif
6350
6351 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006352" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006353
6354 " Local mkdir:
6355 " sanity checks
6356 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006357" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6358 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006359 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006360 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006361 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006362 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006363" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006364 return
6365 endif
6366 if s:FileReadable(fullnewdir)
6367 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006368 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006369 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006370 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006371" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006372 return
6373 endif
6374
6375 " requested new local directory is neither a pre-existing file or
6376 " directory, so make it!
6377 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006378 if has("unix")
6379 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6380 else
6381 call mkdir(fullnewdir,"p")
6382 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006383 else
6384 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006385 if s:NetrwLcd(b:netrw_curdir)
6386" call Dret("s:NetrwMakeDir : lcd failure")
6387 return
6388 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006389" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006390 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006391 if v:shell_error != 0
6392 let @@= ykeep
6393 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 +01006394" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006395 return
6396 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006397 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006398" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006399 if s:NetrwLcd(netrw_origdir)
6400" call Dret("s:NetrwBrowse : lcd failure")
6401 return
6402 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006403 endif
6404 endif
6405
6406 if v:shell_error == 0
6407 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006408" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006409 let svpos= winsaveview()
6410" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006411 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006412" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6413 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006414 elseif !exists("g:netrw_quiet")
6415 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6416 endif
6417" redraw!
6418
6419 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006420 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006421" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006422 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6423 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006424 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006425 if v:shell_error == 0
6426 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006427 let svpos= winsaveview()
6428" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006429 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006430" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6431 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006432 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006433 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006434 endif
6435" redraw!
6436
6437 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006438 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006439 let svpos= winsaveview()
6440" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006441" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006442 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006443" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006444 let remotepath= b:netrw_fname
6445 else
6446 let remotepath= ""
6447 endif
6448 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006449 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006450" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6451 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006452
Bram Moolenaar446cb832008-06-24 21:56:24 +00006453 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006454 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006455 let svpos= winsaveview()
6456" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006457" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006458 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006459" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006460 let remotepath= b:netrw_fname
6461 else
6462 let remotepath= ""
6463 endif
6464 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006465 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006466" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6467 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006468 endif
6469
Bram Moolenaar97d62492012-11-15 21:28:22 +01006470 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006471" call Dret("s:NetrwMakeDir")
6472endfun
6473
6474" ---------------------------------------------------------------------
6475" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6476fun! s:TreeSqueezeDir(islocal)
6477" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6478 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6479 " its a tree-listing style
6480 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006481 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006482 let depth = strchars(substitute(curdepth,' ','','g'))
6483 let srch = -1
6484" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6485" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006486" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006487" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6488 if depth >= 2
6489 NetrwKeepj norm! 0
6490 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6491 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6492" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6493" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6494 elseif depth == 1
6495 NetrwKeepj norm! 0
6496 let treedepthchr= substitute(s:treedepthstring,' ','','')
6497 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6498" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6499 endif
6500 if srch > 0
6501" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6502 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6503 exe srch
6504 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006505 endif
6506" call Dret("s:TreeSqueezeDir")
6507endfun
6508
6509" ---------------------------------------------------------------------
6510" s:NetrwMaps: {{{2
6511fun! s:NetrwMaps(islocal)
6512" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6513
Bram Moolenaar85850f32019-07-19 22:05:51 +02006514 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006515 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006516" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006517 if !hasmapto("<Plug>NetrwReturn")
6518 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006519" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006520 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6521 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006522" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006523 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6524 endif
6525 endif
6526 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006527" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006528 endif
6529
Bram Moolenaar85850f32019-07-19 22:05:51 +02006530 " generate default <Plug> maps {{{3
6531 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006532 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006533 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6534 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6535 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6536 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6537 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6538 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6539 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6540 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6541 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6542 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6543" ---------------------------------------------------------------------
6544" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6545" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6546" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6547" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6548" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6549" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6550" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6551" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6552" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6553" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6554" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6555" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6556" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6557" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6558" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6559" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6560" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6561" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6562" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6563" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6564" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6565" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6566" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6567" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6568" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6569" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6570" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6571" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6572" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6573" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6574" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6575" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6576" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6577" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6578" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6579" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6580" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6581" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6582" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6583" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6584" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6585" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6586" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6587" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6588" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6589" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6590" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6591
Bram Moolenaara6878372014-03-22 21:02:50 +01006592 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006593" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006594 " local normal-mode maps {{{3
6595 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6596 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6597 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6598 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6599 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6600 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6601 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6602 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6603 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6604 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6605 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6606" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006607 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6608 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6609 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006610 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006611 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006612 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6613 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6614 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6615 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006616 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6617 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6618 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6619 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6620 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6621 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6622 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6623 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6624 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6625 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6626 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6627 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6628 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006629 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006630 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006631 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6632 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6633 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6634 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6635 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006636 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006637 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006638 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6639 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006640 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6641 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6642 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006643 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006644 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006645 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6646 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006647 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006648 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006649 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6650 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6651 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006652 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6653 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006654
6655 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 +01006656 if !hasmapto('<Plug>NetrwHideEdit')
6657 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006658 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006659 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006660 if !hasmapto('<Plug>NetrwRefresh')
6661 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006662 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006663 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 +01006664 if s:didstarstar || !mapcheck("<s-down>","n")
6665 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006666 endif
6667 if s:didstarstar || !mapcheck("<s-up>","n")
6668 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006669 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006670 if !hasmapto('<Plug>NetrwTreeSqueeze')
6671 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006672 endif
6673 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006674 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6675 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006676 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6677 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6678 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6679 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6680 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6681 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6682 imap <buffer> <leftmouse> <Plug>ILeftmouse
6683 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006684 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6685 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6686 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6687 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6688 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006689 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006690 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6691 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006692 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006693 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6694 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6695 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6696 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6697 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6698 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6699 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006700 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6701
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006702 " support user-specified maps
6703 call netrw#UserMaps(1)
6704
Bram Moolenaar85850f32019-07-19 22:05:51 +02006705 else
6706 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006707" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006708 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006709 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6710 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6711 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6712 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6713 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6714 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6715 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6716 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6717 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6718 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6719 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6720" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006721 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6722 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6723 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6724 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6725 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6726 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6727 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6728 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006729 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006730 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006731 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6732 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6733 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6734 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6735 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6736 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6737 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6738 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6739 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6740 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6741 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006742 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006743 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006744 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6745 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6746 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6747 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6748 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006749 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6750 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6751 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6752 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006753 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006754 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6755 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006756 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006757 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 +01006758 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6759 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6760 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6761 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6762 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6763 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6764 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6765 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6766 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006767 if !hasmapto('<Plug>NetrwHideEdit')
6768 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006769 endif
6770 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6771 if !hasmapto('<Plug>NetrwRefresh')
6772 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006773 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006774 if !hasmapto('<Plug>NetrwTreeSqueeze')
6775 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006776 endif
6777 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006778
6779 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006780 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006781
6782 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6783 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006784 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006785 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006786 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006787 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006788 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006789 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006790 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006791 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006792 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006793 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006794 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6795 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6796 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006797 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006798 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006799 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6800 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006801 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006802 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6803 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6804 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6805 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6806 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6807 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6808 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006809 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006810
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006811 " support user-specified maps
6812 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006813 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006814
6815" call Dret("s:NetrwMaps")
6816endfun
6817
6818" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006819" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006820" If -buffer, the command is only available from within netrw buffers
6821" Otherwise, the command is available from any window, so long as netrw
6822" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006823fun! s:NetrwCommands(islocal)
6824" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6825
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006826 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6827 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006828 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 +01006829 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006830 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006831 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006832 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006833 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006834 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006835
6836" call Dret("s:NetrwCommands")
6837endfun
6838
6839" ---------------------------------------------------------------------
6840" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6841" glob()ing only works with local files
6842fun! s:NetrwMarkFiles(islocal,...)
6843" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006844 let curdir = s:NetrwGetCurdir(a:islocal)
6845 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006846 while i <= a:0
6847 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006848 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006849 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006850 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006851 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006852 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006853 else
6854 let mffiles= [a:{i}]
6855 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006856" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006857 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006858" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006859 call s:NetrwMarkFile(a:islocal,mffile)
6860 endfor
6861 let i= i + 1
6862 endwhile
6863" call Dret("s:NetrwMarkFiles")
6864endfun
6865
6866" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006867" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006868fun! s:NetrwMarkTarget(...)
6869" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6870 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006871 let curdir = s:NetrwGetCurdir(1)
6872 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006873 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006874 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6875 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006876 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006877" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006878 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006879 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6880 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006881 let svpos = winsaveview()
6882" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006883 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006884" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6885 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006886" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006887endfun
6888
6889" ---------------------------------------------------------------------
6890" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6891" mark and unmark files. If a markfile list exists,
6892" then the rename and delete functions will use it instead
6893" of whatever may happen to be under the cursor at that
6894" moment. When the mouse and gui are available,
6895" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006896"
6897" Creates two lists
6898" s:netrwmarkfilelist -- holds complete paths to all marked files
6899" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6900"
6901" Creates a marked file match string
6902" s:netrwmarfilemtch_# -- used with 2match to display marked files
6903"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006904" Creates a buffer version of islocal
6905" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006906fun! s:NetrwMarkFile(islocal,fname)
6907" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006908" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006909
6910 " sanity check
6911 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006912" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006913 return
6914 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006915 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006916
Bram Moolenaar97d62492012-11-15 21:28:22 +01006917 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006918 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006919 if a:fname =~ '^\a'
6920 let leader= '\<'
6921 else
6922 let leader= ''
6923 endif
6924 if a:fname =~ '\a$'
6925 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6926 else
6927 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6928 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006929
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006930 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006931 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006932" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6933" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6934" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006935 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936
6937 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006938 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006939" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006940 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006941 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942
6943 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006944 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006945" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006946 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6947 if s:netrwmarkfilelist_{curbufnr} == []
6948 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006949" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006950 call s:NetrwUnmarkList(curbufnr,curdir)
6951 else
6952 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006953" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006954 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006955 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006956 for fname in s:netrwmarkfilelist_{curbufnr}
6957 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006958 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006959 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006960 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006961 endif
6962 let first= 0
6963 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006964" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965 endif
6966 endif
6967
6968 else
6969 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006970" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006971
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006972" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006973 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006974 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6975" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006976
6977 " build initial markfile matching pattern
6978 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006979 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006980 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006981 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006982 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006983" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006984 endif
6985
6986 " handle global markfilelist
6987 if exists("s:netrwmarkfilelist")
6988 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6989 if index(s:netrwmarkfilelist,dname) == -1
6990 " append new filename to global markfilelist
6991 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006992" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006993 else
6994 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006995" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6996" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006997 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006998" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006999 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007000" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007001 unlet s:netrwmarkfilelist
7002 endif
7003 endif
7004 else
7005 " initialize new global-directory markfilelist
7006 let s:netrwmarkfilelist= []
7007 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007008" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007009 endif
7010
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007011 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02007012 if has("syntax") && exists("g:syntax_on") && g:syntax_on
7013 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
7014" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
7015 if exists("g:did_drchip_netrwlist_syntax")
7016 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
7017 endif
7018 else
7019" " call Decho("2match none",'~'.expand("<slnum>"))
7020 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01007021 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007022 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007023 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007024" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
7025" 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 +00007026endfun
7027
7028" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007029" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7030" mA: move the argument list to marked file list (tomflist=1)
7031" Uses the global marked file list
7032fun! s:NetrwMarkFileArgList(islocal,tomflist)
7033" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7034
7035 let svpos = winsaveview()
7036" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7037 let curdir = s:NetrwGetCurdir(a:islocal)
7038 let curbufnr = bufnr("%")
7039
7040 if a:tomflist
7041 " mA: move argument list to marked file list
7042 while argc()
7043 let fname= argv(0)
7044" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7045 exe "argdel ".fnameescape(fname)
7046 call s:NetrwMarkFile(a:islocal,fname)
7047 endwhile
7048
7049 else
7050 " ma: move marked file list to argument list
7051 if exists("s:netrwmarkfilelist")
7052
7053 " for every filename in the marked list
7054 for fname in s:netrwmarkfilelist
7055" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7056 exe "argadd ".fnameescape(fname)
7057 endfor " for every file in the marked list
7058
7059 " unmark list and refresh
7060 call s:NetrwUnmarkList(curbufnr,curdir)
7061 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7062" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7063 NetrwKeepj call winrestview(svpos)
7064 endif
7065 endif
7066
7067" call Dret("s:NetrwMarkFileArgList")
7068endfun
7069
7070" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007071" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7072" compress/decompress files using the programs
7073" in g:netrw_compress and g:netrw_uncompress,
7074" using g:netrw_compress_suffix to know which to
7075" do. By default:
7076" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007077" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007078fun! s:NetrwMarkFileCompress(islocal)
7079" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007080 let svpos = winsaveview()
7081" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007082 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007083 let curbufnr = bufnr("%")
7084
Bram Moolenaarff034192013-04-24 18:51:19 +02007085 " sanity check
7086 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007087 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007088" call Dret("s:NetrwMarkFileCompress")
7089 return
7090 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007091" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007092
Bram Moolenaar446cb832008-06-24 21:56:24 +00007093 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007094
7095 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007096 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007097 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007098" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007099 if exists("g:netrw_decompress['".sfx."']")
7100 " fname has a suffix indicating that its compressed; apply associated decompression routine
7101 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007102" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007103 let exe= netrw#WinPath(exe)
7104 if a:islocal
7105 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007106 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007107 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007108 call system(exe." ".fname)
7109 if v:shell_error
7110 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007111 endif
7112 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007113 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7114 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007115 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007116
Bram Moolenaarff034192013-04-24 18:51:19 +02007117 endif
7118 unlet sfx
7119
Bram Moolenaar446cb832008-06-24 21:56:24 +00007120 if exists("exe")
7121 unlet exe
7122 elseif a:islocal
7123 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007124 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007125 if v:shell_error
7126 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7127 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007128 else
7129 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007130 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007131 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007132 endfor " for every file in the marked list
7133
Bram Moolenaar446cb832008-06-24 21:56:24 +00007134 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007135 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007136" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7137 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007138 endif
7139" call Dret("s:NetrwMarkFileCompress")
7140endfun
7141
7142" ---------------------------------------------------------------------
7143" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7144" If no marked files, then set up directory as the
7145" target. Currently does not support copying entire
7146" directories. Uses the local-buffer marked file list.
7147" Returns 1=success (used by NetrwMarkFileMove())
7148" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007149fun! s:NetrwMarkFileCopy(islocal,...)
7150" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7151
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007152 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007153 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007154 if b:netrw_curdir !~ '/$'
7155 if !exists("b:netrw_curdir")
7156 let b:netrw_curdir= curdir
7157 endif
7158 let b:netrw_curdir= b:netrw_curdir."/"
7159 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007160
Bram Moolenaarff034192013-04-24 18:51:19 +02007161 " sanity check
7162 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007163 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007164" call Dret("s:NetrwMarkFileCopy")
7165 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007166 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007167" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007168
Bram Moolenaar446cb832008-06-24 21:56:24 +00007169 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007170 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007171" call Dret("s:NetrwMarkFileCopy 0")
7172 return 0
7173 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007174" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007175
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007176 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007177 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007178" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007179 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007180 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7181" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7182 return
7183 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007184
7185 " copy marked files while within the same directory (ie. allow renaming)
7186 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7187 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7188 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007189" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007190 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007191 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7192 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007193" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007194 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007195 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007196 let oldname = a:1
7197 else
7198 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007199" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007200 let s:recursive= 1
7201 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7202 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7203 if ret == 0
7204 break
7205 endif
7206 endfor
7207 unlet s:recursive
7208 call s:NetrwUnmarkList(curbufnr,curdir)
7209" call Dret("s:NetrwMarkFileCopy ".ret)
7210 return ret
7211 endif
7212
7213 call inputsave()
7214 let newname= input("Copy ".oldname." to : ",oldname,"file")
7215 call inputrestore()
7216 if newname == ""
7217" call Dret("s:NetrwMarkFileCopy 0")
7218 return 0
7219 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007220 let args= s:ShellEscape(oldname)
7221 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007222 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007223 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7224 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007225 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007226 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7227 let args= substitute(args,'/','\\','g')
7228 let tgt = substitute(tgt, '/','\\','g')
7229 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007230 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7231 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7232 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7233 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7234" call Decho("args <".args.">",'~'.expand("<slnum>"))
7235" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007236 if isdirectory(s:NetrwFile(args))
7237" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007238 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007239" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007240 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7241 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7242 " contents to a target. One must append the source directory name to the target to get xcopy to
7243 " do the right thing.
7244 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007245" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007246 endif
7247 else
7248 let copycmd= g:netrw_localcopycmd
7249 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007250 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007251 let copycmd = substitute(copycmd,'\s.*$','','')
7252 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007253 let copycmd = netrw#WinPath(copycmd).copycmdargs
7254 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007255 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007256 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007257" call Decho("args <".args.">",'~'.expand("<slnum>"))
7258" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7259" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7260" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007261 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007262 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007263 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007264 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 +01007265 else
7266 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7267 endif
7268" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007269 return 0
7270 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007271
7272 elseif a:islocal && !s:netrwmftgt_islocal
7273 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007274" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007275 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007276
7277 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007278 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007279" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007280 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007281
7282 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007283 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007284" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007285 let curdir = getcwd()
7286 let tmpdir = s:GetTempfile("")
7287 if tmpdir !~ '/'
7288 let tmpdir= curdir."/".tmpdir
7289 endif
7290 if exists("*mkdir")
7291 call mkdir(tmpdir)
7292 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007293 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007294 if v:shell_error != 0
7295 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 +01007296" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007297 return
7298 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007299 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007300 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007301 if s:NetrwLcd(tmpdir)
7302" call Dret("s:NetrwMarkFileCopy : lcd failure")
7303 return
7304 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007305 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007306 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007307 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007308 if getcwd() == tmpdir
7309 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007310 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007311 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007312 if s:NetrwLcd(curdir)
7313" call Dret("s:NetrwMarkFileCopy : lcd failure")
7314 return
7315 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007316 if delete(tmpdir,"d")
7317 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007318 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007319 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007320 if s:NetrwLcd(curdir)
7321" call Dret("s:NetrwMarkFileCopy : lcd failure")
7322 return
7323 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007324 endif
7325 endif
7326 endif
7327
7328 " -------
7329 " cleanup
7330 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007331" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007332 " remove markings from local buffer
7333 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007334" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7335" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7336" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7337" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7338" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7339" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7340 if exists("s:recursive")
7341" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7342 else
7343" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007344 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007345 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007346 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007347 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007348 else
7349 " refresh local and targets for fast browsing
7350 if !exists("s:recursive")
7351 " remove markings from local buffer
7352" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7353 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7354 endif
7355
7356 " refresh buffers
7357 if s:netrwmftgt_islocal
7358" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7359 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7360 endif
7361 if a:islocal && s:netrwmftgt != curdir
7362" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7363 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7364 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007365 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007366
Bram Moolenaar446cb832008-06-24 21:56:24 +00007367" call Dret("s:NetrwMarkFileCopy 1")
7368 return 1
7369endfun
7370
7371" ---------------------------------------------------------------------
7372" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7373" invoke vim's diff mode on the marked files.
7374" Either two or three files can be so handled.
7375" Uses the global marked file list.
7376fun! s:NetrwMarkFileDiff(islocal)
7377" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7378 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007379
Bram Moolenaarff034192013-04-24 18:51:19 +02007380 " sanity check
7381 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007382 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007383" call Dret("s:NetrwMarkFileDiff")
7384 return
7385 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007386 let curdir= s:NetrwGetCurdir(a:islocal)
7387" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007388
Bram Moolenaara6878372014-03-22 21:02:50 +01007389 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007390 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007391 for fname in s:netrwmarkfilelist
7392 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007393 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007394" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007395 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007396 diffthis
7397 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007398 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007399" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007400 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007401 diffthis
7402 else
7403 break
7404 endif
7405 endfor
7406 call s:NetrwUnmarkList(curbufnr,curdir)
7407 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007408
Bram Moolenaar446cb832008-06-24 21:56:24 +00007409" call Dret("s:NetrwMarkFileDiff")
7410endfun
7411
7412" ---------------------------------------------------------------------
7413" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7414" Uses global markfilelist
7415fun! s:NetrwMarkFileEdit(islocal)
7416" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7417
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007418 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007419 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007420
7421 " sanity check
7422 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007423 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007424" call Dret("s:NetrwMarkFileEdit")
7425 return
7426 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007427" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007428
Bram Moolenaar446cb832008-06-24 21:56:24 +00007429 if exists("s:netrwmarkfilelist_{curbufnr}")
7430 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007431 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007432 " unmark markedfile list
7433" call s:NetrwUnmarkList(curbufnr,curdir)
7434 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007435" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007436 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007437 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007438 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007439
Bram Moolenaar446cb832008-06-24 21:56:24 +00007440" call Dret("s:NetrwMarkFileEdit")
7441endfun
7442
7443" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007444" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007445fun! s:NetrwMarkFileQFEL(islocal,qfel)
7446" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7447 call s:NetrwUnmarkAll()
7448 let curbufnr= bufnr("%")
7449
7450 if !empty(a:qfel)
7451 for entry in a:qfel
7452 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007453" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007454 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007455" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007456 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7457 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7458 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7459 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007460" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007461 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7462 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007463" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007464 endif
7465 endfor
7466 echo "(use me to edit marked files)"
7467 else
7468 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7469 endif
7470
7471" call Dret("s:NetrwMarkFileQFEL")
7472endfun
7473
7474" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007475" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7476" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7477" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7478fun! s:NetrwMarkFileExe(islocal,enbloc)
7479" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007480 let svpos = winsaveview()
7481" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007482 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007483 let curbufnr = bufnr("%")
7484
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007485 if a:enbloc == 0
7486 " individually apply command to files, one at a time
7487 " sanity check
7488 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7489 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7490" call Dret("s:NetrwMarkFileExe")
7491 return
7492 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007493" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007494
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007495 if exists("s:netrwmarkfilelist_{curbufnr}")
7496 " get the command
7497 call inputsave()
7498 let cmd= input("Enter command: ","","file")
7499 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007500" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007501 if cmd == ""
7502" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7503 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007504 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007505
7506 " apply command to marked files, individually. Substitute: filename -> %
7507 " If no %, then append a space and the filename to the command
7508 for fname in s:netrwmarkfilelist_{curbufnr}
7509 if a:islocal
7510 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007511 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007512 endif
7513 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007514 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007515 endif
7516 if cmd =~ '%'
7517 let xcmd= substitute(cmd,'%',fname,'g')
7518 else
7519 let xcmd= cmd.' '.fname
7520 endif
7521 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007522" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007523 let ret= system(xcmd)
7524 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007525" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007526 let ret= s:RemoteSystem(xcmd)
7527 endif
7528 if v:shell_error < 0
7529 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7530 break
7531 else
7532 echo ret
7533 endif
7534 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007535
7536 " unmark marked file list
7537 call s:NetrwUnmarkList(curbufnr,curdir)
7538
7539 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007540 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007541" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7542 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007543 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007544 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007545 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007546
7547 else " apply command to global list of files, en bloc
7548
7549 call inputsave()
7550 let cmd= input("Enter command: ","","file")
7551 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007552" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007553 if cmd == ""
7554" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7555 return
7556 endif
7557 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007558 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007559 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007560 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007561 endif
7562 if a:islocal
7563 call system(cmd)
7564 if v:shell_error < 0
7565 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7566 endif
7567 else
7568 let ret= s:RemoteSystem(cmd)
7569 endif
7570 call s:NetrwUnmarkAll()
7571
7572 " refresh the listing
7573 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007574" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7575 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007576
7577 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007578
Bram Moolenaar446cb832008-06-24 21:56:24 +00007579" call Dret("s:NetrwMarkFileExe")
7580endfun
7581
7582" ---------------------------------------------------------------------
7583" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7584" as the marked file(s) (toggles suffix presence)
7585" Uses the local marked file list.
7586fun! s:NetrwMarkHideSfx(islocal)
7587" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007588 let svpos = winsaveview()
7589" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007590 let curbufnr = bufnr("%")
7591
7592 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7593 if exists("s:netrwmarkfilelist_{curbufnr}")
7594
7595 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007596" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007597 " construct suffix pattern
7598 if fname =~ '\.'
7599 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7600 else
7601 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7602 endif
7603 " determine if its in the hiding list or not
7604 let inhidelist= 0
7605 if g:netrw_list_hide != ""
7606 let itemnum = 0
7607 let hidelist= split(g:netrw_list_hide,',')
7608 for hidepat in hidelist
7609 if sfxpat == hidepat
7610 let inhidelist= 1
7611 break
7612 endif
7613 let itemnum= itemnum + 1
7614 endfor
7615 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007616" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007617 if inhidelist
7618 " remove sfxpat from list
7619 call remove(hidelist,itemnum)
7620 let g:netrw_list_hide= join(hidelist,",")
7621 elseif g:netrw_list_hide != ""
7622 " append sfxpat to non-empty list
7623 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7624 else
7625 " set hiding list to sfxpat
7626 let g:netrw_list_hide= sfxpat
7627 endif
7628 endfor
7629
7630 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007631 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007632" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7633 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007634 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007635 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007636 endif
7637
7638" call Dret("s:NetrwMarkHideSfx")
7639endfun
7640
7641" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007642" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007643" Uses the local marked-file list.
7644fun! s:NetrwMarkFileVimCmd(islocal)
7645" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007646 let svpos = winsaveview()
7647" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007648 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007649 let curbufnr = bufnr("%")
7650
Bram Moolenaarff034192013-04-24 18:51:19 +02007651 " sanity check
7652 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007653 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007654" call Dret("s:NetrwMarkFileVimCmd")
7655 return
7656 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007657" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007658
Bram Moolenaar15146672011-10-20 22:22:38 +02007659 if exists("s:netrwmarkfilelist_{curbufnr}")
7660 " get the command
7661 call inputsave()
7662 let cmd= input("Enter vim command: ","","file")
7663 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007664" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007665 if cmd == ""
7666" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7667 return
7668 endif
7669
7670 " apply command to marked files. Substitute: filename -> %
7671 " If no %, then append a space and the filename to the command
7672 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007673" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007674 if a:islocal
7675 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007676 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007677" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007678 exe cmd
7679 exe "sil! keepalt wq!"
7680 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007681" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007682 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007683 endif
7684 endfor
7685
7686 " unmark marked file list
7687 call s:NetrwUnmarkList(curbufnr,curdir)
7688
7689 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007690 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007691" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7692 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007693 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007694 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007695 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007696
Bram Moolenaar15146672011-10-20 22:22:38 +02007697" call Dret("s:NetrwMarkFileVimCmd")
7698endfun
7699
7700" ---------------------------------------------------------------------
7701" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7702" as the marked file(s) (toggles suffix presence)
7703" Uses the local marked file list.
7704fun! s:NetrwMarkHideSfx(islocal)
7705" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007706 let svpos = winsaveview()
7707" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007708 let curbufnr = bufnr("%")
7709
7710 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7711 if exists("s:netrwmarkfilelist_{curbufnr}")
7712
7713 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007714" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007715 " construct suffix pattern
7716 if fname =~ '\.'
7717 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7718 else
7719 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7720 endif
7721 " determine if its in the hiding list or not
7722 let inhidelist= 0
7723 if g:netrw_list_hide != ""
7724 let itemnum = 0
7725 let hidelist= split(g:netrw_list_hide,',')
7726 for hidepat in hidelist
7727 if sfxpat == hidepat
7728 let inhidelist= 1
7729 break
7730 endif
7731 let itemnum= itemnum + 1
7732 endfor
7733 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007734" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007735 if inhidelist
7736 " remove sfxpat from list
7737 call remove(hidelist,itemnum)
7738 let g:netrw_list_hide= join(hidelist,",")
7739 elseif g:netrw_list_hide != ""
7740 " append sfxpat to non-empty list
7741 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7742 else
7743 " set hiding list to sfxpat
7744 let g:netrw_list_hide= sfxpat
7745 endif
7746 endfor
7747
7748 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007749 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007750" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7751 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007752 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007753 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007754 endif
7755
7756" call Dret("s:NetrwMarkHideSfx")
7757endfun
7758
7759" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007760" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7761" Uses the global markfilelist
7762fun! s:NetrwMarkFileGrep(islocal)
7763" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007764 let svpos = winsaveview()
7765" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007766 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007767 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007768
7769 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007770" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007771 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007772" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007773 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007774 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007775" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007776 let netrwmarkfilelist= "*"
7777 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007778
Bram Moolenaarff034192013-04-24 18:51:19 +02007779 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007780" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007781 call inputsave()
7782 let pat= input("Enter pattern: ","")
7783 call inputrestore()
7784 let patbang = ""
7785 if pat =~ '^!'
7786 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007787 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007788 endif
7789 if pat =~ '^\i'
7790 let pat = escape(pat,'/')
7791 let pat = '/'.pat.'/'
7792 else
7793 let nonisi = pat[0]
7794 endif
7795
7796 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007797" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007798 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007799 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007800 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007801 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007802" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7803 return
7804 endtry
7805 echo "(use :cn, :cp to navigate, :Rex to return)"
7806
7807 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007808" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7809 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007810
7811 if exists("nonisi")
7812 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007813" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007814 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007815 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007816 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817 endif
7818
7819" call Dret("s:NetrwMarkFileGrep")
7820endfun
7821
7822" ---------------------------------------------------------------------
7823" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7824" uses the global marked file list
7825" s:netrwmfloc= 0: target directory is remote
7826" = 1: target directory is local
7827fun! s:NetrwMarkFileMove(islocal)
7828" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007829 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007830 let curbufnr = bufnr("%")
7831
7832 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007833 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007834 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007835" call Dret("s:NetrwMarkFileMove")
7836 return
7837 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007838" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007839
Bram Moolenaar446cb832008-06-24 21:56:24 +00007840 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007841 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007842" call Dret("s:NetrwMarkFileCopy 0")
7843 return 0
7844 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007845" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007846
7847 if a:islocal && s:netrwmftgt_islocal
7848 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007849" call Decho("move from local to local",'~'.expand("<slnum>"))
7850" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007851 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007852 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7853" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7854 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007855 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007856 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007857" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007858 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007859 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007860" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007861 if g:netrw_localmovecmd =~ '\s'
7862 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7863 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7864 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007865" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007866 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007867 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007868" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007869 endif
7870 else
7871 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007872" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007873 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007874 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007875 if g:netrw_keepdir
7876 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7877 let fname= b:netrw_curdir."/".fname
7878 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007879 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7880 let fname= substitute(fname,'/','\\','g')
7881 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>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009479 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009480" 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" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009505" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009506
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009507 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9508" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9509" let newdir = w:netrw_treetop.'/'.potentialdir
9510" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9511" let treedir = s:NetrwTreePath(newdir)
9512" let w:netrw_treetop = newdir
9513" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9514" else
9515" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009516 if a:islocal && curline =~ '@$'
9517 if isdirectory(s:NetrwFile(potentialdir))
9518 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9519 let w:netrw_treetop = treedir
9520 endif
9521 else
9522 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9523 let treedir = s:NetrwTreePath(w:netrw_treetop)
9524 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009525 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009526" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009527
9528 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009529 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009530" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009531" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009532
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009533" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009534 return treedir
9535endfun
9536
9537" ---------------------------------------------------------------------
9538" s:NetrwTreeDisplay: recursive tree display {{{2
9539fun! s:NetrwTreeDisplay(dir,depth)
9540" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9541
9542 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009543 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009544
9545 " install ../ and shortdir
9546 if a:depth == ""
9547 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009548" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009549 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009550 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009551 if a:dir == w:netrw_treetop
9552 let shortdir= a:dir
9553 else
9554 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9555 endif
9556 call setline(line("$")+1,a:depth.shortdir)
9557 else
9558 let shortdir= substitute(a:dir,'^.*/','','e')
9559 call setline(line("$")+1,a:depth.shortdir.'/')
9560 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009561" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009562 " append a / to dir if its missing one
9563 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009564
9565 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009566 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009567" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009568
Bram Moolenaar85850f32019-07-19 22:05:51 +02009569 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9570 if g:netrw_hide == 1
9571 " hide given patterns
9572 let listhide= split(g:netrw_list_hide,',')
9573" call Decho("listhide=".string(listhide))
9574 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009575 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009576 endfor
9577
9578 elseif g:netrw_hide == 2
9579 " show given patterns (only)
9580 let listhide= split(g:netrw_list_hide,',')
9581" call Decho("listhide=".string(listhide))
9582 let entries=[]
9583 for entry in w:netrw_treedict[dir]
9584 for pat in listhide
9585 if entry =~ pat
9586 call add(entries,entry)
9587 break
9588 endif
9589 endfor
9590 endfor
9591 let w:netrw_treedict[dir]= entries
9592 endif
9593 if depth != ""
9594 " always remove "." and ".." entries when there's depth
9595 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9596 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9597 endif
9598
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009599" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009600 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009601 if dir =~ '/$'
9602 let direntry= substitute(dir.entry,'[@/]$','','e')
9603 else
9604 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9605 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009606" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009607 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009608" 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 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009611" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9612 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9613 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9614" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009615 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009616 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009617" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009618 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009619 endif
9620 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009621" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009622
Bram Moolenaar446cb832008-06-24 21:56:24 +00009623" call Dret("NetrwTreeDisplay")
9624endfun
9625
9626" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009627" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9628fun! s:NetrwRefreshTreeDict(dir)
9629" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009630 if !exists("w:netrw_treedict")
9631" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9632 return
9633 endif
9634
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009635 for entry in w:netrw_treedict[a:dir]
9636 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9637" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9638
9639 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9640" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9641 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009642 let liststar = s:NetrwGlob(direntry,'*',1)
9643 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009644 let w:netrw_treedict[direntry] = liststar + listdotstar
9645" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9646
9647 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9648" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9649 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009650 let liststar = s:NetrwGlob(direntry.'/','*',1)
9651 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009652 let w:netrw_treedict[direntry]= liststar + listdotstar
9653" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9654
9655 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9656" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9657 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009658 let liststar = s:NetrwGlob(direntry.'/','*',1)
9659 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009660" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9661
9662 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009663" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009664 endif
9665 endfor
9666" call Dret("s:NetrwRefreshTreeDict")
9667endfun
9668
9669" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009670" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009671" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009672fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009673 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009674" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009675" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9676" 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>"))
9677" 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 +00009678
9679 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009680 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009681" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009682 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009683 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009684" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009685 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 +02009686" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009687 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009688 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009689" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009690 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009691 if exists("w:netrw_treetop")
9692 let s:netrw_treetop= w:netrw_treetop
9693 else
9694 let w:netrw_treetop= getcwd()
9695 let s:netrw_treetop= w:netrw_treetop
9696 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009697
Bram Moolenaar446cb832008-06-24 21:56:24 +00009698 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009699 " insure that we have a treedict, albeit empty
9700" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009701 let w:netrw_treedict= {}
9702 endif
9703
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009704 " update the dictionary for the current directory
9705" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009706" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009707 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009708 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009709" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009710 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009711
9712 " if past banner, record word
9713 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9714 let fname= expand("<cword>")
9715 else
9716 let fname= ""
9717 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009718" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9719" 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 +00009720
9721 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009722" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009723 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009724" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009725
9726 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9727 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009728" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009729 1d
9730 endwhile
9731
Bram Moolenaar13600302014-05-22 18:26:40 +02009732 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009733
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009734" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009735 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009736 endif
9737endfun
9738
9739" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009740" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009741" Normally, treetop is w:netrw_treetop, but a
9742" user of the function ( netrw#SetTreetop() )
9743" wipes that out prior to calling this function
9744fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009745" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9746 if line(".") < w:netrw_bannercnt + 2
9747 let treedir= a:treetop
9748 if treedir !~ '/$'
9749 let treedir= treedir.'/'
9750 endif
9751" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9752 return treedir
9753 endif
9754
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009755 let svpos = winsaveview()
9756" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009757 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009758" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009759 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009760" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9761 let curline= getline('.')
9762" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9763 if curline =~ '/$'
9764" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9765 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9766" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9767 elseif curline =~ '@\s\+-->'
9768" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9769 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9770 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9771" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009772 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009773" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009774 let treedir= ""
9775 endif
9776 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009777" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9778" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009779 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9780 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9781 let treedir= dirname.treedir
9782 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009783" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009784 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009785" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009786 if a:treetop =~ '/$'
9787 let treedir= a:treetop.treedir
9788 else
9789 let treedir= a:treetop.'/'.treedir
9790 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009791" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009792 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009793" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009794" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9795 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009796" call Dret("s:NetrwTreePath <".treedir.">")
9797 return treedir
9798endfun
9799
9800" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009801" s:NetrwWideListing: {{{2
9802fun! s:NetrwWideListing()
9803
9804 if w:netrw_liststyle == s:WIDELIST
9805" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9806 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009807 " cpf: characters per filename
9808 " fpl: filenames per line
9809 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009810 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009811 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009812" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009813 let b:netrw_cpf= 0
9814 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009815 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009816 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9817 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009818 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009819 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009820" call Dret("NetrwWideListing")
9821 return
9822 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009823 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009824 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009825" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009826
9827 " determine qty files per line (fpl)
9828 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9829 if w:netrw_fpl <= 0
9830 let w:netrw_fpl= 1
9831 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009832" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009833
9834 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009835 " fpc: files per column of wide listing
9836 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009837 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009838 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9839 let newcolstart = w:netrw_bannercnt + fpc
9840 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009841" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009842 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009843" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009844 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009845 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009846 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009847 while line("$") >= newcolstart
9848 if newcolend > line("$") | let newcolend= line("$") | endif
9849 let newcolqty= newcolend - newcolstart
9850 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009851 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009852 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009853 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009854 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009855 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009856 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009857 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009858 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009859 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009860 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009861" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009862 if @* != keepregstar | sil! let @* = keepregstar | endif
9863 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009864 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009865 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9866 NetrwKeepj call histdel("/",-1)
9867 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9868 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009869" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009870 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009871 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009872" 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 +00009873" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009874 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009875 else
9876 if hasmapto("w","n")
9877 sil! nunmap <buffer> w
9878 endif
9879 if hasmapto("b","n")
9880 sil! nunmap <buffer> b
9881 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009882 endif
9883
9884endfun
9885
9886" ---------------------------------------------------------------------
9887" s:PerformListing: {{{2
9888fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009889" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9890" 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 +02009891" 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>"))
9892 sil! NetrwKeepj %d _
9893" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009894
Bram Moolenaar15146672011-10-20 22:22:38 +02009895 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009896" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009897 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009898
Bram Moolenaar85850f32019-07-19 22:05:51 +02009899 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009900 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009901" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009902
9903" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009904" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009905" endif " Decho
9906
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009907" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009908 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9909 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009910" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9911 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009912 endif
9913
9914 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009915 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009916
9917 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009918 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009919" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009920 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009921 if exists("g:netrw_pchk")
9922 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9923 " failure detections.
9924 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009925 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009926 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9927 endif
9928 if exists("g:netrw_pchk")
9929 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9930 else
9931 let curdir= b:netrw_curdir
9932 endif
9933 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9934 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9935 else
9936 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009937 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009938 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009939 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009940 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009941" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009942 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009943 let w:netrw_bannercnt= 1
9944 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009945" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9946" 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 +00009947
Bram Moolenaar85850f32019-07-19 22:05:51 +02009948 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009949 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009950 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009951 let sortby= sortby." reversed"
9952 endif
9953
9954 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009955 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009956" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009957 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009958" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009959 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009960 NetrwKeepj put ='\" Sorted by '.sortby
9961 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009962 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9963 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009964" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009965 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009966 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009967 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9968 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009969 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009970" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009971" 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 +00009972 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009973
Bram Moolenaar85850f32019-07-19 22:05:51 +02009974 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009975 if g:netrw_banner
9976 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009977" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009978 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009979 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009980 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009981 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009982 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009983 endif
9984 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009985 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009986" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009987 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009988 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009989 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009990
9991 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009992 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009993" 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 +01009994 if g:netrw_list_hide != "" && g:netrw_hide
9995 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009996 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009997 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009998 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009999 endif
10000 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010001 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010002 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010003
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010004" 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 +010010005 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010006" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010007 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010008" 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 +010010009 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +010010010 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +010010011" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010012" 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 +000010013 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010014
10015 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +010010016 if g:netrw_banner
10017 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010018 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010019" 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 +010010020" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010021" 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 +010010022 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010023
Bram Moolenaar446cb832008-06-24 21:56:24 +000010024 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010025" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010026 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010027 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010028 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010029 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010030 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010031" 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 +010010032" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10033 return
10034 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010035 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010036
10037 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010038 if !exists("w:netrw_bannercnt")
10039 let w:netrw_bannercnt= 0
10040 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010041" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10042" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10043" 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 +010010044
Bram Moolenaar5c736222010-01-06 20:54:52 +010010045 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010046" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010047" 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 +000010048 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010049 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010050 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010051 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010052" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010053
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010054 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010055 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010056" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010057 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010058
Bram Moolenaar5c736222010-01-06 20:54:52 +010010059 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010060" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010061 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010062 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010063 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010064 else
10065 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010066 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010067 endif
10068 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010069
Bram Moolenaar446cb832008-06-24 21:56:24 +000010070 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010071" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010072 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10073 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010074
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010075 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010076 " exten: sort by extension
10077 " The histdel(...,-1) calls remove the last search from the search history
10078" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010079 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10080 NetrwKeepj call histdel("/",-1)
10081 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10082 NetrwKeepj call histdel("/",-1)
10083 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10084 NetrwKeepj call histdel("/",-1)
10085 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10086" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010087 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010088 " normal direction sorting
10089 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10090 else
10091 " reverse direction sorting
10092 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10093 endif
10094 endif
10095 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10096 NetrwKeepj call histdel("/",-1)
10097
Bram Moolenaar446cb832008-06-24 21:56:24 +000010098 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010099 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010100" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010101 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010102" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010103 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010104 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010105" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010106 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010107 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010108" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010109 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10110 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010111 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010112 endif
10113
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010114 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010116 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010117 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010118 call histdel("/",-1)
10119 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010120 endif
10121 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010122" 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 +000010123
10124 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010125" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10126" 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 +010010127 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010128" 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 +010010129 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#3)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010131
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010132 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010133 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010134" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010135 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010136 endif
10137
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010138 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010139 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010140" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10141 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010142 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010143" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10144 else
10145" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10146" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10147" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10148" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010149 endif
10150
10151 " record previous current directory
10152 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010153" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010154
10155 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010156" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10157" 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 +010010158 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010159" 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 +020010160 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010161" 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 +000010162
10163 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010164" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010165 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010166" 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 +010010167 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010168" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010169 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10170 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010171" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010172" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010173
Bram Moolenaar8d043172014-01-23 14:24:41 +010010174 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010175" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10176" 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 +010010177" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10178 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010179 unlet s:treecurpos
10180 endif
10181
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010182" 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>"))
10183" 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 +000010184" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10185endfun
10186
10187" ---------------------------------------------------------------------
10188" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010189fun! s:SetupNetrwStatusLine(statline)
10190" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10191
10192 if !exists("s:netrw_setup_statline")
10193 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010194" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010195
10196 if !exists("s:netrw_users_stl")
10197 let s:netrw_users_stl= &stl
10198 endif
10199 if !exists("s:netrw_users_ls")
10200 let s:netrw_users_ls= &laststatus
10201 endif
10202
10203 " set up User9 highlighting as needed
10204 let keepa= @a
10205 redir @a
10206 try
10207 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010208 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010209 if &bg == "dark"
10210 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10211 else
10212 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10213 endif
10214 endtry
10215 redir END
10216 let @a= keepa
10217 endif
10218
10219 " set up status line (may use User9 highlighting)
10220 " insure that windows have a statusline
10221 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010222 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010223 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010224" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010225 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010226
10227" call Dret("SetupNetrwStatusLine : stl=".&stl)
10228endfun
10229
Bram Moolenaar85850f32019-07-19 22:05:51 +020010230" =========================================
10231" Remote Directory Browsing Support: {{{1
10232" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010233
10234" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010235" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10236" This function assumes that a long listing will be received. Size, time,
10237" and reverse sorts will be requested of the server but not otherwise
10238" enforced here.
10239fun! s:NetrwRemoteFtpCmd(path,listcmd)
10240" 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 +010010241" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010242 " sanity check: {{{3
10243 if !exists("w:netrw_method")
10244 if exists("b:netrw_method")
10245 let w:netrw_method= b:netrw_method
10246 else
10247 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10248" call Dret("NetrwRemoteFtpCmd")
10249 return
10250 endif
10251 endif
10252
10253 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10254 let ffkeep= &ff
10255 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010256" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010257
10258 " clear off any older non-banner lines " {{{3
10259 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010260" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10261 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010262
10263 ".........................................
10264 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10265 " ftp + <.netrc>: Method #2
10266 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010267 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010268 endif
10269 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010270 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010271" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010272 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010273 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010274" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010275 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010276" 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>"))
10277 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 +010010278 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010279" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10280 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 +010010281 endif
10282
10283 ".........................................
10284 elseif w:netrw_method == 3 " {{{3
10285 " ftp + machine,id,passwd,filename: Method #3
10286 setl ff=unix
10287 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010288 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010289 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010290 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010291 endif
10292
10293 " handle userid and password
10294 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010295" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010296 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10297 call NetUserPass("ftp:".host)
10298 endif
10299 if exists("g:netrw_uid") && g:netrw_uid != ""
10300 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010301 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010302 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010303 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010304 endif
10305 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010306 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010307 endif
10308 endif
10309
10310 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010311 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010312 endif
10313 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010314 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010315" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010316 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010317 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010318
10319 " perform ftp:
10320 " -i : turns off interactive prompting from ftp
10321 " -n unix : DON'T use <.netrc>, even though it exists
10322 " -n win32: quit being obnoxious about password
10323 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010324" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010325 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010326" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010327" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10328" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010329 endif
10330
10331 ".........................................
10332 elseif w:netrw_method == 9 " {{{3
10333 " sftp username@machine: Method #9
10334 " s:netrw_sftp_cmd
10335 setl ff=unix
10336
10337 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010338 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010339" call Dret("NetrwRemoteFtpCmd")
10340 return
10341
10342 ".........................................
10343 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010344 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010345 endif
10346
10347 " cleanup for Windows " {{{3
10348 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010349 sil! NetrwKeepj %s/\r$//e
10350 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010351 endif
10352 if a:listcmd == "dir"
10353 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010354 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10355 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10356 NetrwKeepj call histdel("/",-1)
10357 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010358 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 +010010359 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10360 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010361 endif
10362 endif
10363
10364 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10365 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010366 exe 'NetrwKeepj '.w:netrw_bannercnt
10367 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010368 endif
10369 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010370 exe 'NetrwKeepj '.w:netrw_bannercnt
10371 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010372 endif
10373
10374 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010375 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010376" call Dret("NetrwRemoteFtpCmd")
10377endfun
10378
10379" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010380" s:NetrwRemoteListing: {{{2
10381fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010382" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010383
Bram Moolenaara6878372014-03-22 21:02:50 +010010384 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10385 let w:netrw_bannercnt= s:bannercnt
10386 endif
10387 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010388 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010389 endif
10390
Bram Moolenaar446cb832008-06-24 21:56:24 +000010391 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010392
Bram Moolenaar446cb832008-06-24 21:56:24 +000010393 " sanity check:
10394 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010395" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010396 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010397" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010398 if !exists("g:netrw_quiet")
10399 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10400 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010401 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010402" call Dret("s:NetrwRemoteListing -1")
10403 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010404 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010405
Bram Moolenaar8d043172014-01-23 14:24:41 +010010406 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010407" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010408 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010409 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010410 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 +000010411 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010412 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 +000010413 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010414 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010415
Bram Moolenaar85850f32019-07-19 22:05:51 +020010416 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010417" call Dret("s:NetrwRemoteListing -1")
10418 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010419 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010420" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010421
Bram Moolenaar446cb832008-06-24 21:56:24 +000010422 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010423" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010424 let w:netrw_method= b:netrw_method
10425 endif
10426
Bram Moolenaar13600302014-05-22 18:26:40 +020010427 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010428 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010429" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010430 let s:method = "ftp"
10431 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010432 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010433 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010434 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010435 let listcmd= g:netrw_ftp_sizelist_cmd
10436 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010437" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010438 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010439" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010440
Bram Moolenaara6878372014-03-22 21:02:50 +010010441 " report on missing file or directory messages
10442 if search('[Nn]o such file or directory\|Failed to change directory')
10443 let mesg= getline(".")
10444 if exists("w:netrw_bannercnt")
10445 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010446 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010447 setl noma
10448 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010449 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010450 call netrw#ErrorMsg(s:WARNING,mesg,96)
10451" call Dret("s:NetrwRemoteListing : -1")
10452 return -1
10453 endif
10454
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010455 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 +000010456 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010457" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010458 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459
10460 " cleanup
10461 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010462 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10463 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010464 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010465 sil! NetrwKeepj %s/\r$//e
10466 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010467
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010468 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010469 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010470 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010471 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010472" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010473 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010474" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010475 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010476 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010477 exe "sil! NetrwKeepj ".line1
10478 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010481 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010482" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010483 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10484 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010486" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010487 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10488 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10489 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10490 NetrwKeepj call histdel("/",-1)
10491 NetrwKeepj call histdel("/",-1)
10492 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493 endif
10494 endif
10495
Bram Moolenaar13600302014-05-22 18:26:40 +020010496 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010498" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010499 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010500" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010501 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010502" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10503 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010504 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010505 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10506 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10507 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10508 NetrwKeepj call histdel("/",-1)
10509 NetrwKeepj call histdel("/",-1)
10510 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010511 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010512 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10513 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 endif
10515 else
10516 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010517" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010518 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010519 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010520" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10521 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10522" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 endif
10524 endif
10525
10526 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010527 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010528" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010529 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10530 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531 endif
10532 endif
10533
10534 if w:netrw_liststyle == s:LONGLIST
10535 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010536" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010537
10538 if s:method == "ftp"
10539 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010540 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010541 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010542 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010543 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010544 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010545 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010546 sil! NetrwKeepj 1
10547 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010548 let line2= line(".")
10549 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010550 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010551 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010552 endif
10553 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010554 exe "sil! NetrwKeepj ".line1
10555 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010556 endif
10557
10558 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010559" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010560 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 +000010561 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010562" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010563 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010564 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010565 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10566 NetrwKeepj call histdel("/",-1)
10567 NetrwKeepj call histdel("/",-1)
10568 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010569 endif
10570 endif
10571
10572" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010573" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010574" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010575
10576" call Dret("s:NetrwRemoteListing 0")
10577 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010578endfun
10579
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580" ---------------------------------------------------------------------
10581" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10582fun! s:NetrwRemoteRm(usrhost,path) range
10583" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010584" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010585 let svpos= winsaveview()
10586" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010587
10588 let all= 0
10589 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10590 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010591" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010592 for fname in s:netrwmarkfilelist_{bufnr("%")}
10593 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010594 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010595 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010596 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010597 let all= 1
10598 endif
10599 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010600 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601
10602 else
10603 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010604" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010605
10606 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010607 let keepsol = &l:sol
10608 setl nosol
10609 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010610
10611 " remove multiple files and directories
10612 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010613 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010614 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010615 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010616 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010617 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010618 let all= 1
10619 endif
10620 let ctr= ctr + 1
10621 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010622 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010623 endif
10624
10625 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010626" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010627 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010628" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10629 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010630
10631" call Dret("s:NetrwRemoteRm")
10632endfun
10633
10634" ---------------------------------------------------------------------
10635" s:NetrwRemoteRmFile: {{{2
10636fun! s:NetrwRemoteRmFile(path,rmfile,all)
10637" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10638
10639 let all= a:all
10640 let ok = ""
10641
10642 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10643 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010644" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010645 if !all
10646 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010647" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010648 call inputsave()
10649 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10650 call inputrestore()
10651 echohl NONE
10652 if ok == ""
10653 let ok="no"
10654 endif
10655 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010656 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010657 let all= 1
10658 endif
10659 endif
10660
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010661 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010662" 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 +000010663 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010664" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010665 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010666 if path =~ '^\a\{3,}://'
10667 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010668 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010669 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010670 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10671 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010673 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010674" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010676 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010677 let ok="q"
10678 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010679 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010680" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10681" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10682" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010683 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010684 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010685 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010686 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010687 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010688" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010689 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010690 if v:shell_error != 0
10691 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010692 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 +010010693 else
10694 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10695 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010696 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010697 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010698 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010699" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010700 endif
10701 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010702 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010703" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010704 endif
10705
10706 else
10707 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010708" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010709 if !all
10710 call inputsave()
10711 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10712 call inputrestore()
10713 if ok == ""
10714 let ok="no"
10715 endif
10716 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010717 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010718 let all= 1
10719 endif
10720 endif
10721
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010722 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010723 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010724 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010725 else
10726 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010727 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10728" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010729 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010730" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010731
10732 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010733" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10734 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10735" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010736 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010737" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010738
10739 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010740 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010741 endif
10742 endif
10743 endif
10744
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010745 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010746" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010747 endif
10748 endif
10749
10750" call Dret("s:NetrwRemoteRmFile ".ok)
10751 return ok
10752endfun
10753
10754" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010755" s:NetrwRemoteRename: rename a remote file or directory {{{2
10756fun! s:NetrwRemoteRename(usrhost,path) range
10757" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10758
10759 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010760 let svpos = winsaveview()
10761" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010762 let ctr = a:firstline
10763 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10764
10765 " rename files given by the markfilelist
10766 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10767 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010768" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010769 if exists("subfrom")
10770 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010771" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010772 else
10773 call inputsave()
10774 let newname= input("Moving ".oldname." to : ",oldname)
10775 call inputrestore()
10776 if newname =~ '^s/'
10777 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10778 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10779 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010780" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010781 endif
10782 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010783
Bram Moolenaar446cb832008-06-24 21:56:24 +000010784 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010785 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010786 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010787 let oldname= s:ShellEscape(a:path.oldname)
10788 let newname= s:ShellEscape(a:path.newname)
10789" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010790 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010791 endif
10792
10793 endfor
10794 call s:NetrwUnMarkFile(1)
10795
10796 else
10797
10798 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010799 let keepsol= &l:sol
10800 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010801 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010802 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010803
10804 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010805" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010806
10807 call inputsave()
10808 let newname= input("Moving ".oldname." to : ",oldname)
10809 call inputrestore()
10810
10811 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10812 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10813 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010814 let oldname= s:ShellEscape(a:path.oldname)
10815 let newname= s:ShellEscape(a:path.newname)
10816" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010817 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010818 endif
10819
10820 let ctr= ctr + 1
10821 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010822 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010823 endif
10824
10825 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010826 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010827" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10828 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010829
10830" call Dret("NetrwRemoteRename")
10831endfun
10832
Bram Moolenaar85850f32019-07-19 22:05:51 +020010833" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010834" Local Directory Browsing Support: {{{1
10835" ==========================================
10836
10837" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010838" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010839" Should accept: file://localhost/etc/fstab
10840" file:///etc/fstab
10841" file:///c:/WINDOWS/clock.avi
10842" file:///c|/WINDOWS/clock.avi
10843" file://localhost/c:/WINDOWS/clock.avi
10844" file://localhost/c|/WINDOWS/clock.avi
10845" file://c:/foo.txt
10846" file:///c:/foo.txt
10847" 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 +020010848fun! netrw#FileUrlEdit(fname)
10849" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010850 let fname = a:fname
10851 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010852" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010853 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010854" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010855 endif
10856 if (has("win32") || has("win95") || has("win64") || has("win16"))
10857 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010858" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010859 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010860" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010861 endif
10862 endif
10863 let fname2396 = netrw#RFC2396(fname)
10864 let fname2396e= fnameescape(fname2396)
10865 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10866 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010867" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010868 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010869" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010870 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10871 endif
10872 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010873
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010874" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10875" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010876 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010877 exe 'NetrwKeepj keepalt edit '.plainfname
10878 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10879
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010880" 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 +020010881" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010882 exe "sil doau BufReadPost ".fname2396e
10883endfun
10884
10885" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010886" netrw#LocalBrowseCheck: {{{2
10887fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010888 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010889 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10890 "
10891 " unfortunate interaction -- split window debugging can't be used here, must use
10892 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10893 " another call to LocalBrowseCheck() when attempts to write
10894 " to the DBG buffer are made.
10895 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010896 " The &ft == "netrw" test was installed because the BufEnter event
10897 " would hit when re-entering netrw windows, creating unexpected
10898 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010899" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010900" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010901" 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 +010010902 " getting E930: Cannot use :redir inside execute
10903"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010904" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10905" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010906
Bram Moolenaar97d62492012-11-15 21:28:22 +010010907 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010908 if isdirectory(s:NetrwFile(a:dirname))
10909" 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 +010010910
Bram Moolenaar97d62492012-11-15 21:28:22 +010010911 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010912" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10913" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010914 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010915
Bram Moolenaar446cb832008-06-24 21:56:24 +000010916 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010917" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010918 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010919
Bram Moolenaar5c736222010-01-06 20:54:52 +010010920 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010921" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010922 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010923 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010924 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010925" 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 +010010926" call Dret("netrw#LocalBrowseCheck")
10927 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010928 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010929
Bram Moolenaar85850f32019-07-19 22:05:51 +020010930 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010931 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10932 " AND IF the listing style is not a tree listing
10933 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010934" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010935 let ibuf = 1
10936 let buflast = bufnr("$")
10937 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010938 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10939 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010940 endif
10941 let ibuf= ibuf + 1
10942 endwhile
10943 endif
10944 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010945" 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>"))
10946" 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 +000010947 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010948" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010949endfun
10950
10951" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010952" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010953" performed any shell command. The idea is to cause all local-browsing
10954" buffers to be refreshed after a user has executed some shell command,
10955" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010956fun! s:LocalBrowseRefresh()
10957" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010958" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10959" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010960
Bram Moolenaar446cb832008-06-24 21:56:24 +000010961 " determine which buffers currently reside in a tab
10962 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010963" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010964 return
10965 endif
10966 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010967" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010968 return
10969 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010970 if !empty(getcmdwintype())
10971 " cannot move away from cmdline window, see :h E11
10972 return
10973 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010974 if exists("s:netrw_events") && s:netrw_events == 1
10975 " s:LocalFastBrowser gets called (indirectly) from a
10976 let s:netrw_events= 2
10977" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10978 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010979 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010980 let itab = 1
10981 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010982 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010983 while itab <= tabpagenr("$")
10984 let buftablist = buftablist + tabpagebuflist()
10985 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010986 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010987 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010988" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10989" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010990 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10991 " | refresh any netrw window
10992 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010993 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010994 let ibl = 0
10995 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010996" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010997 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10998 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010999 " (ibuf not shown in a current window AND
11000 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011001" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
11002 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011003 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011004" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011005 continue
11006 elseif index(tabpagebuflist(),ibuf) != -1
11007 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011008" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011009 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011010 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010011011 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
11012 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
11013 let g:netrw_quickhelp= g:netrw_quickhelp - 1
11014 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011015" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011016 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
11017 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11018 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011019 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011020 endif
11021 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011022" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011023 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011024" call Decho("restore window: win_gotoid(".curwinid.")")
11025 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011026 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011027
Bram Moolenaara6878372014-03-22 21:02:50 +010011028" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011029endfun
11030
11031" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011032" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11033"
11034" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011035" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011036" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11037" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011038" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011039"
11040" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11041" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011042" (re-using a buffer may not be as accurate)
11043"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011044" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011045" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11046" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11047" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11048" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011049fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011050" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11051" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11052" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11053" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011054
11055 " initialize browselist, a list of buffer numbers that the local browser has used
11056 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011057" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011058 let s:netrw_browselist= []
11059 endif
11060
11061 " append current buffer to fastbrowse list
11062 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011063" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011064 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011065" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011066 endif
11067
11068 " enable autocmd events to handle refreshing/removing local browser buffers
11069 " If local browse buffer is currently showing: refresh it
11070 " If local browse buffer is currently hidden : wipe it
11071 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11072 " =1 : medium speed, re-use directory listing for remote only
11073 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011074 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11075 let s:netrw_events= 1
11076 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011077 au!
11078 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011079" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011080 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011081 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011082" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011083 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011084 endif
11085 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011086
11087 " user must have changed fastbrowse to its fast setting, so remove
11088 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011089 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011090" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011091 unlet s:netrw_events
11092 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011093 au!
11094 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011095 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011096 endif
11097
Bram Moolenaar85850f32019-07-19 22:05:51 +020011098" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011099endfun
11100
11101" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011102" s:LocalListing: does the job of "ls" for local directories {{{2
11103fun! s:LocalListing()
11104" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011105" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11106" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11107" 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 +010011108
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011109" 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
11110" 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
11111" 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 +010011112
11113 " get the list of files contained in the current directory
11114 let dirname = b:netrw_curdir
11115 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011116 let filelist = s:NetrwGlob(dirname,"*",0)
11117 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011118" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011119
11120 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011121" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011122 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11123 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011124" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011125 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011126" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011127 endif
11128
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011129" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011130" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011131" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011132
11133 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11134 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11135 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011136" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11137" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011138 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011139" 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 +010011140
11141 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011142" call Decho(" ",'~'.expand("<slnum>"))
11143" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011144
11145 if getftype(filename) == "link"
11146 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011147" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011148 let pfile= filename."@"
11149
11150 elseif getftype(filename) == "socket"
11151 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011152" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011153 let pfile= filename."="
11154
11155 elseif getftype(filename) == "fifo"
11156 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011157" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011158 let pfile= filename."|"
11159
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011160 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011161 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011162" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011163 let pfile= filename."/"
11164
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011165 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011166 if (has("win32") || has("win95") || has("win64") || has("win16"))
11167 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11168 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011169" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011170 let pfile= filename."*"
11171 else
11172 " normal file
11173 let pfile= filename
11174 endif
11175 elseif executable(filename)
11176 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011177" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011178 let pfile= filename."*"
11179 else
11180 " normal file
11181 let pfile= filename
11182 endif
11183
11184 else
11185 " normal file
11186 let pfile= filename
11187 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011188" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011189
11190 if pfile =~ '//$'
11191 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011192" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011193 endif
11194 let pfile= strpart(pfile,dirnamelen)
11195 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011196" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11197" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011198
11199 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011200 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11201 let sz = getfsize(filename)
11202 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11203 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011204
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011205 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011206 let sz= s:NetrwHumanReadable(sz)
11207 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011208 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011209 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011210" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011211 endif
11212
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011213 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011214 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011215 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011216" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011217" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011218 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011219 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011220" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011221 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011222 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011223
11224 elseif g:netrw_sort_by =~ "^s"
11225 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011226" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011227" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011228 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011229 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011230" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011231 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011232 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011233
11234 else
11235 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011236" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011237" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011238 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011239 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011240" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011241 endfor
11242
11243 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011244 sil! NetrwKeepj g/^$/d
11245 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011246 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011247" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011248 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11249
11250" call Dret("s:LocalListing")
11251endfun
11252
11253" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011254" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11255fun! s:NetrwLocalExecute(cmd)
11256" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11257 let ykeep= @@
11258 " sanity check
11259 if !executable(a:cmd)
11260 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11261 let @@= ykeep
11262" call Dret("s:NetrwLocalExecute")
11263 return
11264 endif
11265
11266 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011267" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011268 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011269" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011270
11271 " strip any ansi escape sequences off
11272 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11273
11274 " show user the result(s)
11275 echomsg result
11276 let @@= ykeep
11277
11278" call Dret("s:NetrwLocalExecute")
11279endfun
11280
11281" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011282" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011283fun! s:NetrwLocalRename(path) range
11284" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11285
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011286 if !exists("w:netrw_bannercnt")
11287 let w:netrw_bannercnt= b:netrw_bannercnt
11288 endif
11289
Bram Moolenaar97d62492012-11-15 21:28:22 +010011290 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011291 let ykeep = @@
11292 let ctr = a:firstline
11293 let svpos = winsaveview()
11294 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011295" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011296
11297 " rename files given by the markfilelist
11298 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11299 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011300" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011301 if exists("subfrom")
11302 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011303" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011304 else
11305 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011306 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011307 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011308 if newname =~ ''
11309 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11310 let newname = substitute(newname,'^.*','','')
11311 elseif newname =~ ''
11312 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11313 let newname = substitute(newname,'[^/]*','','')
11314 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011315 if newname =~ '^s/'
11316 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11317 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011318" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011319 let newname = substitute(oldname,subfrom,subto,'')
11320 endif
11321 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011322 if !all && filereadable(newname)
11323 call inputsave()
11324 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11325 call inputrestore()
11326 if response == "all"
11327 let all= 1
11328 elseif response != "y" && response != "yes"
11329 " refresh the directory
11330" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11331 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11332" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11333 NetrwKeepj call winrestview(svpos)
11334 let @@= ykeep
11335" call Dret("NetrwLocalRename")
11336 return
11337 endif
11338 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011339 call rename(oldname,newname)
11340 endfor
11341 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011342
Bram Moolenaar97d62492012-11-15 21:28:22 +010011343 else
11344
11345 " attempt to rename files/directories
11346 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011347 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011348
11349 " sanity checks
11350 if line(".") < w:netrw_bannercnt
11351 let ctr= ctr + 1
11352 continue
11353 endif
11354 let curword= s:NetrwGetWord()
11355 if curword == "./" || curword == "../"
11356 let ctr= ctr + 1
11357 continue
11358 endif
11359
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011360 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011361 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011362" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011363
11364 call inputsave()
11365 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11366 call inputrestore()
11367
11368 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011369" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011370
11371 let ctr= ctr + 1
11372 endwhile
11373 endif
11374
11375 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011376" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011377 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011378" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11379 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011380 let @@= ykeep
11381
11382" call Dret("NetrwLocalRename")
11383endfun
11384
11385" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011386" s:NetrwLocalRm: {{{2
11387fun! s:NetrwLocalRm(path) range
11388" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011389" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011390
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011391 if !exists("w:netrw_bannercnt")
11392 let w:netrw_bannercnt= b:netrw_bannercnt
11393 endif
11394
Bram Moolenaar446cb832008-06-24 21:56:24 +000011395 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011396 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011397 let ret = 0
11398 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011399 let svpos = winsaveview()
11400" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011401
11402 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11403 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011404" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011405 for fname in s:netrwmarkfilelist_{bufnr("%")}
11406 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011407 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011408 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011409 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011410 let all= 1
11411 endif
11412 endfor
11413 call s:NetrwUnMarkFile(1)
11414
11415 else
11416 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011417" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011418
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011419 let keepsol= &l:sol
11420 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011421 let ctr = a:firstline
11422 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011423 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011424
11425 " sanity checks
11426 if line(".") < w:netrw_bannercnt
11427 let ctr= ctr + 1
11428 continue
11429 endif
11430 let curword= s:NetrwGetWord()
11431 if curword == "./" || curword == "../"
11432 let ctr= ctr + 1
11433 continue
11434 endif
11435 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011436 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011437 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011438 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011439 let all= 1
11440 endif
11441 let ctr= ctr + 1
11442 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011443 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011444 endif
11445
11446 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011447" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011448 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011449 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011450" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11451 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011452 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011453 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011454
11455" call Dret("s:NetrwLocalRm")
11456endfun
11457
11458" ---------------------------------------------------------------------
11459" s:NetrwLocalRmFile: remove file fname given the path {{{2
11460" Give confirmation prompt unless all==1
11461fun! s:NetrwLocalRmFile(path,fname,all)
11462" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011463
Bram Moolenaar446cb832008-06-24 21:56:24 +000011464 let all= a:all
11465 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011466 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011467 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11468" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011469
11470 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11471 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011472" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011473 if !all
11474 echohl Statement
11475 call inputsave()
11476 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11477 call inputrestore()
11478 echohl NONE
11479 if ok == ""
11480 let ok="no"
11481 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011482" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011483 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011484" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011485 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011486 let all= 1
11487 endif
11488 endif
11489
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011490 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011491 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011492" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011493 endif
11494
11495 else
11496 " attempt to remove directory
11497 if !all
11498 echohl Statement
11499 call inputsave()
11500 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11501 call inputrestore()
11502 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11503 if ok == ""
11504 let ok="no"
11505 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011506 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011507 let all= 1
11508 endif
11509 endif
11510 let rmfile= substitute(rmfile,'[\/]$','','e')
11511
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011512 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar71badf92023-04-22 22:40:14 +010011513 if delete(rmfile,"d")
11514 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011515 endif
11516 endif
11517 endif
11518
11519" call Dret("s:NetrwLocalRmFile ".ok)
11520 return ok
11521endfun
11522
Bram Moolenaar85850f32019-07-19 22:05:51 +020011523" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011524" Support Functions: {{{1
11525
Bram Moolenaar488c6512005-08-11 20:09:58 +000011526" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011527" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11528" 0: marked file list of current buffer
11529" 1: marked file target
11530fun! netrw#Access(ilist)
11531 if a:ilist == 0
11532 if exists("s:netrwmarkfilelist_".bufnr('%'))
11533 return s:netrwmarkfilelist_{bufnr('%')}
11534 else
11535 return "no-list-buf#".bufnr('%')
11536 endif
11537 elseif a:ilist == 1
11538 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011539 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011540endfun
11541
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011542" ---------------------------------------------------------------------
11543" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11544fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011545 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011546endfun
11547
Bram Moolenaara6878372014-03-22 21:02:50 +010011548" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011549" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11550" I expect this function to be used in
11551" :PChkAssert netrw#Expose("netrwmarkfilelist")
11552" for example.
11553fun! netrw#Expose(varname)
11554" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011555 if exists("s:".a:varname)
11556 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011557" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011558 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011559" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011560 if type(retval) == 3
11561 let retval = copy(retval)
11562 let i = 0
11563 while i < len(retval)
11564 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11565 let i = i + 1
11566 endwhile
11567 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011568" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011569 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011570 else
11571" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011572 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011573 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011574" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011575 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011576 endif
11577
11578" call Dret("netrw#Expose ".string(retval))
11579 return retval
11580endfun
11581
11582" ---------------------------------------------------------------------
11583" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11584fun! netrw#Modify(varname,newvalue)
11585" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11586 exe "let s:".a:varname."= ".string(a:newvalue)
11587" call Dret("netrw#Modify")
11588endfun
11589
11590" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011591" netrw#RFC2396: converts %xx into characters {{{2
11592fun! netrw#RFC2396(fname)
11593" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011594 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011595" call Dret("netrw#RFC2396 ".fname)
11596 return fname
11597endfun
11598
11599" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011600" netrw#UserMaps: supports user-specified maps {{{2
11601" see :help function()
11602"
11603" g:Netrw_UserMaps is a List with members such as:
11604" [[keymap sequence, function reference],...]
11605"
11606" The referenced function may return a string,
11607" refresh : refresh the display
11608" -other- : this string will be executed
11609" or it may return a List of strings.
11610"
11611" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011612" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011613" Related functions:
11614" netrw#Expose(varname) -- see s:varname variables
11615" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11616" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11617fun! netrw#UserMaps(islocal)
11618" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11619" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11620
11621 " set up usermaplist
11622 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11623" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11624 for umap in g:Netrw_UserMaps
11625" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11626" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11627 " if umap[0] is a string and umap[1] is a string holding a function name
11628 if type(umap[0]) == 1 && type(umap[1]) == 1
11629" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11630 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11631 else
11632 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11633 endif
11634 endfor
11635 endif
11636" call Dret("netrw#UserMaps")
11637endfun
11638
11639" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011640" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11641fun! netrw#WinPath(path)
11642" call Dfunc("netrw#WinPath(path<".a:path.">)")
11643 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11644 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011645 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011646 " remove trailing slash (Win95)
11647 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11648 " remove escaped spaces
11649 let path = substitute(path, '\ ', ' ', 'g')
11650 " convert slashes to backslashes
11651 let path = substitute(path, '/', '\', 'g')
11652 else
11653 let path= a:path
11654 endif
11655" call Dret("netrw#WinPath <".path.">")
11656 return path
11657endfun
11658
11659" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011660" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11661" cb : bl2mf=0 add marked files to buffer list
11662" cB : bl2mf=1 use bufferlist to mark files
11663" (mnemonic: cb = copy (marked files) to buffer list)
11664fun! s:NetrwBadd(islocal,bl2mf)
11665" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11666 if a:bl2mf
11667 " cB: add buffer list to marked files
11668 redir => bufl
11669 ls
11670 redir END
11671 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11672 for fname in bufl
11673 call s:NetrwMarkFile(a:islocal,fname)
11674 endfor
11675 else
11676 " cb: add marked files to buffer list
11677 for fname in s:netrwmarkfilelist_{bufnr("%")}
11678" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11679 exe "badd ".fnameescape(fname)
11680 endfor
11681 let curbufnr = bufnr("%")
11682 let curdir = s:NetrwGetCurdir(a:islocal)
11683 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11684 endif
11685" call Dret("s:NetrwBadd")
11686endfun
11687
11688" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011689" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11690fun! s:ComposePath(base,subdir)
11691" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11692
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011693 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011694" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011695 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011696 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011697 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011698 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011699 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011700 endif
11701
Bram Moolenaar85850f32019-07-19 22:05:51 +020011702 " COMBAK: test on windows with changing to root directory: :e C:/
11703 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011704" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011705 let ret= a:subdir
11706
Bram Moolenaar85850f32019-07-19 22:05:51 +020011707 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011708" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011709 if a:base =~ '[/\\]$'
11710 let ret= a:base.a:subdir
11711 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011712 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011713 endif
11714
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011715 elseif a:base =~ '^\a\{3,}://'
11716" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011717 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11718 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11719 if a:subdir == '../'
11720 if curpath =~ '[^/]/[^/]\+/$'
11721 let curpath= substitute(curpath,'[^/]\+/$','','')
11722 else
11723 let curpath=""
11724 endif
11725 let ret= urlbase.curpath
11726 else
11727 let ret= urlbase.curpath.a:subdir
11728 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011729" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11730" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11731" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011732
11733 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011734" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011735 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11736 if a:base =~ '^//'
11737 " keeping initial '//' for the benefit of network share listing support
11738 let ret= '/'.ret
11739 endif
11740 let ret= simplify(ret)
11741 endif
11742
11743" call Dret("s:ComposePath ".ret)
11744 return ret
11745endfun
11746
11747" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011748" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11749" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11750fun! s:DeleteBookmark(fname)
11751" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11752 call s:MergeBookmarks()
11753
11754 if exists("g:netrw_bookmarklist")
11755 let indx= index(g:netrw_bookmarklist,a:fname)
11756 if indx == -1
11757 let indx= 0
11758 while indx < len(g:netrw_bookmarklist)
11759 if g:netrw_bookmarklist[indx] =~ a:fname
11760 call remove(g:netrw_bookmarklist,indx)
11761 let indx= indx - 1
11762 endif
11763 let indx= indx + 1
11764 endwhile
11765 else
11766 " remove exact match
11767 call remove(g:netrw_bookmarklist,indx)
11768 endif
11769 endif
11770
11771" call Dret("s:DeleteBookmark")
11772endfun
11773
11774" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011775" s:FileReadable: o/s independent filereadable {{{2
11776fun! s:FileReadable(fname)
11777" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11778
11779 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011780 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011781 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011782 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011783 endif
11784
11785" call Dret("s:FileReadable ".ret)
11786 return ret
11787endfun
11788
11789" ---------------------------------------------------------------------
11790" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11791" Places correct suffix on end of temporary filename,
11792" using the suffix provided with fname
11793fun! s:GetTempfile(fname)
11794" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11795
11796 if !exists("b:netrw_tmpfile")
11797 " get a brand new temporary filename
11798 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011799" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011800
Bram Moolenaarc236c162008-07-13 17:41:49 +000011801 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011802" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011803
Bram Moolenaar9964e462007-05-05 17:54:07 +000011804 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011805 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11806" 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 +010011807 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011808" call Dret("s:GetTempfile getcwd<".getcwd().">")
11809 return ""
11810 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011811
Bram Moolenaar9964e462007-05-05 17:54:07 +000011812 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011813 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011814" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011815
Bram Moolenaar9964e462007-05-05 17:54:07 +000011816 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011817 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011818 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011819 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011820 if !exists("+shellslash") || !&ssl
11821 let tmpfile = substitute(tmpfile,'/','\','g')
11822 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011823 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011824 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011825 endif
11826 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011827" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011828 else
11829 " re-use temporary filename
11830 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011831" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011832 endif
11833
11834 " use fname's suffix for the temporary file
11835 if a:fname != ""
11836 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011837" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011838 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011839 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011840 elseif a:fname =~ '.txz$'
11841 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011842 else
11843 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11844 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011845" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011846 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011847" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011848 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011849" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011850 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11851 endif
11852 endif
11853
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011854" 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 +000011855" call Dret("s:GetTempfile <".tmpfile.">")
11856 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011857endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011858
11859" ---------------------------------------------------------------------
11860" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011861" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011862fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011863" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011864 if s:user == ""
11865 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11866 else
11867 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11868 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011869 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011870 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011871 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011872 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011873 else
11874 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11875 endif
11876" call Dret("s:MakeSshCmd <".sshcmd.">")
11877 return sshcmd
11878endfun
11879
11880" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011881" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11882fun! s:MakeBookmark(fname)
11883" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11884
11885 if !exists("g:netrw_bookmarklist")
11886 let g:netrw_bookmarklist= []
11887 endif
11888
11889 if index(g:netrw_bookmarklist,a:fname) == -1
11890 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011891 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011892 call add(g:netrw_bookmarklist,a:fname.'/')
11893 elseif a:fname !~ '/'
11894 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11895 else
11896 call add(g:netrw_bookmarklist,a:fname)
11897 endif
11898 call sort(g:netrw_bookmarklist)
11899 endif
11900
11901" call Dret("s:MakeBookmark")
11902endfun
11903
11904" ---------------------------------------------------------------------
11905" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11906fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011907" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011908 " get bookmarks from .netrwbook file
11909 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011910 if filereadable(s:NetrwFile(savefile))
11911" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011912 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011913" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011914 NetrwKeepj call delete(savefile)
11915 endif
11916" call Dret("s:MergeBookmarks")
11917endfun
11918
11919" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011920" s:NetrwBMShow: {{{2
11921fun! s:NetrwBMShow()
11922" call Dfunc("s:NetrwBMShow()")
11923 redir => bmshowraw
11924 menu
11925 redir END
11926 let bmshowlist = split(bmshowraw,'\n')
11927 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011928 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011929 if bmshowfuncs != []
11930 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011931 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011932 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011933 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011934 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011935 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011936" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11937endfun
11938
11939" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011940" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011941fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011942 if !exists("w:netrw_liststyle")
11943 let w:netrw_liststyle= g:netrw_liststyle
11944 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011945" 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 +020011946
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011947" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11948
Bram Moolenaaradc21822011-04-01 18:03:16 +020011949 if &ft != "netrw"
11950 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11951 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011952" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011953
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011954 elseif g:netrw_cursor == 8
11955 if w:netrw_liststyle == s:WIDELIST
11956 setl cursorline
11957 setl cursorcolumn
11958 else
11959 setl cursorline
11960 endif
11961 elseif g:netrw_cursor == 7
11962 setl cursorline
11963 elseif g:netrw_cursor == 6
11964 if w:netrw_liststyle == s:WIDELIST
11965 setl cursorline
11966 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011967 elseif g:netrw_cursor == 4
11968 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011969" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011970 setl cursorline
11971 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011972
11973 elseif g:netrw_cursor == 3
11974 " thin-long-tree: cursorline, user's cursorcolumn
11975 " wide : cursorline, cursorcolumn
11976 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011977" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011978 setl cursorline
11979 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011980 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011981" 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 +020011982 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011983 endif
11984
11985 elseif g:netrw_cursor == 2
11986 " thin-long-tree: cursorline, user's cursorcolumn
11987 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011988" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011989 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011990
11991 elseif g:netrw_cursor == 1
11992 " thin-long-tree: user's cursorline, user's cursorcolumn
11993 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011994 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011995" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011996 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011997 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011998" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011999 endif
12000
12001 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020012002 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012003" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012004 let &l:cursorline = s:netrw_usercul
12005 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012006 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020012007
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012008" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020012009" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012010endfun
12011
12012" ---------------------------------------------------------------------
12013" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
12014fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012015" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012016 if exists("s:netrw_usercul")
12017 let &l:cursorline = s:netrw_usercul
12018 endif
12019 if exists("s:netrw_usercuc")
12020 let &l:cursorcolumn = s:netrw_usercuc
12021 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012022" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012023" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12024endfun
12025
12026" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012027" s:NetrwDelete: Deletes a file. {{{2
12028" Uses Steve Hall's idea to insure that Windows paths stay
12029" acceptable. No effect on Unix paths.
12030" Examples of use: let result= s:NetrwDelete(path)
12031fun! s:NetrwDelete(path)
12032" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12033
Bram Moolenaar5c736222010-01-06 20:54:52 +010012034 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012035 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
12036 if exists("+shellslash")
12037 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012038 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012039 let result = delete(path)
12040 let &shellslash = sskeep
12041 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012042" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012043 let result= delete(path)
12044 endif
12045 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012046" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012047 let result= delete(path)
12048 endif
12049 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012050 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012051 endif
12052
12053" call Dret("s:NetrwDelete ".result)
12054 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012055endfun
12056
12057" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012058" s:NetrwBufRemover: removes a buffer that: {{{2s
12059" has buffer-id > 1
12060" is unlisted
12061" is unnamed
12062" does not appear in any window
12063fun! s:NetrwBufRemover(bufid)
12064" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12065" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12066" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12067" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12068" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12069
yasuda4dbb2662023-10-04 20:50:35 +020012070 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012071" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012072 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012073 endif
12074
12075" call Dret("s:NetrwBufRemover")
12076endfun
12077
12078" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012079" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012080fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012081" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012082" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012083
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012084 " Clean out the last buffer:
12085 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12086 " If so, delete it.
12087 call s:NetrwBufRemover(bufnr("$"))
12088
Bram Moolenaar446cb832008-06-24 21:56:24 +000012089 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012090" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012091 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12092 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12093 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12094 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12095 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12096 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12097 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12098 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12099 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12100 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12101 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12102 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12103 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12104 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12105 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12106 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12107
Bram Moolenaar85850f32019-07-19 22:05:51 +020012108 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012109" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012110 " when tree listing uses file TreeListing... a new buffer is made.
12111 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012112 " COMBAK: this causes a problem, see P43
12113" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012114 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012115 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012116 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012117" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012118 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012119
Bram Moolenaar446cb832008-06-24 21:56:24 +000012120 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012121" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012122 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12123 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12124 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12125 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12126 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12127 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12128 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12129 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12130 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12131 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12132 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12133 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12134 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12135 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12136 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12137 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12138
Bram Moolenaar5c736222010-01-06 20:54:52 +010012139 if a:0 > 0
12140 let b:netrw_curdir= a:1
12141 if b:netrw_curdir =~ '/$'
12142 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012143 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012144 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012145 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012146 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12147 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012148 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012149 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012150 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012151 endif
12152 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012153 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12154 let &l:bexpr = "netrw#BalloonHelp()"
12155 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012156
Bram Moolenaar8d043172014-01-23 14:24:41 +010012157" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012158endfun
12159
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012160" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012161" s:NetrwExe: executes a string using "!" {{{2
12162fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012163" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012164 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012165" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012166 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12167 set shell& shellcmdflag& shellxquote& shellxescape&
12168 set shellquote& shellpipe& shellredir& shellslash&
12169 exe a:cmd
12170 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12171 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012172" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012173 exe a:cmd
12174 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012175 if v:shell_error
12176 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12177 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012178" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012179endfun
12180
12181" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012182" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12183fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012184 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012185" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012186 let curbuf = bufnr("%")
12187 let curwin = winnr()
12188 let iwin = 1
12189 while iwin <= winnr("$")
12190 exe iwin."wincmd w"
12191 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12192 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12193 let winvars= w:
12194 break
12195 endif
12196 let iwin= iwin + 1
12197 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012198 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012199 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012200" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012201 for k in keys(winvars)
12202 let w:{k}= winvars[k]
12203 endfor
12204 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012205" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012206 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012207endfun
12208
Bram Moolenaara6878372014-03-22 21:02:50 +010012209" ---------------------------------------------------------------------
12210" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012211" Returns: 0=success
12212" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012213fun! s:NetrwLcd(newdir)
12214" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012215" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012216
Bram Moolenaar85850f32019-07-19 22:05:51 +020012217 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012218 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012219 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012220 catch /^Vim\%((\a\+)\)\=:E344/
12221 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12222 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012223 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012224 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12225 " forward slashes by earlier code; so check for both.
12226 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
12227 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12228 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012229 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012230 endif
12231 endif
12232 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012233 let err472= 1
12234 endtry
12235
12236 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012237 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12238 if exists("w:netrw_prvdir")
12239 let a:newdir= w:netrw_prvdir
12240 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012241 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012242" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012243 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012244" 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 +010012245 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012246 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012247" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12248 return -1
12249 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012250
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012251" call Decho("getcwd <".getcwd().">")
12252" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012253" call Dret("s:NetrwLcd 0")
12254 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012255endfun
12256
Bram Moolenaar9964e462007-05-05 17:54:07 +000012257" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012258" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12259" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12260fun! s:NetrwSaveWordPosn()
12261" call Dfunc("NetrwSaveWordPosn()")
12262 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12263" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12264endfun
12265
12266" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012267" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12268" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12269fun! s:NetrwHumanReadable(sz)
12270" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12271
12272 if g:netrw_sizestyle == 'h'
12273 if a:sz >= 1000000000
12274 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12275 elseif a:sz >= 10000000
12276 let sz = printf("%d",a:sz/1000000)."m"
12277 elseif a:sz >= 1000000
12278 let sz = printf("%.1f",a:sz/1000000.0)."m"
12279 elseif a:sz >= 10000
12280 let sz = printf("%d",a:sz/1000)."k"
12281 elseif a:sz >= 1000
12282 let sz = printf("%.1f",a:sz/1000.0)."k"
12283 else
12284 let sz= a:sz
12285 endif
12286
12287 elseif g:netrw_sizestyle == 'H'
12288 if a:sz >= 1073741824
12289 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12290 elseif a:sz >= 10485760
12291 let sz = printf("%d",a:sz/1048576)."M"
12292 elseif a:sz >= 1048576
12293 let sz = printf("%.1f",a:sz/1048576.0)."M"
12294 elseif a:sz >= 10240
12295 let sz = printf("%d",a:sz/1024)."K"
12296 elseif a:sz >= 1024
12297 let sz = printf("%.1f",a:sz/1024.0)."K"
12298 else
12299 let sz= a:sz
12300 endif
12301
12302 else
12303 let sz= a:sz
12304 endif
12305
12306" call Dret("s:NetrwHumanReadable ".sz)
12307 return sz
12308endfun
12309
12310" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012311" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12312" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12313fun! s:NetrwRestoreWordPosn()
12314" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012315 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012316" call Dret("NetrwRestoreWordPosn")
12317endfun
12318
12319" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012320" s:RestoreBufVars: {{{2
12321fun! s:RestoreBufVars()
12322" call Dfunc("s:RestoreBufVars()")
12323
12324 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12325 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12326 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12327 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12328 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12329 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12330
12331" call Dret("s:RestoreBufVars")
12332endfun
12333
12334" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012335" s:RemotePathAnalysis: {{{2
12336fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012337" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012338
Bram Moolenaara6878372014-03-22 21:02:50 +010012339 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012340 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012341 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012342 let s:user = substitute(a:dirname,dirpat,'\3','')
12343 let s:machine = substitute(a:dirname,dirpat,'\4','')
12344 let s:port = substitute(a:dirname,dirpat,'\5','')
12345 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012346 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012347 if s:machine =~ '@'
12348 let dirpat = '^\(.*\)@\(.\{-}\)$'
12349 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12350 let s:machine = substitute(s:machine,dirpat,'\2','')
12351 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012352
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012353" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12354" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12355" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12356" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12357" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12358" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012359
12360" call Dret("s:RemotePathAnalysis")
12361endfun
12362
12363" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012364" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12365" Returns status
12366" Runs system() on
12367" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012368" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012369fun! s:RemoteSystem(cmd)
12370" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12371 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012372 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 +000012373 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012374 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012375 else
12376 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12377 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12378 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012379 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012380 else
12381 let cmd= cmd.' '
12382 endif
12383 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012384" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012385 let ret= system(cmd)
12386 endif
12387" call Dret("s:RemoteSystem ".ret)
12388 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012389endfun
12390
12391" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012392" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012393fun! s:RestoreWinVars()
12394" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012395 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012396 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12397 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12398 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12399 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12400 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12401 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12402 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12403 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12404 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12405 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12406 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12407 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012408 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12409 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012410 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12411 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12412 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12413" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012414endfun
12415
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012416" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012417" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12418"
12419" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12420" is true) and a command, :Rexplore, which call this function.
12421"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012422" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012423"
12424" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012425fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012426 if exists("s:netrwdrag")
12427 return
12428 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012429" 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 +010012430" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12431" 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 +010012432
12433 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012434 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012435" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012436 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012437 unlet w:netrw_rexfile
12438" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012439 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012440" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012441" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12442" 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 +020012443 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012444
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012445 " ---------------------------
12446 " :Rex issued while in a file
12447 " ---------------------------
12448
Bram Moolenaara6878372014-03-22 21:02:50 +010012449 " record current file so :Rex can return to it from netrw
12450 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012451" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012452
12453 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012454" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012455 return
12456 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012457" 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 +020012458 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012459 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012460 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012461 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012462 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012463 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012464 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012465 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012466 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012467" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12468 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012469" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12470 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012471 if exists("s:rexposn_".bufnr('%'))
12472 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012473 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012474 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012475" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012476 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012477
Bram Moolenaar85850f32019-07-19 22:05:51 +020012478 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12479 if exists("s:explore_match")
12480 exe "2match netrwMarkFile /".s:explore_match."/"
12481 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012482 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012483
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012484" 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 +010012485" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012486endfun
12487
12488" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012489" s:SaveBufVars: save selected b: variables to s: variables {{{2
12490" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012491fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012492" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012493
12494 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12495 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12496 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12497 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12498 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12499 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12500
12501" call Dret("s:SaveBufVars")
12502endfun
12503
12504" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012505" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12506fun! s:SavePosn(posndict)
12507" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12508
Bram Moolenaar85850f32019-07-19 22:05:51 +020012509 if !exists("a:posndict[bufnr('%')]")
12510 let a:posndict[bufnr("%")]= []
12511 endif
12512" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12513 call add(a:posndict[bufnr("%")],winsaveview())
12514" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012515
12516" call Dret("s:SavePosn posndict")
12517 return a:posndict
12518endfun
12519
12520" ---------------------------------------------------------------------
12521" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12522fun! s:RestorePosn(posndict)
12523" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012524 if exists("a:posndict")
12525 if has_key(a:posndict,bufnr("%"))
12526" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12527 let posnlen= len(a:posndict[bufnr("%")])
12528 if posnlen > 0
12529 let posnlen= posnlen - 1
12530" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12531 call winrestview(a:posndict[bufnr("%")][posnlen])
12532 call remove(a:posndict[bufnr("%")],posnlen)
12533" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12534 endif
12535 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012536 endif
12537" call Dret("s:RestorePosn")
12538endfun
12539
12540" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012541" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012542fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012543" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012544 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12545 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12546 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12547 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12548 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12549 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12550 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12551 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12552 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12553 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12554 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12555 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12556 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12557 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12558 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12559 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12560 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12561 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12562" call Dret("s:SaveWinVars")
12563endfun
12564
12565" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012566" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012567" To allow separate windows to have their own activities, such as
12568" Explore **/pattern, several variables have been made window-oriented.
12569" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012570" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012571" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012572fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012573" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012574 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12575 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12576 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12577 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12578 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12579 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12580 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12581 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12582 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12583 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12584" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012585endfun
12586
12587" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012588" s:SetRexDir: set directory for :Rexplore {{{2
12589fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012590" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012591 let w:netrw_rexdir = a:dirname
12592 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012593 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012594" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12595" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012596" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012597" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012598" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012599endfun
12600
12601" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012602" s:ShowLink: used to modify thin and tree listings to show links {{{2
12603fun! s:ShowLink()
12604" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012605" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12606" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012607 if exists("b:netrw_curdir")
12608 norm! $?\a
12609 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12610 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012611" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12612" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12613" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12614 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012615 let dirlen = strlen(b:netrw_curdir)
12616 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012617" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012618 endif
12619 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012620" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12621" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012622 setl noro ma
12623 call setline(".",modline)
12624 setl ro noma nomod
12625 endif
12626" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12627endfun
12628
12629" ---------------------------------------------------------------------
12630" s:ShowStyle: {{{2
12631fun! s:ShowStyle()
12632 if !exists("w:netrw_liststyle")
12633 let liststyle= g:netrw_liststyle
12634 else
12635 let liststyle= w:netrw_liststyle
12636 endif
12637 if liststyle == s:THINLIST
12638 return s:THINLIST.":thin"
12639 elseif liststyle == s:LONGLIST
12640 return s:LONGLIST.":long"
12641 elseif liststyle == s:WIDELIST
12642 return s:WIDELIST.":wide"
12643 elseif liststyle == s:TREELIST
12644 return s:TREELIST.":tree"
12645 else
12646 return 'n/a'
12647 endif
12648endfun
12649
12650" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012651" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12652" Solution from Nicolai Weibull, vim docs (:help strlen()),
12653" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012654fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012655" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12656
12657 if v:version >= 703 && exists("*strdisplaywidth")
12658 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012659
Bram Moolenaar8d043172014-01-23 14:24:41 +010012660 elseif type(g:Align_xstrlen) == 1
12661 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12662 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012663
Bram Moolenaar8d043172014-01-23 14:24:41 +010012664 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012665 " number of codepoints (Latin a + combining circumflex is two codepoints)
12666 " (comment from TM, solution from NW)
12667 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012668
Bram Moolenaar8d043172014-01-23 14:24:41 +010012669 elseif g:Align_xstrlen == 2
12670 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012671 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12672 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012673 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012674
Bram Moolenaar8d043172014-01-23 14:24:41 +010012675 elseif g:Align_xstrlen == 3
12676 " virtual length (counting, for instance, tabs as anything between 1 and
12677 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012678 " preceded by lam, one otherwise, etc.)
12679 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012680 let modkeep= &l:mod
12681 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012682 call setline(line("."),a:x)
12683 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012684 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012685 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012686 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012687
Bram Moolenaar446cb832008-06-24 21:56:24 +000012688 else
12689 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012690 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012691 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012692" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012693 return ret
12694endfun
12695
12696" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012697" s:ShellEscape: shellescape(), or special windows handling {{{2
12698fun! s:ShellEscape(s, ...)
12699 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12700 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12701 endif
12702 let f = a:0 > 0 ? a:1 : 0
12703 return shellescape(a:s, f)
12704endfun
12705
12706" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012707" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012708fun! s:TreeListMove(dir)
12709" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012710 let curline = getline('.')
12711 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12712 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12713 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12714 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12715 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12716 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12717" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12718" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12719" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12720" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12721" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12722 " COMBAK : need to handle when on a directory
12723 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012724 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012725 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012726 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012727 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012728" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012729 elseif a:dir == '[]' && nxtline != ''
12730 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012731" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012732 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12733 if nl != 0
12734 NetrwKeepj norm! k
12735 else
12736 NetrwKeepj norm! G
12737 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012738" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012739 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012740 endif
12741
12742" call Dret("s:TreeListMove")
12743endfun
12744
12745" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012746" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12747" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12748" can't be called except via emenu. But due to locale, that menu line may not be called
12749" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12750fun! s:UpdateBuffersMenu()
12751" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012752 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012753 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012754 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012755 catch /^Vim\%((\a\+)\)\=:E/
12756 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012757 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012758 endtry
12759 endif
12760" call Dret("s:UpdateBuffersMenu")
12761endfun
12762
12763" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012764" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012765" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012766fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012767" call Dfunc("s:UseBufWinVars()")
12768 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012769 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12770 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12771 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12772 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12773 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12774 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12775 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12776 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12777 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 +000012778" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012779endfun
12780
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012781" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012782" s:UserMaps: supports user-defined UserMaps {{{2
12783" * calls a user-supplied funcref(islocal,curdir)
12784" * interprets result
12785" See netrw#UserMaps()
12786fun! s:UserMaps(islocal,funcname)
12787" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12788
12789 if !exists("b:netrw_curdir")
12790 let b:netrw_curdir= getcwd()
12791 endif
12792 let Funcref = function(a:funcname)
12793 let result = Funcref(a:islocal)
12794
12795 if type(result) == 1
12796 " if result from user's funcref is a string...
12797" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12798 if result == "refresh"
12799" call Decho("refreshing display",'~'.expand("<slnum>"))
12800 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12801 elseif result != ""
12802" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12803 exe result
12804 endif
12805
12806 elseif type(result) == 3
12807 " if result from user's funcref is a List...
12808" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12809 for action in result
12810 if action == "refresh"
12811" call Decho("refreshing display",'~'.expand("<slnum>"))
12812 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12813 elseif action != ""
12814" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12815 exe action
12816 endif
12817 endfor
12818 endif
12819
12820" call Dret("s:UserMaps")
12821endfun
12822
Bram Moolenaar85850f32019-07-19 22:05:51 +020012823" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012824" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012825" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012826let &cpo= s:keepcpo
12827unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012828
Bram Moolenaar85850f32019-07-19 22:05:51 +020012829" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012830" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012831" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012832" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012833" doing autoload/netrw.vim version v172g ~57
12834" varname<g:netrw_dirhistcnt> value=0 ~1
12835" varname<s:THINLIST> value=0 ~1
12836" varname<s:LONGLIST> value=1 ~1
12837" varname<s:WIDELIST> value=2 ~1
12838" varname<s:TREELIST> value=3 ~1
12839" varname<s:MAXLIST> value=4 ~1
12840" varname<g:netrw_use_errorwindow> value=2 ~1
12841" varname<g:netrw_http_xcmd> value=-q -O ~1
12842" varname<g:netrw_http_put_cmd> value=curl -T ~1
12843" varname<g:netrw_keepj> value=keepj ~1
12844" varname<g:netrw_rcp_cmd> value=rcp ~1
12845" varname<g:netrw_rsync_cmd> value=rsync ~1
12846" varname<g:netrw_rsync_sep> value=/ ~1
12847" varname<g:netrw_scp_cmd> value=scp -q ~1
12848" varname<g:netrw_sftp_cmd> value=sftp ~1
12849" varname<g:netrw_ssh_cmd> value=ssh ~1
12850" varname<g:netrw_alto> value=0 ~1
12851" varname<g:netrw_altv> value=1 ~1
12852" varname<g:netrw_banner> value=1 ~1
12853" varname<g:netrw_browse_split> value=0 ~1
12854" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12855" varname<g:netrw_chgwin> value=-1 ~1
12856" varname<g:netrw_clipboard> value=1 ~1
12857" varname<g:netrw_compress> value=gzip ~1
12858" varname<g:netrw_ctags> value=ctags ~1
12859" varname<g:netrw_cursor> value=2 ~1
12860" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12861" varname<g:netrw_cygdrive> value=/cygdrive ~1
12862" varname<s:didstarstar> value=0 ~1
12863" varname<g:netrw_dirhistcnt> value=0 ~1
12864" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12865" varname<g:netrw_dirhistmax> value=10 ~1
12866" varname<g:netrw_errorlvl> value=0 ~1
12867" varname<g:netrw_fastbrowse> value=1 ~1
12868" 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
12869" varname<g:netrw_ftpmode> value=binary ~1
12870" varname<g:netrw_hide> value=1 ~1
12871" varname<g:netrw_keepdir> value=1 ~1
12872" varname<g:netrw_list_hide> value= ~1
12873" varname<g:netrw_localmkdir> value=mkdir ~1
12874" varname<g:netrw_remote_mkdir> value=mkdir ~1
12875" varname<g:netrw_liststyle> value=0 ~1
12876" varname<g:netrw_markfileesc> value=*./[\~ ~1
12877" varname<g:netrw_maxfilenamelen> value=32 ~1
12878" varname<g:netrw_menu> value=1 ~1
12879" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12880" varname<g:netrw_mousemaps> value=1 ~1
12881" varname<g:netrw_retmap> value=0 ~1
12882" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12883" varname<g:netrw_preview> value=0 ~1