blob: 768954edaf72670e3190976c6326e9afb1bcf02a [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01003" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00004" Version: 173a
5" Last Change:
6" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09007" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Bram Moolenaar29634562020-01-09 21:46:04 +01008" Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM>
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00009" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000011" Permission is hereby granted to use and distribute this code,
12" with or without modifications, provided that this copyright
13" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000014" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000015" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000016" expressed or implied. By using this plugin, you agree that
17" in no event will the copyright holder be liable for any damages
18" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010019"
20" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
21" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
22"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020023"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000024"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000025" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000026" (James 1:22 RSV)
27" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000028" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000029if &cp || exists("g:loaded_netrw")
30 finish
31endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020032
33" Check that vim has patches that netrw requires.
34" Patches needed for v7.4: 1557, and 213.
35" (netrw will benefit from vim's having patch#656, too)
36let s:needspatches=[1557,213]
37if exists("s:needspatches")
38 for ptch in s:needspatches
39 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
40 if !exists("s:needpatch{ptch}")
41 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
42 endif
43 let s:needpatch{ptch}= 1
44 finish
45 endif
46 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020047endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020048
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010049let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000050if !exists("s:NOTE")
51 let s:NOTE = 0
52 let s:WARNING = 1
53 let s:ERROR = 2
54endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000055
Bram Moolenaar1afcace2005-11-25 19:54:28 +000056let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010057setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020058"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010059"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010060"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000061
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000062" ======================
63" Netrw Variables: {{{1
64" ======================
65
Bram Moolenaar071d4272004-06-13 20:20:40 +000066" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020067" netrw#ErrorMsg: {{{2
68" 0=note = s:NOTE
69" 1=warning = s:WARNING
70" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010071" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
72" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
73" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010074" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020075fun! netrw#ErrorMsg(level,msg,errnum)
76" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
77
78 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020079" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020080 return
81 endif
82
83 if a:level == 1
84 let level= "**warning** (netrw) "
85 elseif a:level == 2
86 let level= "**error** (netrw) "
87 else
88 let level= "**note** (netrw) "
89 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010090" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020091
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020092 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
93 " use popup window
94 if type(a:msg) == 3
95 let msg = [level]+a:msg
96 else
97 let msg= level.a:msg
98 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020099 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200100 let s:popuperr_text= ""
101 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200102 " (default) netrw creates a one-line window to show error/warning
103 " messages (reliably displayed)
104
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100105 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200106 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100107" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200108
109 " getting messages out reliably is just plain difficult!
110 " This attempt splits the current window, creating a one line window.
111 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100112" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200113 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100114" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200115 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100116 if type(a:msg) == 3
117 for msg in a:msg
118 NetrwKeepj call setline(line("$")+1,level.msg)
119 endfor
120 else
121 NetrwKeepj call setline(line("$")+1,level.a:msg)
122 endif
123 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200124 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100125" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200126 bo 1split
127 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200128 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200129 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100130 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100131" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200132 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100133 if type(a:msg) == 3
134 for msg in a:msg
135 NetrwKeepj call setline(line("$")+1,level.msg)
136 endfor
137 else
138 NetrwKeepj call setline(line("$"),level.a:msg)
139 endif
140 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200141 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100142" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200143 if &fo !~ '[ta]'
144 syn clear
145 syn match netrwMesgNote "^\*\*note\*\*"
146 syn match netrwMesgWarning "^\*\*warning\*\*"
147 syn match netrwMesgError "^\*\*error\*\*"
148 hi link netrwMesgWarning WarningMsg
149 hi link netrwMesgError Error
150 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100151" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200152 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200153
154 else
155 " (optional) netrw will show messages using echomsg. Even if the
156 " message doesn't appear, at least it'll be recallable via :messages
157" redraw!
158 if a:level == s:WARNING
159 echohl WarningMsg
160 elseif a:level == s:ERROR
161 echohl Error
162 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100163
164 if type(a:msg) == 3
165 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100166 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100167 endfor
168 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100169 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100170 endif
171
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100172" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200173 echohl None
174 endif
175
176" call Dret("netrw#ErrorMsg")
177endfun
178
179" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100180" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100181" Loosely, varname = value.
182fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100183" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100184 if !exists(a:varname)
185 if type(a:value) == 0
186 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200187 elseif type(a:value) == 1 && a:value =~ '^[{[]'
188 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100189 elseif type(a:value) == 1
190 exe "let ".a:varname."="."'".a:value."'"
191 else
192 exe "let ".a:varname."=".a:value
193 endif
194 endif
195endfun
196
197" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000198" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200199call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000200if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100201 call s:NetrwInit("s:THINLIST",0)
202 call s:NetrwInit("s:LONGLIST",1)
203 call s:NetrwInit("s:WIDELIST",2)
204 call s:NetrwInit("s:TREELIST",3)
205 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000206endif
207
208" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200209" Default option values: {{{2
210let g:netrw_localcopycmdopt = ""
211let g:netrw_localcopydircmdopt = ""
212let g:netrw_localmkdiropt = ""
213let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200214
215" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000216" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200217if (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")
218 call s:NetrwInit("g:netrw_use_errorwindow",2)
219else
220 call s:NetrwInit("g:netrw_use_errorwindow",1)
221endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200222
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000223if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100224 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000225 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100226 elseif executable("curl")
227 let g:netrw_dav_cmd = "curl"
228 else
229 let g:netrw_dav_cmd = ""
230 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000231endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000232if !exists("g:netrw_fetch_cmd")
233 if executable("fetch")
234 let g:netrw_fetch_cmd = "fetch -o"
235 else
236 let g:netrw_fetch_cmd = ""
237 endif
238endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100239if !exists("g:netrw_file_cmd")
240 if executable("elinks")
241 call s:NetrwInit("g:netrw_file_cmd","elinks")
242 elseif executable("links")
243 call s:NetrwInit("g:netrw_file_cmd","links")
244 endif
245endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000246if !exists("g:netrw_ftp_cmd")
247 let g:netrw_ftp_cmd = "ftp"
248endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200249let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200250if !exists("g:netrw_ftp_options")
251 let g:netrw_ftp_options= "-i -n"
252endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000253if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100254 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100255 let g:netrw_http_cmd = "wget"
256 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100257 elseif executable("curl")
258 let g:netrw_http_cmd = "curl"
259 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200260 elseif executable("elinks")
261 let g:netrw_http_cmd = "elinks"
262 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000263 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100264 let g:netrw_http_cmd = "fetch"
265 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200266 elseif executable("links")
267 let g:netrw_http_cmd = "links"
268 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000269 else
270 let g:netrw_http_cmd = ""
271 endif
272endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100273call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100274call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100275call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
276call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200277call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200278if !exists("g:netrw_scp_cmd")
279 if executable("scp")
280 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
281 elseif executable("pscp")
282 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
283 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
284 else
285 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
286 endif
287 else
288 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
289 endif
290endif
291
Bram Moolenaar5c736222010-01-06 20:54:52 +0100292call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
293call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000294
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000295if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000296 \ && exists("g:netrw_use_nt_rcp")
297 \ && g:netrw_use_nt_rcp
298 \ && executable( $SystemRoot .'/system32/rcp.exe')
299 let s:netrw_has_nt_rcp = 1
300 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000301else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000302 let s:netrw_has_nt_rcp = 0
303 let s:netrw_rcpmode = ''
304endif
305
306" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000307" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000308" Cygwin Detection ------- {{{3
309if !exists("g:netrw_cygwin")
310 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100311 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000312 let g:netrw_cygwin= 1
313 else
314 let g:netrw_cygwin= 0
315 endif
316 else
317 let g:netrw_cygwin= 0
318 endif
319endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000320" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100321call s:NetrwInit("g:netrw_alto" , &sb)
322call s:NetrwInit("g:netrw_altv" , &spr)
323call s:NetrwInit("g:netrw_banner" , 1)
324call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200325call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100326call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200327call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100328call s:NetrwInit("g:netrw_compress" , "gzip")
329call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200330if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
331 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
332 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000333endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200334call s:NetrwInit("g:netrw_cursor" , 2)
335let s:netrw_usercul = &cursorline
336let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200337"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100338call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000339" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200340call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200341call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200342call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100343call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200344call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100345call s:NetrwInit("g:netrw_fastbrowse" , 1)
346call 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 +0000347if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000348 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
349 let g:netrw_ftp_list_cmd = "ls -lF"
350 let g:netrw_ftp_timelist_cmd = "ls -tlF"
351 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000352 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000353 let g:netrw_ftp_list_cmd = "dir"
354 let g:netrw_ftp_timelist_cmd = "dir"
355 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000356 endif
357endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100358call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000359" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100360call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000361if !exists("g:netrw_ignorenetrc")
362 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
363 let g:netrw_ignorenetrc= 1
364 else
365 let g:netrw_ignorenetrc= 0
366 endif
367endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100368call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000369if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000370 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000371 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200372 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000373 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
374 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100375 if exists("g:netrw_list_cmd_options")
376 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
377 else
378 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
379 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000380 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200381 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100382 if exists("g:netrw_list_cmd_options")
383 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
384 else
385 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
386 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000387 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100388" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000389 let g:netrw_list_cmd= ""
390 endif
391endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100392call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000393" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200394if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200395 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200396 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
397endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100398if !exists("g:netrw_localcmdshell")
399 let g:netrw_localcmdshell= ""
400endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000401if !exists("g:netrw_localcopycmd")
402 if has("win32") || has("win95") || has("win64") || has("win16")
403 if g:netrw_cygwin
404 let g:netrw_localcopycmd= "cp"
405 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000406 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200407 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000408 endif
409 elseif has("unix") || has("macunix")
410 let g:netrw_localcopycmd= "cp"
411 else
412 let g:netrw_localcopycmd= ""
413 endif
414endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100415if !exists("g:netrw_localcopydircmd")
416 if has("win32") || has("win95") || has("win64") || has("win16")
417 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200418 let g:netrw_localcopydircmd = "cp"
419 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100420 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000421 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200422 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100423 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200424 elseif has("unix")
425 let g:netrw_localcopydircmd = "cp"
426 let g:netrw_localcopydircmdopt= " -R"
427 elseif has("macunix")
428 let g:netrw_localcopydircmd = "cp"
429 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100430 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200431 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100432 endif
433endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200434if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100435 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200436 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
437endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200438if has("win32") || has("win95") || has("win64") || has("win16")
439 if g:netrw_cygwin
440 call s:NetrwInit("g:netrw_localmkdir","mkdir")
441 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000442 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200443 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200444 endif
445else
446 call s:NetrwInit("g:netrw_localmkdir","mkdir")
447endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200448call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200449if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200450 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200451 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
452endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000453if !exists("g:netrw_localmovecmd")
454 if has("win32") || has("win95") || has("win64") || has("win16")
455 if g:netrw_cygwin
456 let g:netrw_localmovecmd= "mv"
457 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000458 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200459 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000460 endif
461 elseif has("unix") || has("macunix")
462 let g:netrw_localmovecmd= "mv"
463 else
464 let g:netrw_localmovecmd= ""
465 endif
466endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100467" following serves as an example for how to insert a version&patch specific test
468"if v:version < 704 || (v:version == 704 && !has("patch1107"))
469"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100470call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
471" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000472if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000473 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000474endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000475if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000476 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
477endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000478" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100479call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
480call s:NetrwInit("g:netrw_maxfilenamelen", 32)
481call s:NetrwInit("g:netrw_menu" , 1)
482call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200483call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100484call s:NetrwInit("g:netrw_retmap" , 0)
485if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
486 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
487elseif has("win32") || has("win95") || has("win64") || has("win16")
488 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
489else
490 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000491endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100492call s:NetrwInit("g:netrw_preview" , 0)
493call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100494call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100495call s:NetrwInit("g:netrw_sshport" , "-p")
496call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
497call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
498call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100499call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
500" Default values - q-s ---------- {{{3
501call s:NetrwInit("g:netrw_quickhelp",0)
502let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100503 \ "(create new) %:file d:directory",
504 \ "(windows split&open) o:horz v:vert p:preview",
505 \ "i:style qf:file info O:obtain r:reverse",
506 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
507 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
508 \ "(history) qb:list u:go up U:go down",
509 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100510" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
511call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100512if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
513 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
514else
515 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
516endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100517call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
518call s:NetrwInit("g:netrw_sort_options" , "")
519call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000520if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100521 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200522 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100523 else
524 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000525 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000526endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100527call s:NetrwInit("g:netrw_special_syntax" , 0)
528call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200529call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100530call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100531call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000532" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100533call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200534if !exists("g:netrw_xstrlen")
535 if exists("g:Align_xstrlen")
536 let g:netrw_xstrlen= g:Align_xstrlen
537 elseif exists("g:drawit_xstrlen")
538 let g:netrw_xstrlen= g:drawit_xstrlen
539 elseif &enc == "latin1" || !has("multi_byte")
540 let g:netrw_xstrlen= 0
541 else
542 let g:netrw_xstrlen= 1
543 endif
544endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100545call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100546call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200547call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100548call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200549if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000550" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000551" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100552call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200553if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200554 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200555else
Bram Moolenaarff034192013-04-24 18:51:19 +0200556 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200557endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200558call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100559call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
560call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100561if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100562 let s:treedepthstring= "│ "
563else
564 let s:treedepthstring= "| "
565endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200566call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000567
568" BufEnter event ignored by decho when following variable is true
569" Has a side effect that doau BufReadPost doesn't work, so
570" files read by network transfer aren't appropriately highlighted.
571"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572
Bram Moolenaaradc21822011-04-01 18:03:16 +0200573" ======================
574" Netrw Initialization: {{{1
575" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200576if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100577" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100578 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200579" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100580 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100581 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
582 au VimEnter * let s:initbeval= &beval
583"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100584" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
585" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
586" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
587" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
588" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
589" if exists("g:syntax_on") | call Decho("did not install beval events: g:syntax_on exists","~".expand("<slnum>")) | endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200590endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200591au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200592
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200593if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100594 com! -nargs=* NetrwKeepj keepj <args>
595else
596 let g:netrw_keepj= ""
597 com! -nargs=* NetrwKeepj <args>
598endif
599
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000600" ==============================
601" Netrw Utility Functions: {{{1
602" ==============================
603
Bram Moolenaaradc21822011-04-01 18:03:16 +0200604" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100605" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100606if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100607" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100608 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100609 if &ft != "netrw"
610 return ""
611 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200612 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
613 " popup error window is still showing
614 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
615 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
616 " text under mouse hasn't changed; only close window when it changes
617 call popup_close(s:popuperr_id)
618 unlet s:popuperr_text
619 else
620 let s:popuperr_text= v:beval_text
621 endif
622 let mesg= ""
623 elseif !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
Bram Moolenaar8d043172014-01-23 14:24:41 +0100624 let mesg= ""
625 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
626 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
627 elseif getline(v:beval_lnum) =~ '^"\s*/'
628 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
629 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100630 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100631 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
632 let mesg = "S: edit sorting sequence"
633 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
634 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
635 elseif v:beval_text == "Quick" || v:beval_text == "Help"
636 let mesg = "Help: press <F1>"
637 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
638 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
639 else
640 let mesg= ""
641 endif
642 return mesg
643 endfun
644"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100645" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
646" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
647" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
648" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
649" if exists("g:netrw_nobeval") |call Decho("did not load netrw#BalloonHelp(): g:netrw_nobeval exists","~".expand("<slnum>")) |endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200650endif
651
Bram Moolenaar071d4272004-06-13 20:20:40 +0000652" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200653" netrw#Explore: launch the local browser in the directory of the current file {{{2
654" indx: == -1: Nexplore
655" == -2: Pexplore
656" == +: this is overloaded:
657" * If Nexplore/Pexplore is in use, then this refers to the
658" indx'th item in the w:netrw_explore_list[] of items which
659" matched the */pattern **/pattern *//pattern **//pattern
660" * If Hexplore or Vexplore, then this will override
661" g:netrw_winsize to specify the qty of rows or columns the
662" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100663" dosplit==0: the window will be split iff the current file has been modified and hidden not set
Bram Moolenaarff034192013-04-24 18:51:19 +0200664" dosplit==1: the window will be split before running the local browser
665" style == 0: Explore style == 1: Explore!
666" == 2: Hexplore style == 3: Hexplore!
667" == 4: Vexplore style == 5: Vexplore!
668" == 6: Texplore
669fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100670" call Dfunc("netrw#Explore(indx=".a:indx." dosplit=".a:dosplit." style=".a:style.",a:1<".a:1.">) &modified=".&modified." modifiable=".&modifiable." a:0=".a:0." win#".winnr()." buf#".bufnr("%")." ft=".&ft)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100671" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200672 if !exists("b:netrw_curdir")
673 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100674" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200675 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100676
677 " record current file for Rexplore's benefit
678 if &ft != "netrw"
679 let w:netrw_rexfile= expand("%:p")
680 endif
681
682 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200683 let curdir = simplify(b:netrw_curdir)
684 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200685 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
686 let curdir= substitute(curdir,'\','/','g')
687 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100688" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100689
690 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
691 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
692 " try Explore again.
693 if a:0 > 0
694" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100695 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
696 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
697 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
698 \ '~'.expand("<slnum>"))
699 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
700" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100701 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
702" call Dret("netrw#Explore : returning from retry")
703 return
704" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100705" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100706 endif
707 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200708
709 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200710 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100711" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100712 sil! let keepregstar = @*
713 sil! let keepregplus = @+
714 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200715 sil! let keepregslash= @/
716
Bram Moolenaar8d043172014-01-23 14:24:41 +0100717 " if dosplit
718 " -or- file has been modified AND file not hidden when abandoned
719 " -or- Texplore used
720 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100721" call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200722 call s:SaveWinVars()
723 let winsz= g:netrw_winsize
724 if a:indx > 0
725 let winsz= a:indx
726 endif
727
728 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100729" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200730 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200731 if winsz == 0|let winsz= ""|endif
732 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100733" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200734
735 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100736" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200737 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200738 if winsz == 0|let winsz= ""|endif
739 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100740" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200741
742 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100743" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200744 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200745 if winsz == 0|let winsz= ""|endif
746 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100747" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200748
749 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100750" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200751 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200752 if winsz == 0|let winsz= ""|endif
753 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100754" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200755
756 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100757" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200758 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200759 if winsz == 0|let winsz= ""|endif
760 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100761" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200762
763 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100764" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200765 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200766 if winsz == 0|let winsz= ""|endif
767 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100768" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200769
770 elseif a:style == 6 " Texplore
771 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100772" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200773 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100774" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 call s:RestoreBufVars()
776 endif
777 call s:RestoreWinVars()
778" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100779" call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200780 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100781 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200782
783 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
792 if dirname !~ '/$'
793 let dirname= dirname."/"
794 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200800 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100803" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100805" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200806 let dirname= a:1
807 endif
808 else
809 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100810" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200811 call s:NetrwClearExplore()
812" call Dret("netrw#Explore : cleared list")
813 return
814 endif
815
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100816" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200817 if dirname =~ '\.\./\=$'
818 let dirname= simplify(fnamemodify(dirname,':p:h'))
819 elseif dirname =~ '\.\.' || dirname == '.'
820 let dirname= simplify(fnamemodify(dirname,':p'))
821 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100822" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200823
824 if dirname =~ '^\*//'
825 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100826" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200827 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
828 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100829" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200830 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
831
832 elseif dirname =~ '^\*\*//'
833 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100834" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200835 let pattern= substitute(dirname,'^\*\*//','','')
836 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100837" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200838
839 elseif dirname =~ '/\*\*/'
840 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100841" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200842 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
843 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
844 let b:netrw_curdir = prefixdir
845 else
846 let b:netrw_curdir= getcwd().'/'.prefixdir
847 endif
848 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
849 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100850" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
851" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200852
853 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200854 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200855 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100856" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200857
858 elseif dirname=~ '^\*\*/'
859 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
860 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100861" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200862
863 else
864 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100865" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200866 endif
867
868 if starpat == 0 && a:indx >= 0
869 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100870" call Decho("case starpat==0 && a:indx=".a:indx.": dirname<".dirname.">, handles Explore Hexplore Vexplore Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200871 if dirname == ""
872 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100873" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200874 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200875 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200876 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200877 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200878 if dirname == ""
879 let dirname= getcwd()
880 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100881 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100882 " depending on whether backslashes have been converted to forward slashes by earlier code).
883 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200884 let dirname= b:netrw_curdir."/".dirname
885 endif
886 elseif dirname !~ '^/'
887 let dirname= b:netrw_curdir."/".dirname
888 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100889" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200890 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100891" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
892" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200893 endif
894 if exists("w:netrw_bannercnt")
895 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
896 " If one wants to return the same place in the netrw window, use :Rex instead.
897 exe w:netrw_bannercnt
898 endif
899
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100900" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200901 " ---------------------------------------------------------------------
902 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
903" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100904" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200905" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100906" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200907" endif
908 " ---------------------------------------------------------------------
909
910 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
911 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
912 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
913 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
914 elseif a:indx <= 0
915 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100916" call Decho("case a:indx<=0: Nexplore, Pexplore, <s-down>, <s-up> starpat=".starpat." a:indx=".a:indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200917 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100918" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200919 let s:didstarstar= 1
920 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
921 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
922 endif
923
924 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100925" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200926 if !exists("w:netrw_explore_indx")
927 let w:netrw_explore_indx= 0
928 endif
929
930 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100931" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200932
933 if indx == -1
934 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100935" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200936 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100937 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200938 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100939" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100940 if @* != keepregstar | sil! let @* = keepregstar | endif
941 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100942 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200943 sil! let @/ = keepregslash
944" call Dret("netrw#Explore")
945 return
946 endif
947 let indx= w:netrw_explore_indx
948 if indx < 0 | let indx= 0 | endif
949 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
950 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100951" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200952 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
953 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100954" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200955 endwhile
956 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100957" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200958
959 elseif indx == -2
960 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100961" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200962 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100963 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200964 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100965" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100966 if @* != keepregstar | sil! let @* = keepregstar | endif
967 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100968 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200969 sil! let @/ = keepregslash
970" call Dret("netrw#Explore")
971 return
972 endif
973 let indx= w:netrw_explore_indx
974 if indx < 0 | let indx= 0 | endif
975 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
976 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100977" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200978 while indx >= 0 && curfile == w:netrw_explore_list[indx]
979 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100980" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200981 endwhile
982 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100983" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200984
985 else
986 " Explore -- initialize
987 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100988" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100989 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200990 let w:netrw_explore_indx= 0
991 if !exists("b:netrw_curdir")
992 let b:netrw_curdir= getcwd()
993 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100994" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200995
996 " switch on starpat to build the w:netrw_explore_list of files
997 if starpat == 1
998 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100999" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
1000" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001001 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001002 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001003 catch /^Vim\%((\a\+)\)\=:E480/
1004 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1005" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1006 return
1007 endtry
1008 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1009 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1010
1011 elseif starpat == 2
1012 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001013" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1014" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001015 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001016 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001017 catch /^Vim\%((\a\+)\)\=:E480/
1018 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1019 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001020 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001021" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001022 if @* != keepregstar | sil! let @* = keepregstar | endif
1023 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001024 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001025 sil! let @/ = keepregslash
1026" call Dret("netrw#Explore : no files matched pattern")
1027 return
1028 endtry
1029 let s:netrw_curdir = b:netrw_curdir
1030 let w:netrw_explore_list = getqflist()
1031 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1032 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1033
1034 elseif starpat == 3
1035 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001036" call Decho("..case starpat=".starpat.": build */filepat list (curdir-only srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001037 let filepat= substitute(dirname,'^\*/','','')
1038 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001039" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1040" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001041 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1042 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1043
1044 elseif starpat == 4
1045 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001046" call Decho("..case starpat=".starpat.": build **/filepat list (recursive descent srch filenames matching filepat) &hls=".&hls,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001047 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1048 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1049 endif " switch on starpat to build w:netrw_explore_list
1050
1051 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001052" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1053" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001054
1055 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001056 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001057 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001058" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001059 if @* != keepregstar | sil! let @* = keepregstar | endif
1060 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001061 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001062 sil! let @/ = keepregslash
1063" call Dret("netrw#Explore : no files matched")
1064 return
1065 endif
1066 endif " if indx ... endif
1067
1068 " NetrwStatusLine support - for exploring support
1069 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001070" call Decho("....w:netrw_explore_list<".join(w:netrw_explore_list,',')."> len=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001071
1072 " wrap the indx around, but issue a note
1073 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001074" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1076 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001077 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001078 endif
1079
1080 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001081" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001082 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001083" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001084
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001085" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001086 call netrw#LocalBrowseCheck(newdir)
1087 if !exists("w:netrw_liststyle")
1088 let w:netrw_liststyle= g:netrw_liststyle
1089 endif
1090 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001091 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001092 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001093 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001094 endif
1095 let w:netrw_explore_mtchcnt = indx + 1
1096 let w:netrw_explore_bufnr = bufnr("%")
1097 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001098 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001099" call Decho("....explore: mtchcnt=".w:netrw_explore_mtchcnt." bufnr=".w:netrw_explore_bufnr." line#".w:netrw_explore_line,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001100
1101 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001102" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001103 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001104 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your vim needs the +path_extra feature for Exploring with **!",44)
Bram Moolenaarff034192013-04-24 18:51:19 +02001105 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001106 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001107" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001108 if @* != keepregstar | sil! let @* = keepregstar | endif
1109 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001110 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001111 sil! let @/ = keepregslash
1112" call Dret("netrw#Explore : missing +path_extra")
1113 return
1114 endif
1115
1116 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001117" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001118 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1119 sil! unlet w:netrw_treedict
1120 sil! unlet w:netrw_treetop
1121 endif
1122 let newdir= dirname
1123 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001124 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001125 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001126 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001127 endif
1128 endif
1129
1130 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001131" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1132" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001133 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001134" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001135 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001136 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001137" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001138 let s:explore_prvdir = b:netrw_curdir
1139 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001140 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001141 if b:netrw_curdir !~ '/$'
1142 let dirlen= dirlen + 1
1143 endif
1144 let prvfname= ""
1145 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001146" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001147 if fname =~ '^'.b:netrw_curdir
1148 if s:explore_match == ""
1149 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1150 else
1151 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1152 endif
1153 elseif fname !~ '^/' && fname != prvfname
1154 if s:explore_match == ""
1155 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1156 else
1157 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1158 endif
1159 endif
1160 let prvfname= fname
1161 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001162" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001163 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1164 exe "2match netrwMarkFile /".s:explore_match."/"
1165 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001166 endif
1167 echo "<s-up>==Pexplore <s-down>==Nexplore"
1168 else
1169 2match none
1170 if exists("s:explore_match") | unlet s:explore_match | endif
1171 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001172" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001173 endif
1174
Bram Moolenaara6878372014-03-22 21:02:50 +01001175 " since Explore may be used to initialize netrw's browser,
1176 " there's no danger of a late FocusGained event on initialization.
1177 " Consequently, set s:netrw_events to 2.
1178 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001179 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001180" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001181 if @* != keepregstar | sil! let @* = keepregstar | endif
1182 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001183 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001184 sil! let @/ = keepregslash
1185" call Dret("netrw#Explore : @/<".@/.">")
1186endfun
1187
1188" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001189" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001190" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1191" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1192" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1193" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1194" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001196" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001197 let curwin= winnr()
1198
Bram Moolenaara6878372014-03-22 21:02:50 +01001199 if a:0 > 0 && a:1 != ""
1200 " if a netrw window is already on the left-side of the tab
1201 " and a directory has been specified, explore with that
1202 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001203" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001204 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001205" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001206 exe "1wincmd w"
1207 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001208" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 exe "Explore ".fnameescape(a1)
1210 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001211 let s:lexplore_win= curwin
1212 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001213 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001214" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001215 unlet t:netrw_lexposn
1216 endif
1217" call Dret("netrw#Lexplore")
1218 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001219 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001220 exe curwin."wincmd w"
1221 else
1222 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001223" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001224 endif
1225
Bram Moolenaar8d043172014-01-23 14:24:41 +01001226 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001228 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001229" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001230 else
1231 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001232" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001233 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001234" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001235
1236 if lexwinnr > 0
1237 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001238" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001239 exe lexwinnr."wincmd w"
1240 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001241 let t:netrw_lexposn = winsaveview()
1242" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001243" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001244 close
1245 if lexwinnr < curwin
1246 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001247 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001248 if lexwinnr != curwin
1249 exe curwin."wincmd w"
1250 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001251 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001252" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001253
1254 else
1255 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001256" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001257 exe "1wincmd w"
1258 let keep_altv = g:netrw_altv
1259 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001260 if a:count != 0
1261 let netrw_winsize = g:netrw_winsize
1262 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001263 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001264 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001265" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001267" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001269" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001270 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001271 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001272 elseif curfile =~ '^\a\{3,}://'
1273" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001274 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001275 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001276" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001277 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001278 endif
1279 if a:count != 0
1280 let g:netrw_winsize = netrw_winsize
1281 endif
1282 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001283 let g:netrw_altv = keep_altv
1284 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001285 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1286 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001287 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001288 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001289" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1290" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001291 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001292" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001293" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1294 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001295 unlet t:netrw_lexposn
1296 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001297 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001298
1299 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001300 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001301 if a:rightside
1302 let g:netrw_chgwin= 1
1303 else
1304 let g:netrw_chgwin= 2
1305 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001306" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001307 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001308
Bram Moolenaar8d043172014-01-23 14:24:41 +01001309" call Dret("netrw#Lexplore")
1310endfun
1311
1312" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001313" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001314" supports :NetrwClean -- remove netrw from first directory on runtimepath
1315" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001316fun! netrw#Clean(sys)
1317" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001318
1319 if a:sys
1320 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1321 else
1322 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1323 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001324" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001325 let diddel= 0
1326 let diddir= ""
1327
1328 if choice == 1
1329 for dir in split(&rtp,',')
1330 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001331" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001332 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1333 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1334 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1335 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1336 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1337 if s:NetrwDelete(dir."/syntax/netrwlist.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrwlist.vim",55) |endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00001338 let diddir= dir
1339 let diddel= diddel + 1
1340 if !a:sys|break|endif
1341 endif
1342 endfor
1343 endif
1344
1345 echohl WarningMsg
1346 if diddel == 0
1347 echomsg "netrw is either not installed or not removable"
1348 elseif diddel == 1
1349 echomsg "removed one copy of netrw from <".diddir.">"
1350 else
1351 echomsg "removed ".diddel." copies of netrw"
1352 endif
1353 echohl None
1354
Bram Moolenaara6878372014-03-22 21:02:50 +01001355" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001356endfun
1357
Bram Moolenaar5c736222010-01-06 20:54:52 +01001358" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001359" netrw#MakeTgt: make a target out of the directory name provided {{{2
1360fun! netrw#MakeTgt(dname)
1361" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1362 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001363 let svpos = winsaveview()
1364" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001365 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1366" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001367 if s:netrwmftgt_islocal
1368 let netrwmftgt= simplify(a:dname)
1369 else
1370 let netrwmftgt= a:dname
1371 endif
1372 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1373 " re-selected target, so just clear it
1374 unlet s:netrwmftgt s:netrwmftgt_islocal
1375 else
1376 let s:netrwmftgt= netrwmftgt
1377 endif
1378 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001379 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001380 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001381" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1382 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001383" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001384endfun
1385
Bram Moolenaara6878372014-03-22 21:02:50 +01001386" ---------------------------------------------------------------------
1387" netrw#Obtain: {{{2
1388" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001389" islocal=0 obtain from remote source
1390" =1 obtain from local source
1391" fname : a filename or a list of filenames
1392" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001393fun! netrw#Obtain(islocal,fname,...)
1394" call Dfunc("netrw#Obtain(islocal=".a:islocal." fname<".((type(a:fname) == 1)? a:fname : string(a:fname)).">) a:0=".a:0)
Bram Moolenaarff034192013-04-24 18:51:19 +02001395 " NetrwStatusLine support - for obtaining support
1396
1397 if type(a:fname) == 1
1398 let fnamelist= [ a:fname ]
1399 elseif type(a:fname) == 3
1400 let fnamelist= a:fname
1401 else
1402 call netrw#ErrorMsg(s:ERROR,"attempting to use NetrwObtain on something not a filename or a list",62)
Bram Moolenaara6878372014-03-22 21:02:50 +01001403" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001404 return
1405 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001406" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001407 if a:0 > 0
1408 let tgtdir= a:1
1409 else
1410 let tgtdir= getcwd()
1411 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001412" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001413
1414 if exists("b:netrw_islocal") && b:netrw_islocal
1415 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001416" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001417 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1418 let topath= s:ComposePath(tgtdir,"")
1419 if (has("win32") || has("win95") || has("win64") || has("win16"))
1420 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001421" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001422 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001423" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001424 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001425 if v:shell_error != 0
1426 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001427" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001428 return
1429 endif
1430 endfor
1431 else
1432 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001433" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1434 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1435" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001436 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001437 if v:shell_error != 0
1438 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localcopycmd<".g:netrw_localcopycmd."> to something that works",80)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001439" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001440 return
1441 endif
1442 endif
1443 elseif !exists("b:netrw_curdir")
1444 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1445 else
1446 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1447 endif
1448
1449 else
1450 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001451" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001452 if type(a:fname) == 1
1453 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1454 endif
1455 call s:NetrwMethod(b:netrw_curdir)
1456
1457 if b:netrw_method == 4
1458 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001459" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001460 if exists("g:netrw_port") && g:netrw_port != ""
1461 let useport= " ".g:netrw_scpport." ".g:netrw_port
1462 else
1463 let useport= ""
1464 endif
1465 if b:netrw_fname =~ '/'
1466 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1467 else
1468 let path= ""
1469 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001470 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001471 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".filelist." ".s:ShellEscape(tgtdir,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001472
1473 elseif b:netrw_method == 2
1474 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001475" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001476 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001477 let tmpbufnr= bufnr("%")
1478 setl ff=unix
1479 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001480 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001481" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001482 endif
1483
1484 if exists("b:netrw_fname") && b:netrw_fname != ""
1485 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001486" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001487 endif
1488
1489 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001490 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001491" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001492 endif
1493 for fname in fnamelist
1494 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001495" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001496 endfor
1497 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001498 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001499 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001500 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001501 endif
1502 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1503 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1504 let debugkeep= &debug
1505 setl debug=msg
1506 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1507 let &debug= debugkeep
1508 endif
1509
1510 elseif b:netrw_method == 3
1511 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001512" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001513 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001514 let tmpbufnr= bufnr("%")
1515 setl ff=unix
1516
1517 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001518 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001519" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001520 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001521 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001522" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 endif
1524
1525 if exists("g:netrw_uid") && g:netrw_uid != ""
1526 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001527 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001528" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001529 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001530 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001531 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001532" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001533 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001534 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001535" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001536 endif
1537 endif
1538
1539 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001540 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001541" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001542 endif
1543
1544 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001545 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001546" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001547 endif
1548
1549 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001550 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001551" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001552 endif
1553
1554 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001555 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001556" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001557 endif
1558 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001559 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001560 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001561" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001562
1563 " perform ftp:
1564 " -i : turns off interactive prompting from ftp
1565 " -n unix : DON'T use <.netrc>, even though it exists
1566 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001567 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1568 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001569 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001570 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1571 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001572" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001573 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001574 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001575 endif
1576 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001577
1578 elseif b:netrw_method == 9
1579 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001580" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001581 if a:fname =~ '/'
1582 let localfile= substitute(a:fname,'^.*/','','')
1583 else
1584 let localfile= a:fname
1585 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001586 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1).s:ShellEscape(localfile)." ".s:ShellEscape(tgtdir))
Bram Moolenaar13600302014-05-22 18:26:40 +02001587
Bram Moolenaarff034192013-04-24 18:51:19 +02001588 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001589 " probably a badly formed url; protocol not recognized
1590" call Dret("netrw#Obtain : unsupported method")
1591 return
1592
1593 else
1594 " protocol recognized but not supported for Obtain (yet?)
1595 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001596 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001597 endif
1598" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001599 return
1600 endif
1601
1602 " restore status line
1603 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001604 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001605 endif
1606
1607 endif
1608
1609 " cleanup
1610 if exists("tmpbufnr")
1611 if bufnr("%") != tmpbufnr
1612 exe tmpbufnr."bw!"
1613 else
1614 q!
1615 endif
1616 endif
1617
Bram Moolenaara6878372014-03-22 21:02:50 +01001618" call Dret("netrw#Obtain")
1619endfun
1620
1621" ---------------------------------------------------------------------
1622" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1623fun! netrw#Nread(mode,fname)
1624" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001625 let svpos= winsaveview()
1626" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001627 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001628" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1629 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001630
1631 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1632 if exists("w:netrw_bannercnt")
1633 " start with cursor just after the banner
1634 exe w:netrw_bannercnt
1635 endif
1636 endif
1637" call Dret("netrw#Nread")
1638endfun
1639
1640" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001641" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1642" Options get restored by s:NetrwOptionsRestore()
1643"
1644" Option handling:
1645" * save user's options (s:NetrwOptionsSave)
1646" * set netrw-safe options (s:NetrwOptionsSafe)
1647" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1648" * restore user's options (s:netrwOPtionsRestore)
1649" - restore a user option when != safe option (s:NetrwRestoreSetting)
1650" vt: (variable type) normally its either "w:" or "s:"
1651fun! s:NetrwOptionsSave(vt)
1652" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1653" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001654" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt." hid=".&hid,'~'.expand("<slnum>"))
1655" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001656
1657 if !exists("{a:vt}netrw_optionsave")
1658 let {a:vt}netrw_optionsave= 1
1659 else
1660" call Dret("s:NetrwOptionsSave : options already saved")
1661 return
1662 endif
1663" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1664
1665 " Save current settings and current directory
1666" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1667 let s:yykeep = @@
1668 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1669 let {a:vt}netrw_aikeep = &l:ai
1670 let {a:vt}netrw_awkeep = &l:aw
1671 let {a:vt}netrw_bhkeep = &l:bh
1672 let {a:vt}netrw_blkeep = &l:bl
1673 let {a:vt}netrw_btkeep = &l:bt
1674 let {a:vt}netrw_bombkeep = &l:bomb
1675 let {a:vt}netrw_cedit = &cedit
1676 let {a:vt}netrw_cikeep = &l:ci
1677 let {a:vt}netrw_cinkeep = &l:cin
1678 let {a:vt}netrw_cinokeep = &l:cino
1679 let {a:vt}netrw_comkeep = &l:com
1680 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001681 let {a:vt}netrw_cuckeep = &l:cuc
1682 let {a:vt}netrw_culkeep = &l:cul
1683" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001684 let {a:vt}netrw_diffkeep = &l:diff
1685 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001686 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1687 let {a:vt}netrw_ffkeep = &l:ff
1688 endif
1689 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1690 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001691 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001692 let {a:vt}netrw_hidkeep = &l:hidden
1693 let {a:vt}netrw_imkeep = &l:im
1694 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001695 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001696 let {a:vt}netrw_lskeep = &l:ls
1697 let {a:vt}netrw_makeep = &l:ma
1698 let {a:vt}netrw_magickeep = &l:magic
1699 let {a:vt}netrw_modkeep = &l:mod
1700 let {a:vt}netrw_nukeep = &l:nu
1701 let {a:vt}netrw_rnukeep = &l:rnu
1702 let {a:vt}netrw_repkeep = &l:report
1703 let {a:vt}netrw_rokeep = &l:ro
1704 let {a:vt}netrw_selkeep = &l:sel
1705 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001706 if !g:netrw_use_noswf
1707 let {a:vt}netrw_swfkeep = &l:swf
1708 endif
1709 let {a:vt}netrw_tskeep = &l:ts
1710 let {a:vt}netrw_twkeep = &l:tw " textwidth
1711 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1712 let {a:vt}netrw_wrapkeep = &l:wrap
1713 let {a:vt}netrw_writekeep = &l:write
1714
1715 " save a few selected netrw-related variables
1716" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1717 if g:netrw_keepdir
1718 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001719" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001720 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001721 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001722 sil! let {a:vt}netrw_starkeep = @*
1723 sil! let {a:vt}netrw_pluskeep = @+
1724 endif
1725 sil! let {a:vt}netrw_slashkeep= @/
1726
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001727" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001728" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
1729" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1730endfun
1731
1732" ---------------------------------------------------------------------
1733" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1734" Use s:NetrwSaveOptions() to save user settings
1735" Use s:NetrwOptionsRestore() to restore user settings
1736fun! s:NetrwOptionsSafe(islocal)
1737" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1738" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1739" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
1740 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1741 call s:NetrwSetSafeSetting("&l:ai",0)
1742 call s:NetrwSetSafeSetting("&l:aw",0)
1743 call s:NetrwSetSafeSetting("&l:bl",0)
1744 call s:NetrwSetSafeSetting("&l:bomb",0)
1745 if a:islocal
1746 call s:NetrwSetSafeSetting("&l:bt","nofile")
1747 else
1748 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1749 endif
1750 call s:NetrwSetSafeSetting("&l:ci",0)
1751 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001752 if g:netrw_fastbrowse > a:islocal
1753 call s:NetrwSetSafeSetting("&l:bh","hide")
1754 else
1755 call s:NetrwSetSafeSetting("&l:bh","delete")
1756 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001757 call s:NetrwSetSafeSetting("&l:cino","")
1758 call s:NetrwSetSafeSetting("&l:com","")
1759 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1760 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1761 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001762 if &go =~ 'a' | set go-=a | endif
1763 if &go =~ 'A' | set go-=A | endif
1764 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001765 call s:NetrwSetSafeSetting("&l:hid",0)
1766 call s:NetrwSetSafeSetting("&l:im",0)
1767 setl isk+=@ isk+=* isk+=/
1768 call s:NetrwSetSafeSetting("&l:magic",1)
1769 if g:netrw_use_noswf
1770 call s:NetrwSetSafeSetting("swf",0)
1771 endif
1772 call s:NetrwSetSafeSetting("&l:report",10000)
1773 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1774 call s:NetrwSetSafeSetting("&l:spell",0)
1775 call s:NetrwSetSafeSetting("&l:tw",0)
1776 call s:NetrwSetSafeSetting("&l:wig","")
1777 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001778
1779 " set up cuc and cul based on g:netrw_cursor and listing style
1780 " COMBAK -- cuc cul related
1781 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001782
1783 " allow the user to override safe options
1784" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1785 if &ft == "netrw"
1786" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1787 keepalt NetrwKeepj doau FileType netrw
1788 endif
1789
1790" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1791" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
1792" call Dret("s:NetrwOptionsSafe")
1793endfun
1794
1795" ---------------------------------------------------------------------
1796" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1797fun! s:NetrwOptionsRestore(vt)
1798" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001799" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001800" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001801 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001802" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01001803 if filereadable(expand("%"))
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001804" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001805 filetype detect
1806" 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>"))
1807 else
1808 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001809 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001810" 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 +02001811" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001812 return
1813 endif
1814 unlet {a:vt}netrw_optionsave
1815
1816 if exists("+acd")
1817 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001818" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001819 let curdir = getcwd()
1820 let &l:acd = {a:vt}netrw_acdkeep
1821 unlet {a:vt}netrw_acdkeep
1822 if &l:acd
1823 call s:NetrwLcd(curdir)
1824 endif
1825 endif
1826 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001827" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001828 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1829 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1830 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1831 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1832 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001833" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001834 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1835 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1836 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1837 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1838 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001839" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001840 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1841 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1842 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1843 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1844 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001845 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001846" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1847 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1848 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001849 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001850 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1851" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1852 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1853 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1854" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1855 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1856" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1857 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1858 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001859 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001860 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1861 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1862" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1863 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1864 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1865 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1866 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1867" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001868 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001869 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1870 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1871 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001872 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001873" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001874 call s:NetrwRestoreSetting("s:yykeep","@@")
1875 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1876 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1877 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1878 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1879
Bram Moolenaara6878372014-03-22 21:02:50 +01001880 if exists("{a:vt}netrw_swfkeep")
1881 if &directory == ""
1882 " user hasn't specified a swapfile directory;
1883 " netrw will temporarily set the swapfile directory
1884 " to the current directory as returned by getcwd().
1885 let &l:directory= getcwd()
1886 sil! let &l:swf = {a:vt}netrw_swfkeep
1887 setl directory=
1888 unlet {a:vt}netrw_swfkeep
1889 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001890 if !g:netrw_use_noswf
1891 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1892 sil! let &l:swf= {a:vt}netrw_swfkeep
1893 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001894 unlet {a:vt}netrw_swfkeep
1895 endif
1896 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001897 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001898 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1899 if exists("{a:vt}netrw_dirkeep")
1900 call s:NetrwLcd(dirkeep)
1901 unlet {a:vt}netrw_dirkeep
1902 endif
1903 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001904 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001905" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001906 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1907 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001908 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001909 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001910
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001911" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1912" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1913" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1914" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1915" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001916 " Moved the filetype detect here from NetrwGetFile() because remote files
1917 " were having their filetype detect-generated settings overwritten by
1918 " NetrwOptionRestore.
1919 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001920" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1921 filetype detect
1922" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001923 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001924" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001925" 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 +02001926" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001927endfun
1928
1929" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001930" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1931" but only when the options' value and the safe setting differ
1932" Doing this means that netrw will not come up as having changed a
1933" setting last when it really didn't actually change it.
1934"
1935" Called from s:NetrwOptionsSafe
1936" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1937fun! s:NetrwSetSafeSetting(setting,safesetting)
1938" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001939
Bram Moolenaar85850f32019-07-19 22:05:51 +02001940 if a:setting =~ '^&'
1941" call Decho("fyi: a:setting starts with &")
1942 exe "let settingval= ".a:setting
1943" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001944
Bram Moolenaar85850f32019-07-19 22:05:51 +02001945 if settingval != a:safesetting
1946" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1947 if type(a:safesetting) == 0
1948 exe "let ".a:setting."=".a:safesetting
1949 elseif type(a:safesetting) == 1
1950 exe "let ".a:setting."= '".a:safesetting."'"
1951 else
1952 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1953 endif
1954 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001955 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001956
Bram Moolenaar85850f32019-07-19 22:05:51 +02001957" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001958endfun
1959
1960" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001961" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1962" but only if the setting value differs from the associated keepvar.
1963" Doing this means that netrw will not come up as having changed a
1964" setting last when it really didn't actually change it.
1965"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001966" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001967" keepvars are set up by s:NetrwOptionsSave
1968fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001969""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001970
Bram Moolenaar85850f32019-07-19 22:05:51 +02001971 " typically called from s:NetrwOptionsRestore
1972 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1973 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001974 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001975 if exists(a:keepvar)
1976 exe "let keepvarval= ".a:keepvar
1977 exe "let setting= ".a:setting
1978
1979"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1980"" call Decho("fyi: keepvarval=".keepvarval)
1981"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1982
1983 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001984"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001985 if type(a:setting) == 0
1986 exe "let ".a:setting."= ".keepvarval
1987 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001988 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001989 else
1990 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1991 endif
1992 endif
1993
1994 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001995 endif
1996
Bram Moolenaar85850f32019-07-19 22:05:51 +02001997"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001998endfun
1999
2000" ---------------------------------------------------------------------
2001" NetrwStatusLine: {{{2
2002fun! NetrwStatusLine()
2003
2004" vvv NetrwStatusLine() debugging vvv
2005" let g:stlmsg=""
2006" if !exists("w:netrw_explore_bufnr")
2007" let g:stlmsg="!X<explore_bufnr>"
2008" elseif w:netrw_explore_bufnr != bufnr("%")
2009" let g:stlmsg="explore_bufnr!=".bufnr("%")
2010" endif
2011" if !exists("w:netrw_explore_line")
2012" let g:stlmsg=" !X<explore_line>"
2013" elseif w:netrw_explore_line != line(".")
2014" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2015" endif
2016" if !exists("w:netrw_explore_list")
2017" let g:stlmsg=" !X<explore_list>"
2018" endif
2019" ^^^ NetrwStatusLine() debugging ^^^
2020
2021 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")
2022 " restore user's status line
2023 let &stl = s:netrw_users_stl
2024 let &laststatus = s:netrw_users_ls
2025 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2026 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2027 return ""
2028 else
2029 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2030 endif
2031endfun
2032
Bram Moolenaar85850f32019-07-19 22:05:51 +02002033" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002034" Netrw Transfer Functions: {{{1
2035" ===============================
2036
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002038" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002039" mode: =0 read remote file and insert before current line
2040" =1 read remote file and insert after current line
2041" =2 replace with remote file
2042" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002043fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002044" 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 +00002045
Bram Moolenaar5c736222010-01-06 20:54:52 +01002046 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002047 call s:NetrwOptionsSave("w:")
2048 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002049 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002050 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2051 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2052 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002053" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002054
Bram Moolenaar5c736222010-01-06 20:54:52 +01002055 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002057 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002058 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002059 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002060 elseif a:mode == 2 " replace with remote file
2061 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002062 elseif a:mode == 3 " skip read of file (leave as temporary)
2063 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002064 else
2065 exe a:mode
2066 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002067 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002068 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002069" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002070
Bram Moolenaar5c736222010-01-06 20:54:52 +01002071 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002072 let tmpfile= s:GetTempfile("")
2073 if tmpfile == ""
2074" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002075 return
2076 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002077
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002078 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002079
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002080 " attempt to repeat with previous host-file-etc
2081 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002082" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002083 let choice = b:netrw_lastfile
2084 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002085
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002086 else
2087 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002088" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002089
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002090 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002091 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002092 echomsg 'NetRead Usage:'
2093 echomsg ':Nread machine:path uses rcp'
2094 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2095 echomsg ':Nread "machine id password path" uses ftp'
2096 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2097 echomsg ':Nread fetch://machine/path uses fetch'
2098 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2099 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002100 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002101 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002102 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2103 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2104 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2105 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002106 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002107 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002108
Bram Moolenaar9964e462007-05-05 17:54:07 +00002109 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002110 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002111" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002112 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002113 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002114 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002115 else
2116 " case "... ... ..."
2117 let choice = strpart(choice,1,strlen(choice)-1)
2118 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002119
Bram Moolenaar9964e462007-05-05 17:54:07 +00002120 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002121 let wholechoice = wholechoice . " " . choice
2122 let ichoice = ichoice + 1
2123 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002124 if !exists("g:netrw_quiet")
2125 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2126 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002127" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002128 return
2129 endif
2130 let choice= a:{ichoice}
2131 endwhile
2132 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2133 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 endif
2135 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002137" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002138 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002139
Bram Moolenaar5c736222010-01-06 20:54:52 +01002140 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002141 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002142 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002143" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002144 return
2145 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002146 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002147
Bram Moolenaar8d043172014-01-23 14:24:41 +01002148 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002149" 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 +02002150 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002151" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002152 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002153" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002156
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002157 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002158 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002159 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002160 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2161 echo "(netrw) Processing your read request..."
2162 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002163
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002164 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002165 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002167" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002168 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002169 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002170 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 " ER: the tmpfile is full path: rcp sees C:\... as host C
2172 if s:netrw_has_nt_rcp == 1
2173 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2174 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2175 else
2176 " Any way needed it machine contains a '.'
2177 let uid_machine = g:netrw_machine .'.'. $USERNAME
2178 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002180 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2181 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2182 else
2183 let uid_machine = g:netrw_machine
2184 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002185 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002186 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 +00002187 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002188 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002189
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002190 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002191 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002192 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002193" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002194 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002195 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002196 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002197 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002198 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002199" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002200 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002201 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002202" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002203 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002204 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002206 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002207 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002208 else
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))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002210 endif
2211 " 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 +00002212 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002213 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002214 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002215 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002216 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002217 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002218 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002219 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002220 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2221 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002222 q!
2223 endif
2224 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002225 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002227
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002229 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2231 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002232" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002233 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002234 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002235 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002236 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002237 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002238 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002239" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002240 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002241 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002242" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002243 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002244
Bram Moolenaar97d62492012-11-15 21:28:22 +01002245 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002246 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002247 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002248" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002249 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002250 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002251 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002252" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002253 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002254 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002255" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002256 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002257 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002258
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002259 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002260 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002261" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002262 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002263 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002264 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002265" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002266 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002267 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002268" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002269
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002270 " perform ftp:
2271 " -i : turns off interactive prompting from ftp
2272 " -n unix : DON'T use <.netrc>, even though it exists
2273 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002274 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002275 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002276 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2277 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002278" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002279 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002280 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002281 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002283 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002284 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002285 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002286
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002287 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002288 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002289 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002290" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002291 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002292 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002293 else
2294 let useport= ""
2295 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002296 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2297 " This is workaround to avoid mis-handle windows local-path:
2298 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2299 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2300 else
2301 let tmpfile_get = tmpfile
2302 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002303 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 +00002304 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002305 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002306
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002307 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002308 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002309 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002310" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002311 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002312 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002313 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002314 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002315" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002316 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002317 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002318
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002319 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2320 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002321" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002322 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002323 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 +00002324 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002325 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 +00002326 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002327 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002328
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002329 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002330 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002331" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002332 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2333 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002334" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2335" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2336 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 +00002337 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002338" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002339 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002340 endif
2341 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002342" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002343 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002344
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002345 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002346 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002347 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002348" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002349
Bram Moolenaar5c736222010-01-06 20:54:52 +01002350 if !executable(g:netrw_dav_cmd)
2351 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2352" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2353 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002354 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002355 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002356 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 +01002357 else
2358 " Construct execution string (four lines) which will be passed through filter
2359 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2360 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002361 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002362 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002363 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002364 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002365 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002366 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002367 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002368 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002369 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002370 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2371 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002372
Bram Moolenaar5c736222010-01-06 20:54:52 +01002373 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002374 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002375 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002376 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002377 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002378 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002379 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002380
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002382 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002383 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002384" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002385 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 +00002386 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002388
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002390 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002392 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002393" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002394 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002395 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002396 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002397 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002398" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002399 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002400 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002401 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002402 let netrw_option= "http"
2403 else
2404 let netrw_option= "ftp"
2405 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002406" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002407
Bram Moolenaar446cb832008-06-24 21:56:24 +00002408 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002409 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002410 else
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_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002412 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002413
Bram Moolenaar446cb832008-06-24 21:56:24 +00002414 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002415 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002416" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002417 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002418
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002419 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002420 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002421 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002422" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2423 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 +00002424 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002425 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002426
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002427 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002428 " NetRead: (file) NetRead Method #10 {{{3
2429 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002430" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2431 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002432 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2433 let b:netrw_lastfile = choice
2434
2435 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002436 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002437 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002438 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002439 endif
2440 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002441
Bram Moolenaar5c736222010-01-06 20:54:52 +01002442 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002443 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002444" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002446 unlet b:netrw_fname
2447 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002448 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 +01002449" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002450 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002451 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002452 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002453
Bram Moolenaar9964e462007-05-05 17:54:07 +00002454" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002455endfun
2456
2457" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002458" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002459fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002460" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002461
Bram Moolenaar5c736222010-01-06 20:54:52 +01002462 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002463 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002464 call s:NetrwOptionsSave("w:")
2465 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002466
Bram Moolenaar5c736222010-01-06 20:54:52 +01002467 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002468 let tmpfile= s:GetTempfile("")
2469 if tmpfile == ""
2470" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002471 return
2472 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002473
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002474 if a:0 == 0
2475 let ichoice = 0
2476 else
2477 let ichoice = 1
2478 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002479
Bram Moolenaar9964e462007-05-05 17:54:07 +00002480 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002481" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002482 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002483 " For binary writes, always write entire file.
2484 " (line numbers don't really make sense for that).
2485 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002486" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002487 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002488 elseif g:netrw_cygwin
2489 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002490 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002491" 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 +01002492 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002493 else
2494 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002495" 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 +01002496 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002497 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002498
Bram Moolenaar9964e462007-05-05 17:54:07 +00002499 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002500 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002501 " on the temporary file's name. Deletion of the temporary file during
2502 " cleanup then causes an error message.
2503 0file!
2504 endif
2505
Bram Moolenaar5c736222010-01-06 20:54:52 +01002506 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002507 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002508
Bram Moolenaar9964e462007-05-05 17:54:07 +00002509 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002510 " attempt to repeat with previous host-file-etc
2511 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002512" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002513 let choice = b:netrw_lastfile
2514 let ichoice= ichoice + 1
2515 else
2516 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002517
Bram Moolenaar8d043172014-01-23 14:24:41 +01002518 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002519 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002520 echomsg 'NetWrite Usage:"'
2521 echomsg ':Nwrite machine:path uses rcp'
2522 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2523 echomsg ':Nwrite "machine id password path" uses ftp'
2524 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2525 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2526 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2527 echomsg ':Nwrite rcp://machine/path uses rcp'
2528 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2529 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2530 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002531 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002532 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002533
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002534 elseif match(choice,"^\"") != -1
2535 if match(choice,"\"$") != -1
2536 " case "..."
2537 let choice=strpart(choice,1,strlen(choice)-2)
2538 else
2539 " case "... ... ..."
2540 let choice = strpart(choice,1,strlen(choice)-1)
2541 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002542
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002543 while match(choice,"\"$") == -1
2544 let wholechoice= wholechoice . " " . choice
2545 let ichoice = ichoice + 1
2546 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002547 if !exists("g:netrw_quiet")
2548 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2549 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002550" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002551 return
2552 endif
2553 let choice= a:{ichoice}
2554 endwhile
2555 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2556 endif
2557 endif
2558 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002559 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002560" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002561
Bram Moolenaar9964e462007-05-05 17:54:07 +00002562 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002563 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002564 if !exists("b:netrw_method") || b:netrw_method < 0
2565" call Dfunc("netrw#NetWrite : unsupported method")
2566 return
2567 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002568
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002569 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002570 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002571 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002572 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2573 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002574" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002575 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002576
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002577 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002578 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002579 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002580" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002581 if s:netrw_has_nt_rcp == 1
2582 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2583 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2584 else
2585 let uid_machine = g:netrw_machine .'.'. $USERNAME
2586 endif
2587 else
2588 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2589 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2590 else
2591 let uid_machine = g:netrw_machine
2592 endif
2593 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002594 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 +00002595 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002596
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002597 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002598 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002599 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002600" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002601 let netrw_fname = b:netrw_fname
2602
2603 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2604 let bhkeep = &l:bh
2605 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002606 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002607 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002608
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002610 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002611 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002612" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002613 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002614 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002615" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002616 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002617 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002618" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002620 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 +00002621 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002622" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2623 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002624 endif
2625 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2626 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002627 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002628 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002629 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002630 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002632
2633 " remove enew buffer (quietly)
2634 let filtbuf= bufnr("%")
2635 exe curbuf."b!"
2636 let &l:bh = bhkeep
2637 exe filtbuf."bw!"
2638
Bram Moolenaar071d4272004-06-13 20:20:40 +00002639 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002640
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002641 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002642 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002643 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002645" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002646 let netrw_fname = b:netrw_fname
2647 let bhkeep = &l:bh
2648
2649 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2650 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002651 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002652 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002653 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002654
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002655 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002656 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002657" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002658 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002659 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002660" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002661 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002662 if exists("g:netrw_uid") && g:netrw_uid != ""
2663 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002664 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002665" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002666 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002667 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002668 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002669" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002670 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002671 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002672" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002673 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002674 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002675 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002676" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002677 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002678 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002679" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002680 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002681 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002682" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002683 " save choice/id/password for future use
2684 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002685
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002686 " perform ftp:
2687 " -i : turns off interactive prompting from ftp
2688 " -n unix : DON'T use <.netrc>, even though it exists
2689 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002690 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002691 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002692 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2693 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002694 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002695 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002696 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002697 let mod=1
2698 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002699
2700 " remove enew buffer (quietly)
2701 let filtbuf= bufnr("%")
2702 exe curbuf."b!"
2703 let &l:bh= bhkeep
2704 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002705
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002706 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002707 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002708 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002709" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002710 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002711 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002712 else
2713 let useport= ""
2714 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002715 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 +00002716 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002717
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002718 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002719 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002720 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002721" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002722 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2723 if executable(curl)
2724 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002725 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 +01002726 elseif !exists("g:netrw_quiet")
Bram Moolenaar85850f32019-07-19 22:05:51 +02002727 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002728 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002729
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002730 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002731 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002732 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002733" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002734
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002735 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002736 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2737 let bhkeep = &l:bh
2738
2739 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2740 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002741 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002742 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002743
Bram Moolenaarff034192013-04-24 18:51:19 +02002744 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002745 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002746 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002747 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002748 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002749 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002750 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002751 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002752 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002753 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002754
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002755 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002756 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002757 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002758
2759 " remove enew buffer (quietly)
2760 let filtbuf= bufnr("%")
2761 exe curbuf."b!"
2762 let &l:bh = bhkeep
2763 exe filtbuf."bw!"
2764
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002765 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002766
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002767 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002768 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002769 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002770" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002771 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 +00002772 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002773
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002774 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002775 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002776 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002777" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002778 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2780 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2781 else
2782 let uid_machine = g:netrw_machine
2783 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002784
2785 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2786 let bhkeep = &l:bh
2787 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002788 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002789 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002790
Bram Moolenaarff034192013-04-24 18:51:19 +02002791 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002792 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002793" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002794 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002795 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002796 let filtbuf= bufnr("%")
2797 exe curbuf."b!"
2798 let &l:bh = bhkeep
2799 exe filtbuf."bw!"
2800 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002801
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002802 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002803 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002804 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002805 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002806 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002808 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002809
Bram Moolenaar5c736222010-01-06 20:54:52 +01002810 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002811" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002812 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002813" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002814 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002815 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002816 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002817
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002818 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002819 " restore modifiability; usually equivalent to set nomod
2820 let &mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002821" 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 +02002822 elseif !exists("leavemod")
2823 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002824" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002825 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002826" 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 +00002827 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002828
Bram Moolenaar9964e462007-05-05 17:54:07 +00002829" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002830endfun
2831
2832" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002833" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002834" uses NetRead to get a copy of the file into a temporarily file,
2835" then sources that file,
2836" then removes that file.
2837fun! netrw#NetSource(...)
2838" call Dfunc("netrw#NetSource() a:0=".a:0)
2839 if a:0 > 0 && a:1 == '?'
2840 " give help
2841 echomsg 'NetSource Usage:'
2842 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2843 echomsg ':Nsource fetch://machine/path uses fetch'
2844 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002845 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002846 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2847 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2848 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2849 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2850 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002851 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002852 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002853 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002854 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002855" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002856 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002857" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002858 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002859" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002860 if delete(s:netrw_tmpfile)
2861 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2862 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002863 unlet s:netrw_tmpfile
2864 else
2865 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2866 endif
2867 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002868 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002869 endif
2870" call Dret("netrw#NetSource")
2871endfun
2872
Bram Moolenaar8d043172014-01-23 14:24:41 +01002873" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002874" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2875" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002876fun! netrw#SetTreetop(iscmd,...)
2877" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2878" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002879
Bram Moolenaar85850f32019-07-19 22:05:51 +02002880 " iscmd==0: netrw#SetTreetop called using gn mapping
2881 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2882" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002883 " clear out the current tree
2884 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002885" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002886 let inittreetop= w:netrw_treetop
2887 unlet w:netrw_treetop
2888 endif
2889 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002890" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002891 unlet w:netrw_treedict
2892 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002893" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002894
Bram Moolenaar85850f32019-07-19 22:05:51 +02002895 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002896 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002897" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002898 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002899 if isdirectory(s:NetrwFile(a:1))
2900" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002901 let treedir = a:1
2902 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002904 let treedir = b:netrw_curdir."/".a:1
2905 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002906" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002907 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002908 " normally the cursor is left in the message window.
2909 " However, here this results in the directory being listed in the message window, which is not wanted.
2910 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002911 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002912 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002913 let treedir = "."
2914 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002915 endif
2916 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002917" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002918
2919 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002920 let islocal= expand("%") !~ '^\a\{3,}://'
2921" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002922
2923 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002924 if islocal
2925 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2926 else
2927 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2928 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002929
Bram Moolenaara6878372014-03-22 21:02:50 +01002930" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002931endfun
2932
Bram Moolenaar9964e462007-05-05 17:54:07 +00002933" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002934" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935" readcmd == %r : replace buffer with newly read file
2936" == 0r : read file at top of buffer
2937" == r : read file after current line
2938" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002939fun! s:NetrwGetFile(readcmd, tfile, method)
2940" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002941
2942 " readcmd=='t': simply do nothing
2943 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002944" 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 +01002945" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002946 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002947 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002948
Bram Moolenaar9964e462007-05-05 17:54:07 +00002949 " get name of remote filename (ie. url and all)
2950 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002951" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002952
Bram Moolenaar9964e462007-05-05 17:54:07 +00002953 if exists("*NetReadFixup")
2954 " for the use of NetReadFixup (not otherwise used internally)
2955 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002956 endif
2957
Bram Moolenaar9964e462007-05-05 17:54:07 +00002958 if a:readcmd[0] == '%'
2959 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002960" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002961
2962 " rename the current buffer to the temp file (ie. tfile)
2963 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002964 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002965 else
2966 let tfile= a:tfile
2967 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002968 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002969
2970 " edit temporary file (ie. read the temporary file in)
2971 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002972" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002973 call zip#Browse(tfile)
2974 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002975" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002976 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002977 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002978" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002979 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002980 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002981" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002982 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002983 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002984" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002985 call tar#Browse(tfile)
2986 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002987" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002988 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002989 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002990" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002991 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002992 endif
2993
2994 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002995 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002996
Bram Moolenaar71badf92023-04-22 22:40:14 +01002997 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002998 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002999 " Note that isk must not include a "/" for scripts.vim
3000 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01003001" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
3002" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003003" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003004" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3005 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003006 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003007 filetype detect
3008" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3009 let &isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003010" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003011 let line1 = 1
3012 let line2 = line("$")
3013
Bram Moolenaar8d043172014-01-23 14:24:41 +01003014 elseif !&ma
3015 " 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 +01003016 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003017" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003018 return
3019
Bram Moolenaar9964e462007-05-05 17:54:07 +00003020 elseif s:FileReadable(a:tfile)
3021 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003022" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003023 let curline = line(".")
3024 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003025" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003026 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003027 let line1= curline + 1
3028 let line2= line("$") - lastline + 1
3029
3030 else
3031 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003032" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3033" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003034 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003035" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003036 return
3037 endif
3038
3039 " User-provided (ie. optional) fix-it-up command
3040 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003041" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003042 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003043" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003044" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003045 endif
3046
Bram Moolenaaradc21822011-04-01 18:03:16 +02003047 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003048 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003049 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003050 endif
3051
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003052" 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 +00003053
3054 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003055" redraw!
3056
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003057" 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 +00003058" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003059endfun
3060
Bram Moolenaar9964e462007-05-05 17:54:07 +00003061" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003062" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003063" Input:
3064" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3065" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003066" b:netrw_method= 1: rcp
3067" 2: ftp + <.netrc>
3068" 3: ftp + machine, id, password, and [path]filename
3069" 4: scp
3070" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003071" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003072" 7: rsync
3073" 8: fetch
3074" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003075" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003076" g:netrw_machine= hostname
3077" b:netrw_fname = filename
3078" g:netrw_port = optional port number (for ftp)
3079" g:netrw_choice = copy of input url (choice)
3080fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003081" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003082
Bram Moolenaar251e1912011-06-19 05:09:16 +02003083 " sanity check: choice should have at least three slashes in it
3084 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3085 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3086 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003087" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003088 return
3089 endif
3090
Bram Moolenaar5c736222010-01-06 20:54:52 +01003091 " record current g:netrw_machine, if any
3092 " curmachine used if protocol == ftp and no .netrc
3093 if exists("g:netrw_machine")
3094 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003095" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003096 else
3097 let curmachine= "N O T A HOST"
3098 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003099 if exists("g:netrw_port")
3100 let netrw_port= g:netrw_port
3101 endif
3102
3103 " insure that netrw_ftp_cmd starts off every method determination
3104 " with the current g:netrw_ftp_cmd
3105 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003106
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003107 " initialization
3108 let b:netrw_method = 0
3109 let g:netrw_machine = ""
3110 let b:netrw_fname = ""
3111 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003112 let g:netrw_choice = a:choice
3113
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003114 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003115 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003116 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3117 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003118 " rcpurm : rcp://[user@]host/filename Use rcp
3119 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003120 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003121 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003122 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003123 " rsyncurm : rsync://host[:port]/path Use rsync
3124 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3125 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003126 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003127 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3128 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003129 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3130 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003131 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003132 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003133 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003134 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003135 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003136 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003137 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003138 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003139
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003140" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003141 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003142 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003143 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003144" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003145 let b:netrw_method = 1
3146 let userid = substitute(a:choice,rcpurm,'\1',"")
3147 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3148 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003149 if userid != ""
3150 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003152
Bram Moolenaaradc21822011-04-01 18:03:16 +02003153 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003154 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003155" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003156 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003157 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3158 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3159 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003160
Bram Moolenaar15146672011-10-20 22:22:38 +02003161 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003162 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003163" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003164 let b:netrw_method = 5
3165 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3166 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003167 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003168
Bram Moolenaaradc21822011-04-01 18:03:16 +02003169 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003170 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003171" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003172 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003173 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003174 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3175 else
3176 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3177 endif
3178 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003179
Bram Moolenaaradc21822011-04-01 18:03:16 +02003180 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003181 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003182" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003183 let b:netrw_method = 7
3184 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3185 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003186
Bram Moolenaaradc21822011-04-01 18:03:16 +02003187 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003188 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003189" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003190 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003191 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3192 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3193 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003194" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003195 if userid != ""
3196 let g:netrw_uid= userid
3197 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003198
Bram Moolenaaradc21822011-04-01 18:03:16 +02003199 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003200 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003201 call NetUserPass("ftp:".g:netrw_machine)
3202 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003203 " if there's a change in hostname, require password re-entry
3204 unlet s:netrw_passwd
3205 endif
3206 if exists("netrw_port")
3207 unlet netrw_port
3208 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003209 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003210
Bram Moolenaar446cb832008-06-24 21:56:24 +00003211 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003212 let b:netrw_method = 3
3213 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003214 let host= substitute(g:netrw_machine,'\..*$','','')
3215 if exists("s:netrw_hup[host]")
3216 call NetUserPass("ftp:".host)
3217
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003218 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003219" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3220" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003221 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003222 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003223" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003224 endif
3225 let b:netrw_method= 2
3226 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003227" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003228 let b:netrw_method= 2
3229 else
3230 if !exists("g:netrw_uid") || g:netrw_uid == ""
3231 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003232 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003233 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003234 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003235 endif
3236 let b:netrw_method= 3
3237 endif
3238 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003239
Bram Moolenaaradc21822011-04-01 18:03:16 +02003240 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003241 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003242" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003243 let b:netrw_method = 8
3244 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3245 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3246 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3247 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003248
Bram Moolenaaradc21822011-04-01 18:03:16 +02003249 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003250 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003251" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003253 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3254 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003255 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003256 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003257 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003258
Bram Moolenaaradc21822011-04-01 18:03:16 +02003259 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003260 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003261" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003262 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003263 let b:netrw_method = 3
3264 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3265 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003266
Bram Moolenaar9964e462007-05-05 17:54:07 +00003267 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003268 let b:netrw_method = 2
3269 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3270 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3271 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003272
Bram Moolenaaradc21822011-04-01 18:03:16 +02003273 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003274 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003275" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003276 let b:netrw_method = 9
3277 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3278 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003279
Bram Moolenaaradc21822011-04-01 18:03:16 +02003280 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003281 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003282" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003283 let b:netrw_method = 1
3284 let userid = substitute(a:choice,rcphf,'\2',"")
3285 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3286 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003287" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3288" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3289" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3290" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003291 if userid != ""
3292 let g:netrw_uid= userid
3293 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003294
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003295 " Method#10: file://user@hostname/...path-to-file {{{3
3296 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003297" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003298 let b:netrw_method = 10
3299 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003300" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003301
Bram Moolenaaradc21822011-04-01 18:03:16 +02003302 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003303 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003304 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003305 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003306 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003307 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003309 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003310
Bram Moolenaar81695252004-12-29 20:58:21 +00003311 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003312 " remove any leading [:#] from port number
3313 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3314 elseif exists("netrw_port")
3315 " retain port number as implicit for subsequent ftp operations
3316 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003317 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003318
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003319" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3320" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3321" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3322" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003323" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003324" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003325" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003326" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003327" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003328" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003329" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003330" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332
3333" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003334" NetReadFixup: this sort of function is typically written by the user {{{2
3335" to handle extra junk that their system's ftp dumps
3336" into the transfer. This function is provided as an
3337" example and as a fix for a Windows 95 problem: in my
3338" experience, win95's ftp always dumped four blank lines
3339" at the end of the transfer.
3340if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3341 fun! NetReadFixup(method, line1, line2)
3342" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003343
3344 " sanity checks -- attempt to convert inputs to integers
3345 let method = a:method + 0
3346 let line1 = a:line1 + 0
3347 let line2 = a:line2 + 0
3348 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3349" call Dret("NetReadFixup")
3350 return
3351 endif
3352
Bram Moolenaar9964e462007-05-05 17:54:07 +00003353 if method == 3 " ftp (no <.netrc>)
3354 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003355 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003356 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003357 call histdel("/",-1)
3358 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003359 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003360
Bram Moolenaar9964e462007-05-05 17:54:07 +00003361" call Dret("NetReadFixup")
3362 endfun
3363endif
3364
3365" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003366" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003367" Usage: :call NetUserPass() -- will prompt for userid and password
3368" :call NetUserPass("uid") -- will prompt for password
3369" :call NetUserPass("uid","password") -- sets global userid and password
3370" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3371" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372fun! NetUserPass(...)
3373
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003374" call Dfunc("NetUserPass() a:0=".a:0)
3375
3376 if !exists('s:netrw_hup')
3377 let s:netrw_hup= {}
3378 endif
3379
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003381 " case: no input arguments
3382
3383 " change host and username if not previously entered; get new password
3384 if !exists("g:netrw_machine")
3385 let g:netrw_machine= input('Enter hostname: ')
3386 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003388 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389 let g:netrw_uid= input('Enter username: ')
3390 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003391 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003392 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003393
3394 " set up hup database
3395 let host = substitute(g:netrw_machine,'\..*$','','')
3396 if !exists('s:netrw_hup[host]')
3397 let s:netrw_hup[host]= {}
3398 endif
3399 let s:netrw_hup[host].uid = g:netrw_uid
3400 let s:netrw_hup[host].passwd = s:netrw_passwd
3401
3402 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003403 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003404
3405 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003406 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003407 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003408" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003409 let host = substitute(a:1,'^ftp:','','')
3410 let host = substitute(host,'\..*','','')
3411 if exists("s:netrw_hup[host]")
3412 let g:netrw_uid = s:netrw_hup[host].uid
3413 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003414" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3415" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003416 else
3417 let g:netrw_uid = input("Enter UserId: ")
3418 let s:netrw_passwd = inputsecret("Enter Password: ")
3419 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003420
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003421 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003422 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003423" 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 +02003424 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003425 if g:netrw_machine =~ '[0-9.]\+'
3426 let host= g:netrw_machine
3427 else
3428 let host= substitute(g:netrw_machine,'\..*$','','')
3429 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003430 else
3431 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003432 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003433 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003434" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003435 if exists("g:netrw_passwd")
3436 " ask for password if one not previously entered
3437 let s:netrw_passwd= g:netrw_passwd
3438 else
3439 let s:netrw_passwd = inputsecret("Enter Password: ")
3440 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003441 endif
3442
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003443" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003444 if exists("host")
3445 if !exists('s:netrw_hup[host]')
3446 let s:netrw_hup[host]= {}
3447 endif
3448 let s:netrw_hup[host].uid = g:netrw_uid
3449 let s:netrw_hup[host].passwd = s:netrw_passwd
3450 endif
3451
3452 elseif a:0 == 2
3453 let g:netrw_uid = a:1
3454 let s:netrw_passwd = a:2
3455
3456 elseif a:0 == 3
3457 " enter hostname, user-id, and password into the hup dictionary
3458 let host = substitute(a:1,'^\a\+:','','')
3459 let host = substitute(host,'\..*$','','')
3460 if !exists('s:netrw_hup[host]')
3461 let s:netrw_hup[host]= {}
3462 endif
3463 let s:netrw_hup[host].uid = a:2
3464 let s:netrw_hup[host].passwd = a:3
3465 let g:netrw_uid = s:netrw_hup[host].uid
3466 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003467" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3468" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003470
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003471" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003473
Bram Moolenaar85850f32019-07-19 22:05:51 +02003474" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003475" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003476" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003478" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003479" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3480fun! s:ExplorePatHls(pattern)
3481" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3482 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003483" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003484 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003485" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003486 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3487" call Dret("s:ExplorePatHls repat<".repat.">")
3488 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003489endfun
3490
3491" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003492" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003493" 0: (user: <mb>) bookmark current directory
3494" 1: (user: <gb>) change to the bookmarked directory
3495" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003496" 3: (browsing) records current directory history
3497" 4: (user: <u>) go up (previous) directory, using history
3498" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003499" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003500fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003501" 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 +02003502 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3503" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3504 return
3505 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003506
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003507 let ykeep = @@
3508 let curbufnr = bufnr("%")
3509
Bram Moolenaar9964e462007-05-05 17:54:07 +00003510 if a:chg == 0
3511 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003512" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003513 if exists("s:netrwmarkfilelist_{curbufnr}")
3514 call s:NetrwBookmark(0)
3515 echo "bookmarked marked files"
3516 else
3517 call s:MakeBookmark(a:curdir)
3518 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003519 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003520
KSR-Yasudaf4498252023-10-06 03:34:17 +09003521 try
3522 call s:NetrwBookHistSave()
3523 catch
3524 endtry
3525
Bram Moolenaar9964e462007-05-05 17:54:07 +00003526 elseif a:chg == 1
3527 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003528" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003529 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003530" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003531 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003532 else
3533 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3534 endif
3535
3536 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003537" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003538 let didwork= 0
3539 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003540" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003541 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003542" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003543 let cnt= 1
3544 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003545" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003546 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003547 let didwork = 1
3548 let cnt = cnt + 1
3549 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003550 endif
3551
3552 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003553 " Note: history is saved only when PerformListing is done;
3554 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3555 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003556 let first = 1
3557 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003558 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003559 while ( first || cnt != g:netrw_dirhistcnt )
3560" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003561 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003562" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003563 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003564 let didwork= 1
3565 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003566 let histcnt = histcnt + 1
3567 let first = 0
3568 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003569 if cnt < 0
3570 let cnt= cnt + g:netrw_dirhistmax
3571 endif
3572 endwhile
3573 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003574 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003575 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003576 if didwork
3577 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3578 endif
3579
3580 elseif a:chg == 3
3581 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003582" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003583 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 +02003584 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003585 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3586 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003587 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003588" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003589 endif
3590
3591 elseif a:chg == 4
3592 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003593" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003594 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003595 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3596 if g:netrw_dirhistcnt < 0
3597 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003598 endif
3599 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003600 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003601 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003602 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3603" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003604 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003605 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003606" call Decho("setl ma noro",'~'.expand("<slnum>"))
3607 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003608 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003609" call Decho("setl nomod",'~'.expand("<slnum>"))
3610" 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 +00003611 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003612" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3613 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003614 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003615 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003616 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003617 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003618 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003619 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003620 echo "Sorry, no predecessor directory exists yet"
3621 endif
3622
3623 elseif a:chg == 5
3624 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003625" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003626 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003627 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3628 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3629" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003630 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003631" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003632 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003633 sil! NetrwKeepj %d _
3634" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3635" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003636 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003637" 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 +02003638 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003639" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3640 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003641 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003642 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3643 if g:netrw_dirhistcnt < 0
3644 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003645 endif
3646 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003647 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003648 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003649 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003650 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003651 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003652
3653 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003654" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003655 if exists("s:netrwmarkfilelist_{curbufnr}")
3656 call s:NetrwBookmark(1)
3657 echo "removed marked files from bookmarks"
3658 else
3659 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003660 let iremove = v:count
3661 let dremove = g:netrw_bookmarklist[iremove - 1]
3662" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003663 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003664" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3665 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3666 echo "removed ".dremove." from g:netrw_bookmarklist"
3667" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003668 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003669" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003670
3671 try
3672 call s:NetrwBookHistSave()
3673 catch
3674 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003675 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003676 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003677 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003678 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003679" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003680endfun
3681
3682" ---------------------------------------------------------------------
3683" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003684" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003685" Sister function: s:NetrwBookHistSave()
3686fun! s:NetrwBookHistRead()
3687" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003688 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003689" 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 +02003690 return
3691 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003692 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003693
3694 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003695 if !exists("s:netrw_initbookhist")
3696 let home = s:NetrwHome()
3697 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003698 if filereadable(s:NetrwFile(savefile))
3699" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003700 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003701 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003702
3703 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003704 if g:netrw_dirhistmax > 0
3705 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003706 if filereadable(s:NetrwFile(savefile))
3707" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003708 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003709 endif
3710 let s:netrw_initbookhist= 1
3711 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003712 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003713 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003714
Bram Moolenaar97d62492012-11-15 21:28:22 +01003715 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003716" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3717" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003718" call Dret("s:NetrwBookHistRead")
3719endfun
3720
3721" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003722" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003723" Sister function: s:NetrwBookHistRead()
3724" I used to do this via viminfo but that appears to
3725" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003726" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3727" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003728" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003729fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003730" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003731 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003732" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003733 return
3734 endif
3735
Bram Moolenaar5c736222010-01-06 20:54:52 +01003736 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003737" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003738 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003739
3740 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003741 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003742" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003743 if g:netrw_use_noswf
3744 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3745 else
3746 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3747 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003748 setl nocin noai noci magic nospell nohid wig= noaw
3749 setl ma noro write
3750 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003751 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003752
Bram Moolenaar85850f32019-07-19 22:05:51 +02003753 " rename enew'd file: .netrwhist -- no attempt to merge
3754 " record dirhistmax and current dirhistcnt
3755 " save history
3756" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003757 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003758 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003759 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3760 if g:netrw_dirhistmax > 0
3761 let lastline = line("$")
3762 let cnt = g:netrw_dirhistcnt
3763 let first = 1
3764 while ( first || cnt != g:netrw_dirhistcnt )
3765 let lastline= lastline + 1
3766 if exists("g:netrw_dirhist_{cnt}")
3767 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3768" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3769 endif
3770 let first = 0
3771 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3772 if cnt < 0
3773 let cnt= cnt + g:netrw_dirhistmax
3774 endif
3775 endwhile
3776 exe "sil! w! ".savefile
3777" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3778 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003779
Bram Moolenaar85850f32019-07-19 22:05:51 +02003780 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003781 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003782 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003783" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003784 " merge and write .netrwbook
3785 let savefile= s:NetrwHome()."/.netrwbook"
3786
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003787 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003788 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003789 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003790 for bdm in booklist
3791 if index(g:netrw_bookmarklist,bdm) == -1
3792 call add(g:netrw_bookmarklist,bdm)
3793 endif
3794 endfor
3795 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003796 endif
3797
3798 " construct and save .netrwbook
3799 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003800 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003801" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003802 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003803
3804 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003805 let bgone= bufnr("%")
3806 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003807 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003808
3809" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003810endfun
3811
3812" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003813" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3814" list of the contents of a local or remote directory. It is assumed that the
3815" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3816" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003817" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003818fun! s:NetrwBrowse(islocal,dirname)
3819 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003820" 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 +02003821" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3822" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3823" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003824
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003825 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3826 " This is useful when one edits a local file, then :e ., then :Rex
3827 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3828 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003829" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003830 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003831
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003832 " s:NetrwBrowse : initialize history {{{3
3833 if !exists("s:netrw_initbookhist")
3834 NetrwKeepj call s:NetrwBookHistRead()
3835 endif
3836
3837 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003838 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003839 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003840" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003841 else
3842 let dirname= a:dirname
3843 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003844
Bram Moolenaar85850f32019-07-19 22:05:51 +02003845 " repoint t:netrw_lexbufnr if appropriate
3846 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3847" call Decho("set repointlexbufnr to true!")
3848 let repointlexbufnr= 1
3849 endif
3850
3851 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003852 if exists("s:netrw_skipbrowse")
3853 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003854" 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 +01003855" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003856 return
3857 endif
3858 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003859 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003860" call Dret("s:NetrwBrowse : missing shellescape()")
3861 return
3862 endif
3863 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003864 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003865" call Dret("s:NetrwBrowse : missing fnameescape()")
3866 return
3867 endif
3868
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003869 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003870 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003871
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003872 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003873 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3874 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3875" call Decho("clearing marked files",'~'.expand("<slnum>"))
3876 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3877 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003878 endif
3879
3880 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003881 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003882" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3883" 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 +02003884 if s:NetrwLcd(dirname)
3885" call Dret("s:NetrwBrowse : lcd failure")
3886 return
3887 endif
3888 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003889" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003890
Bram Moolenaar5c736222010-01-06 20:54:52 +01003891 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003892 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003893" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003894 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003895" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003896 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003897 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003898 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003899" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003900
3901 " remove any filetype indicator from end of dirname, except for the
3902 " "this is a directory" indicator (/).
3903 " There shouldn't be one of those here, anyway.
3904 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003905" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003906 call s:RemotePathAnalysis(dirname)
3907
3908 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3909 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003910 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003911 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003912" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003913 let b:netrw_curdir = dirname
3914 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003915 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003916 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3917 sil call netrw#NetRead(2,url)
3918 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003919" call Decho("url<".url.">",'~'.expand("<slnum>"))
3920" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3921" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003922 if s:path =~ '.bz2'
3923 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3924 elseif s:path =~ '.gz'
3925 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3926 elseif s:path =~ '.gz'
3927 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3928 else
3929 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3930 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003931 endif
3932
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003933 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003934 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003935 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003936" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003937 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003938" 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 +00003939
Bram Moolenaar446cb832008-06-24 21:56:24 +00003940" call Dret("s:NetrwBrowse : file<".s:fname.">")
3941 return
3942 endif
3943
Bram Moolenaaradc21822011-04-01 18:03:16 +02003944 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003945 call s:UseBufWinVars()
3946
3947 " set up some variables {{{3
3948 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003949 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003950 let s:last_sort_by = g:netrw_sort_by
3951
3952 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003953 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003954
Bram Moolenaar97d62492012-11-15 21:28:22 +01003955 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003956" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003957 let svpos = winsaveview()
3958" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003959 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003960
Bram Moolenaar446cb832008-06-24 21:56:24 +00003961 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003962 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3963 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3964" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3965" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3966 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3967 else
3968" " call Decho("2match none",'~'.expand("<slnum>"))
3969 2match none
3970 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003971 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003972 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003973 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003974" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003975 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003976" 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 +01003977" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003978 return
3979 endif
3980
3981 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003982" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003983 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003984 if b:netrw_curdir =~ '[/\\]$'
3985 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3986 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003987 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3988 let b:netrw_curdir= b:netrw_curdir."/"
3989 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003990 if b:netrw_curdir == ''
3991 if has("amiga")
3992 " On the Amiga, the empty string connotes the current directory
3993 let b:netrw_curdir= getcwd()
3994 else
3995 " under unix, when the root directory is encountered, the result
3996 " from the preceding substitute is an empty string.
3997 let b:netrw_curdir= '/'
3998 endif
3999 endif
4000 if !a:islocal && b:netrw_curdir !~ '/$'
4001 let b:netrw_curdir= b:netrw_curdir.'/'
4002 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004003" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004004
4005 " ------------
4006 " (local only) {{{3
4007 " ------------
4008 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004009" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004010
4011 " Set up ShellCmdPost handling. Append current buffer to browselist
4012 call s:LocalFastBrowser()
4013
4014 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
4015 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004016" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
4017" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004018 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004019 if s:NetrwLcd(b:netrw_curdir)
4020" call Dret("s:NetrwBrowse : lcd failure")
4021 return
4022 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004023 endif
4024 endif
4025
4026 " --------------------------------
4027 " remote handling: {{{3
4028 " --------------------------------
4029 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004030" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004031
Bram Moolenaar97d62492012-11-15 21:28:22 +01004032 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004033" 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 +02004034 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004035 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004036" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004037 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4038 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4039 if dirname !~ '/$'
4040 let dirname= dirname.'/'
4041 endif
4042 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004043" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004044 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004045 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004046" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004047 endif
4048
4049 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4050 if dirname !~ dirpat
4051 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004052 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004053 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004054 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004055" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004056 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004057" 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 +00004058" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4059 return
4060 endif
4061 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004062" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004063 endif " (additional remote handling)
4064
Bram Moolenaar85850f32019-07-19 22:05:51 +02004065 " -------------------------------
4066 " Perform Directory Listing: {{{3
4067 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004068 NetrwKeepj call s:NetrwMaps(a:islocal)
4069 NetrwKeepj call s:NetrwCommands(a:islocal)
4070 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004071
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004072 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004073 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004074" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4075
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004076 " If there is a rexposn: restore position with rexposn
4077 " Otherwise : set rexposn
4078 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004079" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4080 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4081 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4082 NetrwKeepj exe w:netrw_bannercnt
4083 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004084 else
4085 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4086 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004087 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004088 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004089" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004090 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004091 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004092
Bram Moolenaar85850f32019-07-19 22:05:51 +02004093 " repoint t:netrw_lexbufnr if appropriate
4094 if exists("repointlexbufnr")
4095 let t:netrw_lexbufnr= bufnr("%")
4096" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4097 endif
4098
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004099 " restore position
4100 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004101" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4102 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004103 endif
4104
Bram Moolenaara6878372014-03-22 21:02:50 +01004105 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004106 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4107 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004108" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4109" 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 +02004110" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004111 return
4112endfun
4113
4114" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004115" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4116" may not apply correctly; ie. netrw's idea of the current directory may
4117" differ from vim's. This function insures that netrw's idea of the current
4118" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004119" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004120fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004121" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4122" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4123" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4124" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4125" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004126
4127 " clean up any leading treedepthstring
4128 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4129 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004130" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004131 else
4132 let fname= a:fname
4133 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004134
4135 if g:netrw_keepdir
4136 " vim's idea of the current directory possibly may differ from netrw's
4137 if !exists("b:netrw_curdir")
4138 let b:netrw_curdir= getcwd()
4139 endif
4140
4141 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004142 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004143 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004144 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004145" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004146 else
4147 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004148 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004149" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004150 endif
4151
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004152 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004153 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004154 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004155" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004156 else
4157 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004158 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004159" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004160 endif
4161 else
4162 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004163 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004164" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4165" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4166" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004167 endif
4168
Bram Moolenaar85850f32019-07-19 22:05:51 +02004169" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004170 return ret
4171endfun
4172
4173" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004174" s:NetrwFileInfo: supports qf (query for file information) {{{2
4175fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004176" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004177 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004178 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004179 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004180 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004181 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004182 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004183 let lsopt= "-lsadh --si"
4184 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004185" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004186 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004187
4188 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004189 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004190" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004191
Bram Moolenaara6878372014-03-22 21:02:50 +01004192 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004193 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004194" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004195
4196 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004197 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004198" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004199
Bram Moolenaar446cb832008-06-24 21:56:24 +00004200 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004201" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004202 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004203" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004204 endif
4205 else
4206 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004207" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4208 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004209 let fname= substitute(a:fname,".$","","")
4210 else
4211 let fname= a:fname
4212 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004213 let t = getftime(s:NetrwFile(fname))
4214 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004215 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004216 let sz= s:NetrwHumanReadable(sz)
4217 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004218 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4219" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004220 endif
4221 else
4222 echo "sorry, \"qf\" not supported yet for remote files"
4223 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004224 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004225" call Dret("s:NetrwFileInfo")
4226endfun
4227
4228" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004229" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4230fun! s:NetrwFullPath(filename)
4231" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4232 let filename= a:filename
4233 if filename !~ '^/'
4234 let filename= resolve(getcwd().'/'.filename)
4235 endif
4236 if filename != "/" && filename =~ '/$'
4237 let filename= substitute(filename,'/$','','')
4238 endif
4239" " call Dret("s:NetrwFullPath <".filename.">")
4240 return filename
4241endfun
4242
4243" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004244" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004245" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004246" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004247" 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 +00004248fun! s:NetrwGetBuffer(islocal,dirname)
4249" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004250" 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 +02004251" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4252" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004253 let dirname= a:dirname
4254
4255 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004256" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004257 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004258" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004259 let s:netrwbuf= {}
4260 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004261" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4262" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4263
4264 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4265 let bufnum = -1
4266
4267 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4268 if has_key(s:netrwbuf,"NetrwTreeListing")
4269 let bufnum= s:netrwbuf["NetrwTreeListing"]
4270 else
4271 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4272 endif
4273" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4274 if !bufexists(bufnum)
4275 call remove(s:netrwbuf,"NetrwTreeListing"])
4276 let bufnum= -1
4277 endif
4278 elseif bufnr("NetrwTreeListing") != -1
4279 let bufnum= bufnr("NetrwTreeListing")
4280" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4281 else
4282" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4283 let bufnum= -1
4284 endif
4285
4286 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004287 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004288" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004289 if !bufexists(bufnum)
4290 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4291 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004292 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004293
Bram Moolenaar446cb832008-06-24 21:56:24 +00004294 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004295" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004296 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004297 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004298" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4299
Bram Moolenaar71badf92023-04-22 22:40:14 +01004300 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004301 " IF the buffer already has the desired name
4302 " AND it is empty
4303 let curbuf = bufname("%")
4304 if curbuf == '.'
4305 let curbuf = getcwd()
4306 endif
4307" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004308" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004309" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4310" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4311" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4312" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4313 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004314" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4315 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004316 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004317" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004318 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004319 " 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 +00004320
4321 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004322 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004323" 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 +00004324 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004325" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004326 " name the buffer
4327 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4328 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004329" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004330 let w:netrw_treebufnr = bufnr("%")
4331 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004332 if g:netrw_use_noswf
4333 setl nobl bt=nofile noswf
4334 else
4335 setl nobl bt=nofile
4336 endif
4337 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4338 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4339 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4340 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004341" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004342 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004343 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004344 " enter the new buffer into the s:netrwbuf dictionary
4345 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4346" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4347" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004348 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004349" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004350
4351 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004352" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004353 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004354 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004355 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004356
4357 if &ft == "netrw"
4358" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4359 exe "sil! NetrwKeepj noswapfile b ".bufnum
4360" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004361 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004362" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4363 call s:NetrwEditBuf(bufnum)
4364" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004365 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004366" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004368 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004369 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004370
4371 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004372 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004373
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004374 if line("$") <= 1 && getline(1) == ""
4375 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004376 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004377" 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>"))
4378" 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 +01004379" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4380 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004381
Bram Moolenaar97d62492012-11-15 21:28:22 +01004382 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004383" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004384 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004385 sil NetrwKeepj %d _
4386" 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>"))
4387" 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 +01004388" 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 +00004389 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004390
Bram Moolenaar446cb832008-06-24 21:56:24 +00004391 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004392" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4393" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004394 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004395 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004396 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004397" 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>"))
4398" 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 +01004399" 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 +00004400 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004401
Bram Moolenaar446cb832008-06-24 21:56:24 +00004402 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004403" 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>"))
4404" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4405" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004406 return 1
4407 endif
4408 endif
4409
4410 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4411 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4412 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4413 " med 1 D H
4414 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004415" 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 +00004416 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004417 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004418 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004419
4420 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004421" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4422" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4423 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004424
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004425" 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>"))
4426" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4427" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004428 return 0
4429endfun
4430
4431" ---------------------------------------------------------------------
4432" s:NetrwGetcwd: get the current directory. {{{2
4433" Change backslashes to forward slashes, if any.
4434" If doesc is true, escape certain troublesome characters
4435fun! s:NetrwGetcwd(doesc)
4436" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4437 let curdir= substitute(getcwd(),'\\','/','ge')
4438 if curdir !~ '[\/]$'
4439 let curdir= curdir.'/'
4440 endif
4441 if a:doesc
4442 let curdir= fnameescape(curdir)
4443 endif
4444" call Dret("NetrwGetcwd <".curdir.">")
4445 return curdir
4446endfun
4447
4448" ---------------------------------------------------------------------
4449" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4450fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004451" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4452" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4453 let keepsol= &l:sol
4454 setl nosol
4455
Bram Moolenaar446cb832008-06-24 21:56:24 +00004456 call s:UseBufWinVars()
4457
4458 " insure that w:netrw_liststyle is set up
4459 if !exists("w:netrw_liststyle")
4460 if exists("g:netrw_liststyle")
4461 let w:netrw_liststyle= g:netrw_liststyle
4462 else
4463 let w:netrw_liststyle= s:THINLIST
4464 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004465" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004466 endif
4467
4468 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4469 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004470" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004471 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004472 let dirname= "./"
4473 let curline= getline('.')
4474
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004475 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004476 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004477 let s:netrw_skipbrowse= 1
4478 echo 'Pressing "s" also works'
4479
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004480 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004481 let s:netrw_skipbrowse= 1
4482 echo 'Press "S" to edit sorting sequence'
4483
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004484 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004485 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004486 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004487
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004488 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004489 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490 let s:netrw_skipbrowse= 1
4491 echo 'Pressing "a" also works'
4492
4493 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004494 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004495 endif
4496
4497 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004498" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004499 NetrwKeepj norm! 0
4500 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004501
4502 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004503" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004504 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004505 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4506
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004507 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004508" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004509 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004510 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004511
4512 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004513" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004514 let dirname= getline('.')
4515
4516 if !exists("b:netrw_cpf")
4517 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004518 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 +01004519 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004520" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004521 endif
4522
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004523" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004524 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004525" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4526" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004527 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004528 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004529 else
4530 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004531 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004532 endif
4533 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004534 let eofname= filestart + b:netrw_cpf + 1
4535 if eofname <= col("$")
4536 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004537 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004538 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004539 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004540 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004541 let dirname = @a
4542 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004543" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004545" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004546 endif
4547
4548 " symlinks are indicated by a trailing "@". Remove it before further processing.
4549 let dirname= substitute(dirname,"@$","","")
4550
4551 " executables are indicated by a trailing "*". Remove it before further processing.
4552 let dirname= substitute(dirname,"\*$","","")
4553
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004554 let &l:sol= keepsol
4555
Bram Moolenaar446cb832008-06-24 21:56:24 +00004556" call Dret("s:NetrwGetWord <".dirname.">")
4557 return dirname
4558endfun
4559
4560" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004561" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4562" g:netrw_bufsettings will be used after the listing is produced.
4563" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004564fun! s:NetrwListSettings(islocal)
4565" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004566" 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 +00004567 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004568" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4569 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4570 setl bt=nofile nobl ma nonu nowrap noro nornu
4571 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004572 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004573 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004574 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004575" call Dredir("ls!","s:NetrwListSettings")
4576" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004577 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004578 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004579 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004580 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004581 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004582 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004583 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004584" 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 +00004585" call Dret("s:NetrwListSettings")
4586endfun
4587
4588" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004589" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004590" islocal=0: remote browsing
4591" =1: local browsing
4592fun! s:NetrwListStyle(islocal)
4593" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004594
Bram Moolenaar97d62492012-11-15 21:28:22 +01004595 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004596 let fname = s:NetrwGetWord()
4597 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004598 let svpos = winsaveview()
4599" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004600 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004601" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4602" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4603" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004604
Bram Moolenaar85850f32019-07-19 22:05:51 +02004605 " repoint t:netrw_lexbufnr if appropriate
4606 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4607" call Decho("set repointlexbufnr to true!")
4608 let repointlexbufnr= 1
4609 endif
4610
Bram Moolenaar446cb832008-06-24 21:56:24 +00004611 if w:netrw_liststyle == s:THINLIST
4612 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004613" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004614 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4615
4616 elseif w:netrw_liststyle == s:LONGLIST
4617 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004618" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004619 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4620
4621 elseif w:netrw_liststyle == s:WIDELIST
4622 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004623" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004624 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4625
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004626 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004627" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004628 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4629
4630 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004631 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004632 let g:netrw_liststyle = s:THINLIST
4633 let w:netrw_liststyle = g:netrw_liststyle
4634 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4635 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004636 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004637" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004638
4639 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004640" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4641 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004642 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004643" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004644 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004645" 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 +00004646
4647 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004648" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004649 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004650 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004651
Bram Moolenaar85850f32019-07-19 22:05:51 +02004652 " repoint t:netrw_lexbufnr if appropriate
4653 if exists("repointlexbufnr")
4654 let t:netrw_lexbufnr= bufnr("%")
4655" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4656 endif
4657
Bram Moolenaar13600302014-05-22 18:26:40 +02004658 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004659" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4660 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004661 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004662
4663" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4664endfun
4665
4666" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004667" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4668fun! s:NetrwBannerCtrl(islocal)
4669" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4670
Bram Moolenaar97d62492012-11-15 21:28:22 +01004671 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004672 " toggle the banner (enable/suppress)
4673 let g:netrw_banner= !g:netrw_banner
4674
4675 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004676 let svpos= winsaveview()
4677" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004678 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4679
4680 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004681 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4682 let fname= s:NetrwGetWord()
4683 sil NetrwKeepj $
4684 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4685" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4686 if result <= 0 && exists("w:netrw_bannercnt")
4687 exe "NetrwKeepj ".w:netrw_bannercnt
4688 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004689 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004690 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004691" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4692endfun
4693
4694" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004695" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4696"
4697" No bang: enters files/directories into Netrw's bookmark system
4698" No argument and in netrw buffer:
4699" if there are marked files: bookmark marked files
4700" otherwise : bookmark file/directory under cursor
4701" No argument and not in netrw buffer: bookmarks current open file
4702" Has arguments: globs them individually and bookmarks them
4703"
4704" With bang: deletes files/directories from Netrw's bookmark system
4705fun! s:NetrwBookmark(del,...)
4706" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4707 if a:0 == 0
4708 if &ft == "netrw"
4709 let curbufnr = bufnr("%")
4710
4711 if exists("s:netrwmarkfilelist_{curbufnr}")
4712 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004713" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004714 let svpos = winsaveview()
4715" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004716 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004717 for fname in s:netrwmarkfilelist_{curbufnr}
4718 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4719 endfor
4720 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4721 call s:NetrwUnmarkList(curbufnr,curdir)
4722 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004723" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4724 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004725 else
4726 let fname= s:NetrwGetWord()
4727 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4728 endif
4729
4730 else
4731 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004732" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004733 let fname= expand("%")
4734 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4735 endif
4736
4737 else
4738 " bookmark specified files
4739 " attempts to infer if working remote or local
4740 " by deciding if the current file begins with an url
4741 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004742 let islocal= expand("%") !~ '^\a\{3,}://'
4743" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004744 let i = 1
4745 while i <= a:0
4746 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004747 if v:version > 704 || (v:version == 704 && has("patch656"))
4748 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004749 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004750 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004751 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004752 else
4753 let mbfiles= [a:{i}]
4754 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004755" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004756 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004757" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004758 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4759 endfor
4760 let i= i + 1
4761 endwhile
4762 endif
4763
4764 " update the menu
4765 call s:NetrwBookmarkMenu()
4766
4767" call Dret("s:NetrwBookmark")
4768endfun
4769
4770" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004771" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4772" .2.[cnt] for bookmarks, and
4773" .3.[cnt] for history
4774" (see s:NetrwMenu())
4775fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004776 if !exists("s:netrw_menucnt")
4777 return
4778 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004779" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004780
4781 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004782 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004783 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004784" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004785 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4786 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004787 endif
4788 if !exists("s:netrw_initbookhist")
4789 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004790 endif
4791
4792 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004793 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004794 let cnt= 1
4795 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004796" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004797 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004798
4799 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004800 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004801
4802 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004803 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 +01004804 let cnt= cnt + 1
4805 endfor
4806
4807 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004808
4809 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004810 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004811 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004812 let first = 1
4813 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004814 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004815 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004816 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004817 if exists("g:netrw_dirhist_{cnt}")
4818 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004819" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004820 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4821 endif
4822 let first = 0
4823 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4824 if cnt < 0
4825 let cnt= cnt + g:netrw_dirhistmax
4826 endif
4827 endwhile
4828 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004829
Bram Moolenaar9964e462007-05-05 17:54:07 +00004830 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004831" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004832endfun
4833
4834" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004835" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4836" directory and a new directory name. Also, if the
4837" "new directory name" is actually a file,
4838" NetrwBrowseChgDir() edits the file.
4839fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004840" 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 +01004841" 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 +00004842
Bram Moolenaar97d62492012-11-15 21:28:22 +01004843 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004844 if !exists("b:netrw_curdir")
4845 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4846 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004847 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004848" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4849" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004850" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004851" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004852 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004853 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004854" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004855
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004856 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004857" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004858 call s:SavePosn(s:netrw_posn)
4859 NetrwKeepj call s:NetrwOptionsSave("s:")
4860 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004861 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004862 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004863 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004864 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004865 endif
4866 let newdir = a:newdir
4867 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004868 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004869" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004870" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004871" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004872
4873 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004874" 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 +01004875 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004876" 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 +01004877 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004878 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004879" 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 +01004880 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004881" 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 +02004882 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004883 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004884 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004885 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004886" 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 +01004887 endif
4888 endif
4889" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004890" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004891 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004892
Bram Moolenaar446cb832008-06-24 21:56:24 +00004893 " set up o/s-dependent directory recognition pattern
4894 if has("amiga")
4895 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004896 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004897 let dirpat= '[\/]$'
4898 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004899" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004900
4901 if dirname !~ dirpat
4902 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004903 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004904 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004905" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906 endif
4907
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004908" 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 +01004909 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004910 " ------------------------------
4911 " NetrwBrowseChgDir: edit a file {{{3
4912 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004913" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004914
Bram Moolenaar97d62492012-11-15 21:28:22 +01004915 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004916 let s:rexposn_{bufnr("%")}= winsaveview()
4917" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004918" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4919" 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 +01004920
Bram Moolenaar446cb832008-06-24 21:56:24 +00004921 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004922" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4923" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004924" let newdir = s:NetrwTreePath(s:netrw_treetop)
4925" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004926 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004927 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4928" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4929 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004930 if dirname =~ '/$'
4931 let dirname= dirname.newdir
4932 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004933 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004934 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004935" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4936" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004937 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004938" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004939 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004940 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004941 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004942 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004943" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004944 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004945 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004946" 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 +02004947 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004948 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004949 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004950" " 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 +01004951 if type(g:netrw_browse_split) == 3
4952 " open file in server
4953 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004954" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004955 call s:NetrwServerEdit(a:islocal,dirname)
4956" call Dret("s:NetrwBrowseChgDir")
4957 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004958
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004959 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004960 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004961" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004962 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4963 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004964 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004965 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004966 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004967 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004968
Bram Moolenaar446cb832008-06-24 21:56:24 +00004969 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004970 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004971" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004972 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4973 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004974 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004975 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004976 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004977 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004978
Bram Moolenaar446cb832008-06-24 21:56:24 +00004979 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004980 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004981" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004982 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004983 if !exists("b:netrw_curdir")
4984 let b:netrw_curdir= getcwd()
4985 endif
4986 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004987
Bram Moolenaar446cb832008-06-24 21:56:24 +00004988 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004989 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004990" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004991 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004992 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004993" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004994 return
4995 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004996 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004997
Bram Moolenaar9964e462007-05-05 17:54:07 +00004998 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004999 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005000" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005001 call s:NetrwMenu(0)
5002 " optional change to window
5003 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005004" 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 +02005005 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09005006 " if g:netrw_chgwin is set to one more than the last window, then
5007 " vertically split the last window to make that window available.
5008 let curwin= winnr()
5009 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
5010 vs
5011 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02005012 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005013 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00005014 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005015 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00005016 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005017
Bram Moolenaar9964e462007-05-05 17:54:07 +00005018 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005019
Bram Moolenaar446cb832008-06-24 21:56:24 +00005020 " the point where netrw actually edits the (local) file
5021 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01005022 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005023 if !&mod
5024 " if e the new file would fail due to &mod, then don't change any of the flags
5025 let dolockout= 1
5026 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005027 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005028" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005029 " some like c-^ to return to the last edited file
5030 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005031 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5032 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005033 call s:NetrwEditFile("e","",dirname)
5034" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005035 " COMBAK -- cuc cul related
5036 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005037 if &hidden || &bufhidden == "hide"
5038 " file came from vim's hidden storage. Don't "restore" options with it.
5039 let dorestore= 0
5040 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005041 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005042" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005043 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005044
5045 " handle g:Netrw_funcref -- call external-to-netrw functions
5046 " This code will handle g:Netrw_funcref as an individual function reference
5047 " or as a list of function references. It will ignore anything that's not
5048 " a function reference. See :help Funcref for information about function references.
5049 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005050" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005051 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005052" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005053 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005054 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005055" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005056 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005057 if type(Fncref) == 2
5058 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005059 endif
5060 endfor
5061 endif
5062 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005063 endif
5064
5065 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005066 " ----------------------------------------------------
5067 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5068 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005069" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005070 let dirname = newdir
5071 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005072 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005073 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005074
5075 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005076 " ---------------------------------------------
5077 " NetrwBrowseChgDir: refresh the directory list {{{3
5078 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005079" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005080 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005081 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005082
5083 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005084 " --------------------------------------
5085 " NetrwBrowseChgDir: go up one directory {{{3
5086 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005087" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005088
5089 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5090 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005091" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5092" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005093 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005094 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005095 endif
5096
5097 if has("amiga")
5098 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005099" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005100 if a:islocal
5101 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5102 let dirname= substitute(dirname,'/$','','')
5103 else
5104 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5105 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005106" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005107
Bram Moolenaar8d043172014-01-23 14:24:41 +01005108 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
5109 " windows
5110 if a:islocal
5111 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5112 if dirname == ""
5113 let dirname= '/'
5114 endif
5115 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005116 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005117 endif
5118 if dirname =~ '^\a:$'
5119 let dirname= dirname.'/'
5120 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005121" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005122
Bram Moolenaar446cb832008-06-24 21:56:24 +00005123 else
5124 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005125" 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 +00005126 if a:islocal
5127 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5128 if dirname == ""
5129 let dirname= '/'
5130 endif
5131 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005132 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005133 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005134" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005135 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005136 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005137 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005138
5139 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005140 " --------------------------------------
5141 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5142 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005143" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005144 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5145" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005146 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005147 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005148" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5149 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005150 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005151 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005152" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005153 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005154 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005155" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005156
5157 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005158" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005159 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005160" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005161 let haskey= 1
5162 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005163" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 endif
5165
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005166 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005167" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005168 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005169 if has_key(w:netrw_treedict,treedir."/")
5170 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005171" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005172 let haskey = 1
5173 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005174" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005175 endif
5176 endif
5177
5178 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005179" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005180 if !haskey && treedir =~ '/$'
5181 let treedir= substitute(treedir,'/$','','')
5182 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005183" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005184 let haskey = 1
5185 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005186" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005187 endif
5188 endif
5189
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005190" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005191 if haskey
5192 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005193" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005194 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005195" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5196" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005197 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005198 else
5199 " go down one directory
5200 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005201" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5202" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005203 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005204 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005205" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005206 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005207
5208 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005209 " ----------------------------------------
5210 " NetrwBrowseChgDir: Go down one directory {{{3
5211 " ----------------------------------------
5212 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005213" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005214 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005215 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005216 endif
5217
Bram Moolenaar97d62492012-11-15 21:28:22 +01005218 " --------------------------------------
5219 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5220 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005221 if dorestore
5222 " dorestore is zero'd when a local file was hidden or bufhidden;
5223 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005224" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005225 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005226" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005227" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005228 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005229 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005230" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005231 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005232" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5233" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005234 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005235" 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 +02005236 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005237" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5238" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005239 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005240" 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 +02005241 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005242 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005243 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005244 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005245
Bram Moolenaar446cb832008-06-24 21:56:24 +00005246" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5247 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005248endfun
5249
5250" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005251" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5252" for thin, long, and wide: cursor placed just after banner
5253" for tree, keeps cursor on current filename
5254fun! s:NetrwBrowseUpDir(islocal)
5255" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005256 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5257 " this test needed because occasionally this function seems to be incorrectly called
5258 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005259 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005260 " directories.
5261" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5262 return
5263 endif
5264
Bram Moolenaara6878372014-03-22 21:02:50 +01005265 norm! 0
5266 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005267" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005268 let curline= getline(".")
5269 let swwline= winline() - 1
5270 if exists("w:netrw_treetop")
5271 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005272 elseif exists("b:netrw_curdir")
5273 let w:netrw_treetop= b:netrw_curdir
5274 else
5275 let w:netrw_treetop= getcwd()
5276 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005277 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005278 let curfile = getline(".")
5279 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005280 if a:islocal
5281 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5282 else
5283 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5284 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005285" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5286" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5287 if w:netrw_treetop == '/'
5288 keepj call search('^\M'.curfile,"w")
5289 elseif curfile == '../'
5290 keepj call search('^\M'.curfile,"wb")
5291 else
5292" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5293 while 1
5294 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5295 let treepath= s:NetrwTreePath(w:netrw_treetop)
5296" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5297 if treepath == curpath
5298 break
5299 endif
5300 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005301 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005302
Bram Moolenaara6878372014-03-22 21:02:50 +01005303 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005304" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005305 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005306 if exists("b:netrw_curdir")
5307 let curdir= b:netrw_curdir
5308 else
5309 let curdir= expand(getcwd())
5310 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005311 if a:islocal
5312 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5313 else
5314 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5315 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005316 call s:RestorePosn(s:netrw_posn)
5317 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005318 let curdir= '\<'. escape(curdir, '~'). '/'
5319 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005320 endif
5321" call Dret("s:NetrwBrowseUpDir")
5322endfun
5323
5324" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005325" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005326" given filename; typically this means given their extension.
5327" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005328fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005329 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005330" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005331
Bram Moolenaar91359012019-11-30 17:57:03 +01005332 if a:remote == 0 && isdirectory(a:fname)
5333 " if its really just a local directory, then do a "gf" instead
5334" 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 +01005335" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5336 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005337" call Dret("netrw#BrowseX")
5338 return
5339 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5340 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5341" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5342" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5343" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5344" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5345 norm! gf
5346" call Dret("netrw#BrowseX")
5347 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005348 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005349" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005350
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005351 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5352 let remote = a:remote
5353 else
5354 let remote = 0
5355 endif
5356
Bram Moolenaar97d62492012-11-15 21:28:22 +01005357 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005358 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005359" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005360
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005361 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5362 let awkeep = &aw
5363 set noaw
5364
Bram Moolenaar5c736222010-01-06 20:54:52 +01005365 " special core dump handler
5366 if a:fname =~ '/core\(\.\d\+\)\=$'
5367 if exists("g:Netrw_corehandler")
5368 if type(g:Netrw_corehandler) == 2
5369 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005370" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005371 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005372 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005373 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005374" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005375 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005376 if type(Fncref) == 2
5377 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005378 endif
5379 endfor
5380 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005381" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005382 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005383 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005384 let &aw= awkeep
5385" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005386 return
5387 endif
5388 endif
5389
Bram Moolenaar446cb832008-06-24 21:56:24 +00005390 " set up the filename
5391 " (lower case the extension, make a local copy of a remote file)
5392 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5393 if has("win32") || has("win95") || has("win64") || has("win16")
5394 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005395 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005396 if exten =~ "[\\/]"
5397 let exten= ""
5398 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005399" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005400
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005401 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005402 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005403" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005404 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005405 call netrw#NetRead(3,a:fname)
5406 " attempt to rename tempfile
5407 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005408 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005409" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5410" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005411 if s:netrw_tmpfile != newname && newname != ""
5412 if rename(s:netrw_tmpfile,newname) == 0
5413 " renaming succeeded
5414" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5415 let fname= newname
5416 else
5417 " renaming failed
5418" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5419 let fname= s:netrw_tmpfile
5420 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005421 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005422 let fname= s:netrw_tmpfile
5423 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005424 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005425" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005426 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005427 " special ~ handler for local
5428 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005429" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5430 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005431 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005432 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005433" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5434" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005435
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005436 " set up redirection (avoids browser messages)
5437 " by default, g:netrw_suppress_gx_mesg is true
5438 if g:netrw_suppress_gx_mesg
5439 if &srr =~ "%s"
5440 if (has("win32") || has("win95") || has("win64") || has("win16"))
5441 let redir= substitute(&srr,"%s","nul","")
5442 else
5443 let redir= substitute(&srr,"%s","/dev/null","")
5444 endif
5445 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5446 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005447 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005448 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005449 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005450 else
5451 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005452 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005453" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005454
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005455 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005456 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005457" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005458 if g:netrw_browsex_viewer =~ '\s'
5459 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5460 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5461 let oviewer = ''
5462 let cnt = 1
5463 while !executable(viewer) && viewer != oviewer
5464 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5465 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5466 let cnt = cnt + 1
5467 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005468" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005469 endwhile
5470 else
5471 let viewer = g:netrw_browsex_viewer
5472 let viewopt = ""
5473 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005474" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005475 endif
5476
5477 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005478" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005479 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005480" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005481 let ret= netrwFileHandlers#Invoke(exten,fname)
5482
5483 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005484" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005485 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005486 let ret= v:shell_error
5487
5488 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005489" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005490 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005491 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005492 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005493 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005494 else
5495 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5496 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005497 let ret= v:shell_error
5498
Bram Moolenaar97d62492012-11-15 21:28:22 +01005499 elseif has("win32unix")
5500 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005501" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005502 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005503" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005504 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005505 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005506" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005507 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005508 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005509" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005510 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005511 else
5512 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5513 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005514 let ret= v:shell_error
5515
Bram Moolenaar85850f32019-07-19 22:05:51 +02005516 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005517" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5518 if a:fname =~ '^https\=://'
5519 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5520 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005521" call Decho("fname<".fname.">")
5522" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005523 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5524
5525 else
5526 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5527 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005528 let ret= v:shell_error
5529
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005530 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5531" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5532 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5533 let ret= v:shell_error
5534
5535 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5536" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5537 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5538 let ret= v:shell_error
5539
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005540 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005541" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005542 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005543 let ret= v:shell_error
5544
5545 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005546" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005547 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005548 let ret= v:shell_error
5549
5550 else
5551 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005552" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005553 let ret= netrwFileHandlers#Invoke(exten,fname)
5554 endif
5555
5556 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5557 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005558" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005559 let ret= netrwFileHandlers#Invoke(exten,fname)
5560 endif
5561
Bram Moolenaarc236c162008-07-13 17:41:49 +00005562 " restoring redraw! after external file handlers
5563 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005564
5565 " cleanup: remove temporary file,
5566 " delete current buffer if success with handler,
5567 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005568 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005569 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005570" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005571"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005572" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005573" endif
5574
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005575 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005576 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005577 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005578 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005579 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005580 if use_ctrlo
5581 exe "sil! NetrwKeepj norm! \<c-o>"
5582 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005583 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005584" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005585 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005586 let @@ = ykeep
5587 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005588
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005589" call Dret("netrw#BrowseX")
5590endfun
5591
5592" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005593" netrw#GX: gets word under cursor for gx support {{{2
5594" See also: netrw#BrowseXVis
5595" netrw#BrowseX
5596fun! netrw#GX()
5597" call Dfunc("netrw#GX()")
5598 if &ft == "netrw"
5599 let fname= s:NetrwGetWord()
5600 else
5601 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5602 endif
5603" call Dret("netrw#GX <".fname.">")
5604 return fname
5605endfun
5606
5607" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005608" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5609fun! netrw#BrowseXVis()
5610" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005611 let akeep = @a
5612 norm! gv"ay
5613 let gxfile= @a
5614 let @a = akeep
5615 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005616" call Dret("netrw#BrowseXVis")
5617endfun
5618
5619" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005620" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5621" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5622" to become an unlisted buffer, so in that case don't bwipe it.
5623fun! s:NetrwBufRename(newname)
5624" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5625" call Dredir("ls!","s:NetrwBufRename (before rename)")
5626 let oldbufname= bufname(bufnr("%"))
5627" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5628
5629 if oldbufname != a:newname
5630" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5631 let b:junk= 1
5632" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5633 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005634" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005635 let oldbufnr= bufnr(oldbufname)
5636" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5637" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5638 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5639" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5640 exe "bwipe! ".oldbufnr
5641" else " Decho
5642" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005643" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5644" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5645" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005646 endif
5647" call Dredir("ls!","s:NetrwBufRename (after rename)")
5648" else " Decho
5649" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5650 endif
5651
5652" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5653endfun
5654
5655" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005656" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005657fun! netrw#CheckIfRemote(...)
5658" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5659 if a:0 > 0
5660 let curfile= a:1
5661 else
5662 let curfile= expand("%")
5663 endif
5664" call Decho("curfile<".curfile.">")
5665 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005666" call Dret("netrw#CheckIfRemote 1")
5667 return 1
5668 else
5669" call Dret("netrw#CheckIfRemote 0")
5670 return 0
5671 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005672endfun
5673
5674" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005675" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5676fun! s:NetrwChgPerm(islocal,curdir)
5677" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005678 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005679 call inputsave()
5680 let newperm= input("Enter new permission: ")
5681 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005682 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5683 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5684" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005685 call system(chgperm)
5686 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005687 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005688 endif
5689 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005690 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005691 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005692 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005693" call Dret("s:NetrwChgPerm")
5694endfun
5695
5696" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005697" s:CheckIfKde: checks if kdeinit is running {{{2
5698" Returns 0: kdeinit not running
5699" 1: kdeinit is running
5700fun! s:CheckIfKde()
5701" call Dfunc("s:CheckIfKde()")
5702 " seems kde systems often have gnome-open due to dependencies, even though
5703 " gnome-open's subsidiary display tools are largely absent. Kde systems
5704 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5705 if !exists("s:haskdeinit")
5706 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005707 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005708 if v:shell_error
5709 let s:haskdeinit = 0
5710 endif
5711 else
5712 let s:haskdeinit= 0
5713 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005714" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005715 endif
5716
5717" call Dret("s:CheckIfKde ".s:haskdeinit)
5718 return s:haskdeinit
5719endfun
5720
5721" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005722" s:NetrwClearExplore: clear explore variables (if any) {{{2
5723fun! s:NetrwClearExplore()
5724" call Dfunc("s:NetrwClearExplore()")
5725 2match none
5726 if exists("s:explore_match") |unlet s:explore_match |endif
5727 if exists("s:explore_indx") |unlet s:explore_indx |endif
5728 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5729 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5730 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5731 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5732 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5733 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5734 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5735" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005736" call Dret("s:NetrwClearExplore")
5737endfun
5738
5739" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005740" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5741fun! s:NetrwEditBuf(bufnum)
5742" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5743 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5744" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5745 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5746 else
5747" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005748 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005749 endif
5750" call Dret("s:NetrwEditBuf")
5751endfun
5752
5753" ---------------------------------------------------------------------
5754" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5755" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5756fun! s:NetrwEditFile(cmd,opt,fname)
5757" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5758 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5759" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5760 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5761 else
5762" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5763 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5764 endif
5765" call Dret("s:NetrwEditFile")
5766endfun
5767
5768" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005769" s:NetrwExploreListUniq: {{{2
5770fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005771" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005772
5773 " this assumes that the list is already sorted
5774 let newexplist= []
5775 for member in a:explist
5776 if !exists("uniqmember") || member != uniqmember
5777 let uniqmember = member
5778 let newexplist = newexplist + [ member ]
5779 endif
5780 endfor
5781
Bram Moolenaar15146672011-10-20 22:22:38 +02005782" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005783 return newexplist
5784endfun
5785
5786" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005787" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5788fun! s:NetrwForceChgDir(islocal,newdir)
5789" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005790 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005791 if a:newdir !~ '/$'
5792 " ok, looks like force is needed to get directory-style treatment
5793 if a:newdir =~ '@$'
5794 let newdir= substitute(a:newdir,'@$','/','')
5795 elseif a:newdir =~ '[*=|\\]$'
5796 let newdir= substitute(a:newdir,'.$','/','')
5797 else
5798 let newdir= a:newdir.'/'
5799 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005800" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005801 else
5802 " should already be getting treatment as a directory
5803 let newdir= a:newdir
5804 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005805 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005806 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005807 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005808" call Dret("s:NetrwForceChgDir")
5809endfun
5810
5811" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005812" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005813" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5814" expr : this is the expression to follow the directory. Will use s:ComposePath()
5815" pare =1: remove the current directory from the resulting glob() filelist
5816" =0: leave the current directory in the resulting glob() filelist
5817fun! s:NetrwGlob(direntry,expr,pare)
5818" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005819 if netrw#CheckIfRemote()
5820 keepalt 1sp
5821 keepalt enew
5822 let keep_liststyle = w:netrw_liststyle
5823 let w:netrw_liststyle = s:THINLIST
5824 if s:NetrwRemoteListing() == 0
5825 keepj keepalt %s@/@@
5826 let filelist= getline(1,$)
5827 q!
5828 else
5829 " remote listing error -- leave treedict unchanged
5830 let filelist= w:netrw_treedict[a:direntry]
5831 endif
5832 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005833 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5834 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5835 if a:pare
5836 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5837 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005838 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005839 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5840 if a:pare
5841 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5842 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005843 endif
5844" call Dret("s:NetrwGlob ".string(filelist))
5845 return filelist
5846endfun
5847
5848" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005849" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5850fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005851" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005852 if a:newfile =~ '[/@*=|\\]$'
5853 let newfile= substitute(a:newfile,'.$','','')
5854 else
5855 let newfile= a:newfile
5856 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005857 if a:islocal
5858 call s:NetrwBrowseChgDir(a:islocal,newfile)
5859 else
5860 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5861 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005862" call Dret("s:NetrwForceFile")
5863endfun
5864
5865" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005866" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5867" and switches the hiding mode. The actual hiding is done by
5868" s:NetrwListHide().
5869" g:netrw_hide= 0: show all
5870" 1: show not-hidden files
5871" 2: show hidden files only
5872fun! s:NetrwHide(islocal)
5873" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005874 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005875 let svpos= winsaveview()
5876" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005877
5878 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005879" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5880" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005881
5882 " hide the files in the markfile list
5883 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005884" 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 +00005885 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5886 " remove fname from hiding list
5887 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5888 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5889 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005890" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005891 else
5892 " append fname to hiding list
5893 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5894 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5895 else
5896 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5897 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005898" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005899 endif
5900 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005901 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005902 let g:netrw_hide= 1
5903
5904 else
5905
5906 " switch between show-all/show-not-hidden/show-hidden
5907 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005908 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005909 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005910 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005911 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005912" call Dret("NetrwHide")
5913 return
5914 endif
5915 endif
5916
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005917 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005918" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5919 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005920 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005921" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005922endfun
5923
5924" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005925" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5926fun! s:NetrwHideEdit(islocal)
5927" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5928
5929 let ykeep= @@
5930 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005931 let svpos= winsaveview()
5932" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005933
5934 " get new hiding list from user
5935 call inputsave()
5936 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5937 call inputrestore()
5938 let g:netrw_list_hide= newhide
5939" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5940
5941 " refresh the listing
5942 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5943
5944 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005945" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5946 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005947 let @@= ykeep
5948
5949" call Dret("NetrwHideEdit")
5950endfun
5951
5952" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005953" s:NetrwHidden: invoked by "gh" {{{2
5954fun! s:NetrwHidden(islocal)
5955" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005956 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005957 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005958 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005959" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005960
5961 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005962 " remove .file pattern from hiding list
5963" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005964 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005965 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005966" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005967 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5968 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005969" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005970 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5971 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005972 if g:netrw_list_hide =~ '^,'
5973 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5974 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005975
5976 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005977 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005978" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5979 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005980 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005981" call Dret("s:NetrwHidden")
5982endfun
5983
5984" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005985" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5986fun! s:NetrwHome()
5987 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005988 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005989 else
5990 " go to vim plugin home
5991 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005992 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005993 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005994 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005995 let home= basehome."/.vim"
5996 break
5997 endif
5998 endfor
5999 if home == ""
6000 " just pick the first directory
6001 let home= substitute(&rtp,',.*$','','')
6002 endif
6003 if (has("win32") || has("win95") || has("win64") || has("win16"))
6004 let home= substitute(home,'/','\\','g')
6005 endif
6006 endif
6007 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006008 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006009" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006010 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02006011" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006012 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01006013 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006014" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006015 call mkdir(home)
6016 endif
6017 endif
6018 let g:netrw_home= home
6019 return home
6020endfun
6021
6022" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006023" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6024fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006025 if exists("s:netrwdrag")
6026 return
6027 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006028 if &ft != "netrw"
6029 return
6030 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006031" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006032
Bram Moolenaar97d62492012-11-15 21:28:22 +01006033 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006034 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006035 while getchar(0) != 0
6036 "clear the input stream
6037 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006038 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006039 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006040 let mouse_lnum = v:mouse_lnum
6041 let wlastline = line('w$')
6042 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006043" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6044" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006045 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6046 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006047 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006048" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6049 return
6050 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006051 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006052 " 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 +01006053 " without this test when its disabled.
6054 " 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 +01006055" 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 +01006056 if v:mouse_col > virtcol('.')
6057 let @@= ykeep
6058" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6059 return
6060 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006061
Bram Moolenaar446cb832008-06-24 21:56:24 +00006062 if a:islocal
6063 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006064 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006065 endif
6066 else
6067 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006068 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006069 endif
6070 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006071 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006072" call Dret("s:NetrwLeftmouse")
6073endfun
6074
6075" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006076" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6077fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006078 if &ft != "netrw"
6079 return
6080 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006081" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6082 call s:NetrwMarkFileTgt(a:islocal)
6083" call Dret("s:NetrwCLeftmouse")
6084endfun
6085
6086" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006087" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6088" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006089" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006090" a:islocal=2 : <c-r> used, remote
6091" a:islocal=3 : <c-r> used, local
6092fun! s:NetrwServerEdit(islocal,fname)
6093" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6094 let islocal = a:islocal%2 " =0: remote =1: local
6095 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006096" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006097
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006098 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006099 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006100 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006101" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006102 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006103 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006104 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6105 unlet s:netrw_browse_split_{winnr()}
6106 endif
6107 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6108" call Dret("s:NetrwServerEdit")
6109 return
6110 endif
6111
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006112" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006113 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006114" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006115
6116 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006117" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006118 let srvrname = g:netrw_browse_split[0]
6119 let tabnum = g:netrw_browse_split[1]
6120 let winnum = g:netrw_browse_split[2]
6121
6122 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006123" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006124
6125 if !ctrlr
6126 " user must have closed the server window and the user did not use <c-r>, but
6127 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006128" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006129 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006130 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006131 endif
6132 let g:netrw_browse_split= 0
6133 if exists("s:netrw_browse_split_".winnr())
6134 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6135 endif
6136 call s:NetrwBrowseChgDir(islocal,a:fname)
6137" call Dret("s:NetrwServerEdit")
6138 return
6139
6140 elseif has("win32") && executable("start")
6141 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006142" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006143 call system("start gvim --servername ".srvrname)
6144
6145 else
6146 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006147" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006148 call system("gvim --servername ".srvrname)
6149 endif
6150 endif
6151
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006152" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006153 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6154 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006155 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006156
6157 else
6158
6159 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6160
6161 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006162" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006163 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006164 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006165 endif
6166 let g:netrw_browse_split= 0
6167 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6168" call Dret("s:NetrwServerEdit")
6169 return
6170
6171 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006172" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006173 if has("win32") && executable("start")
6174 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006175" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006176 call system("start gvim --servername ".g:netrw_servername)
6177 else
6178 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006179" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006180 call system("gvim --servername ".g:netrw_servername)
6181 endif
6182 endif
6183 endif
6184
6185 while 1
6186 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006187" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6188 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006189 break
6190 catch /^Vim\%((\a\+)\)\=:E241/
6191 sleep 200m
6192 endtry
6193 endwhile
6194
6195 if exists("g:netrw_browse_split")
6196 if type(g:netrw_browse_split) != 3
6197 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6198 endif
6199 unlet g:netrw_browse_split
6200 endif
6201 let g:netrw_browse_split= [g:netrw_servername,1,1]
6202 endif
6203
6204 else
6205 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6206 endif
6207
6208" call Dret("s:NetrwServerEdit")
6209endfun
6210
6211" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006212" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6213fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006214 if &ft != "netrw"
6215 return
6216 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006217" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006218
Bram Moolenaar8d043172014-01-23 14:24:41 +01006219 let s:ngw= s:NetrwGetWord()
6220 call s:NetrwMarkFile(a:islocal,s:ngw)
6221
6222" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006223endfun
6224
6225" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006226" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6227" Used to mark multiple files.
6228fun! s:NetrwSLeftdrag(islocal)
6229" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6230 if !exists("s:netrwdrag")
6231 let s:netrwdrag = winnr()
6232 if a:islocal
6233 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006234 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006235 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006236 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006237 endif
6238 let ngw = s:NetrwGetWord()
6239 if !exists("s:ngw") || s:ngw != ngw
6240 call s:NetrwMarkFile(a:islocal,ngw)
6241 endif
6242 let s:ngw= ngw
6243" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6244endfun
6245
6246" ---------------------------------------------------------------------
6247" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6248fun! s:NetrwSLeftrelease(islocal)
6249" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6250 if exists("s:netrwdrag")
6251 nunmap <s-leftrelease>
6252 let ngw = s:NetrwGetWord()
6253 if !exists("s:ngw") || s:ngw != ngw
6254 call s:NetrwMarkFile(a:islocal,ngw)
6255 endif
6256 if exists("s:ngw")
6257 unlet s:ngw
6258 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006259 unlet s:netrwdrag
6260 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006261" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006262endfun
6263
6264" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006265" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6266" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006267fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006268" 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 +02006269" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006270 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006271
6272 " 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 +02006273 " How-it-works: take the hiding command, convert it into a range.
6274 " Duplicate characters don't matter.
6275 " Remove all such characters from the '/~@#...890' string.
6276 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006277" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006278 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006279 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006280" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006281
6282 while listhide != ""
6283 if listhide =~ ','
6284 let hide = substitute(listhide,',.*$','','e')
6285 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6286 else
6287 let hide = listhide
6288 let listhide = ""
6289 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006290" 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 +01006291 if g:netrw_sort_by =~ '^[ts]'
6292 if hide =~ '^\^'
6293" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6294 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6295 elseif hide =~ '^\\(\^'
6296 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6297 endif
6298" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6299 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006300
6301 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006302" 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 +00006303 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006304" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006305 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006307" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006308 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006309 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006310" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006311 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006312
Bram Moolenaar446cb832008-06-24 21:56:24 +00006313 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006314 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006315" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006316 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006317" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006318 endif
6319
Bram Moolenaaradc21822011-04-01 18:03:16 +02006320 " remove any blank lines that have somehow remained.
6321 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006322 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006323
Bram Moolenaar97d62492012-11-15 21:28:22 +01006324 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006325" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006326endfun
6327
6328" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006329" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006330" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006331fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006332" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006333
Bram Moolenaar97d62492012-11-15 21:28:22 +01006334 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335 " get name of new directory from user. A bare <CR> will skip.
6336 " if its currently a directory, also request will be skipped, but with
6337 " a message.
6338 call inputsave()
6339 let newdirname= input("Please give directory name: ")
6340 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006341" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006342
6343 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006344 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006345" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006346 return
6347 endif
6348
6349 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006350" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006351
6352 " Local mkdir:
6353 " sanity checks
6354 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006355" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6356 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006357 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006358 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006359 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006360 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006361" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006362 return
6363 endif
6364 if s:FileReadable(fullnewdir)
6365 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006366 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006367 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006368 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006369" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006370 return
6371 endif
6372
6373 " requested new local directory is neither a pre-existing file or
6374 " directory, so make it!
6375 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006376 if has("unix")
6377 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6378 else
6379 call mkdir(fullnewdir,"p")
6380 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006381 else
6382 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006383 if s:NetrwLcd(b:netrw_curdir)
6384" call Dret("s:NetrwMakeDir : lcd failure")
6385 return
6386 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006387" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006388 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006389 if v:shell_error != 0
6390 let @@= ykeep
6391 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 +01006392" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006393 return
6394 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006395 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006396" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006397 if s:NetrwLcd(netrw_origdir)
6398" call Dret("s:NetrwBrowse : lcd failure")
6399 return
6400 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006401 endif
6402 endif
6403
6404 if v:shell_error == 0
6405 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006406" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006407 let svpos= winsaveview()
6408" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006409 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006410" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6411 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006412 elseif !exists("g:netrw_quiet")
6413 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6414 endif
6415" redraw!
6416
6417 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006418 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006419" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006420 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6421 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006422 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006423 if v:shell_error == 0
6424 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006425 let svpos= winsaveview()
6426" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006427 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006428" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6429 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006430 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006431 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006432 endif
6433" redraw!
6434
6435 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006436 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006437 let svpos= winsaveview()
6438" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006439" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006440 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006441" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006442 let remotepath= b:netrw_fname
6443 else
6444 let remotepath= ""
6445 endif
6446 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006447 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006448" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6449 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006450
Bram Moolenaar446cb832008-06-24 21:56:24 +00006451 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006452 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006453 let svpos= winsaveview()
6454" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006455" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006456 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006457" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006458 let remotepath= b:netrw_fname
6459 else
6460 let remotepath= ""
6461 endif
6462 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006463 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006464" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6465 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006466 endif
6467
Bram Moolenaar97d62492012-11-15 21:28:22 +01006468 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006469" call Dret("s:NetrwMakeDir")
6470endfun
6471
6472" ---------------------------------------------------------------------
6473" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6474fun! s:TreeSqueezeDir(islocal)
6475" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6476 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6477 " its a tree-listing style
6478 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006479 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006480 let depth = strchars(substitute(curdepth,' ','','g'))
6481 let srch = -1
6482" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6483" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006484" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006485" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6486 if depth >= 2
6487 NetrwKeepj norm! 0
6488 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6489 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6490" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6491" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6492 elseif depth == 1
6493 NetrwKeepj norm! 0
6494 let treedepthchr= substitute(s:treedepthstring,' ','','')
6495 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6496" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6497 endif
6498 if srch > 0
6499" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6500 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6501 exe srch
6502 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006503 endif
6504" call Dret("s:TreeSqueezeDir")
6505endfun
6506
6507" ---------------------------------------------------------------------
6508" s:NetrwMaps: {{{2
6509fun! s:NetrwMaps(islocal)
6510" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6511
Bram Moolenaar85850f32019-07-19 22:05:51 +02006512 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006513 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006514" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006515 if !hasmapto("<Plug>NetrwReturn")
6516 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006517" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006518 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6519 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006520" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006521 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6522 endif
6523 endif
6524 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006525" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006526 endif
6527
Bram Moolenaar85850f32019-07-19 22:05:51 +02006528 " generate default <Plug> maps {{{3
6529 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006530 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006531 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6532 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6533 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6534 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6535 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6536 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6537 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6538 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6539 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6540 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6541" ---------------------------------------------------------------------
6542" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6543" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6544" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6545" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6546" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6547" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6548" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6549" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6550" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6551" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6552" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6553" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6554" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6555" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6556" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6557" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6558" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6559" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6560" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6561" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6562" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6563" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6564" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6565" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6566" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6567" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6568" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6569" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6570" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6571" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6572" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6573" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6574" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6575" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6576" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6577" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6578" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6579" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6580" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6581" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6582" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6583" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6584" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6585" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6586" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6587" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6588" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6589
Bram Moolenaara6878372014-03-22 21:02:50 +01006590 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006591" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006592 " local normal-mode maps {{{3
6593 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6594 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6595 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6596 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6597 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6598 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6599 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6600 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6601 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6602 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6603 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6604" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006605 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6606 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6607 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006608 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006609 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006610 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6611 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6612 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6613 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006614 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6615 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6616 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6617 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6618 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6619 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6620 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6621 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6622 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6623 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6624 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6625 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6626 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006627 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006628 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006629 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6630 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6631 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6632 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6633 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006634 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006635 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006636 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6637 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006638 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6639 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6640 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006641 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006642 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006643 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6644 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006645 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006646 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006647 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6648 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6649 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006650 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6651 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006652
6653 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 +01006654 if !hasmapto('<Plug>NetrwHideEdit')
6655 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006656 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006657 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006658 if !hasmapto('<Plug>NetrwRefresh')
6659 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006660 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006661 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 +01006662 if s:didstarstar || !mapcheck("<s-down>","n")
6663 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006664 endif
6665 if s:didstarstar || !mapcheck("<s-up>","n")
6666 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006667 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006668 if !hasmapto('<Plug>NetrwTreeSqueeze')
6669 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006670 endif
6671 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006672 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6673 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006674 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6675 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6676 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6677 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6678 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6679 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6680 imap <buffer> <leftmouse> <Plug>ILeftmouse
6681 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006682 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006683 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006684 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006685 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006686 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006687 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
Bram Moolenaara6878372014-03-22 21:02:50 +01006688 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6689 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006690 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006691 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6692 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6693 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6694 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6695 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6696 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6697 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006698 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6699
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006700 " support user-specified maps
6701 call netrw#UserMaps(1)
6702
Bram Moolenaar85850f32019-07-19 22:05:51 +02006703 else
6704 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006705" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006706 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006707 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6708 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6709 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6710 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6711 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6712 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6713 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6714 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6715 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6716 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6717 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6718" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006719 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6720 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6721 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6722 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6723 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6724 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6725 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6726 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006727 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006728 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006729 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6730 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6731 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6732 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6733 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6734 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6735 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6736 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6737 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6738 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6739 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006740 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006741 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006742 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6743 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6744 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6745 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6746 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006747 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6748 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6749 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6750 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006751 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006752 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6753 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006754 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006755 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 +01006756 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6757 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6758 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6759 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6760 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6761 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6762 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6763 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6764 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006765 if !hasmapto('<Plug>NetrwHideEdit')
6766 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006767 endif
6768 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6769 if !hasmapto('<Plug>NetrwRefresh')
6770 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006771 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006772 if !hasmapto('<Plug>NetrwTreeSqueeze')
6773 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006774 endif
6775 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006776
6777 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006778 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006779
6780 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6781 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006782 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6783 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6784 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6785 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
6786 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6787 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6788 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6789 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6790 nmap <middlemouse> <Plug>NetrwMiddlemouse
6791 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6792 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6793 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6794 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006795 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006796 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
Bram Moolenaara6878372014-03-22 21:02:50 +01006797 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6798 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006799 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006800 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6801 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6802 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6803 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6804 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6805 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6806 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006807 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006808
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006809 " support user-specified maps
6810 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006811 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006812
6813" call Dret("s:NetrwMaps")
6814endfun
6815
6816" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006817" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006818" If -buffer, the command is only available from within netrw buffers
6819" Otherwise, the command is available from any window, so long as netrw
6820" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006821fun! s:NetrwCommands(islocal)
6822" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6823
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006824 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6825 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006826 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 +01006827 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006828 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006829 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006830 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006831 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006832 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006833
6834" call Dret("s:NetrwCommands")
6835endfun
6836
6837" ---------------------------------------------------------------------
6838" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6839" glob()ing only works with local files
6840fun! s:NetrwMarkFiles(islocal,...)
6841" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006842 let curdir = s:NetrwGetCurdir(a:islocal)
6843 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006844 while i <= a:0
6845 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006846 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006847 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006848 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006849 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006850 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006851 else
6852 let mffiles= [a:{i}]
6853 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006854" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006855 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006856" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006857 call s:NetrwMarkFile(a:islocal,mffile)
6858 endfor
6859 let i= i + 1
6860 endwhile
6861" call Dret("s:NetrwMarkFiles")
6862endfun
6863
6864" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006865" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006866fun! s:NetrwMarkTarget(...)
6867" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6868 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006869 let curdir = s:NetrwGetCurdir(1)
6870 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006871 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006872 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6873 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006874 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006875" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006876 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006877 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6878 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006879 let svpos = winsaveview()
6880" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006881 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006882" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6883 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006884" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006885endfun
6886
6887" ---------------------------------------------------------------------
6888" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6889" mark and unmark files. If a markfile list exists,
6890" then the rename and delete functions will use it instead
6891" of whatever may happen to be under the cursor at that
6892" moment. When the mouse and gui are available,
6893" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006894"
6895" Creates two lists
6896" s:netrwmarkfilelist -- holds complete paths to all marked files
6897" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6898"
6899" Creates a marked file match string
6900" s:netrwmarfilemtch_# -- used with 2match to display marked files
6901"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006902" Creates a buffer version of islocal
6903" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006904fun! s:NetrwMarkFile(islocal,fname)
6905" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006906" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006907
6908 " sanity check
6909 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006910" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006911 return
6912 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006913 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006914
Bram Moolenaar97d62492012-11-15 21:28:22 +01006915 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006916 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006917 if a:fname =~ '^\a'
6918 let leader= '\<'
6919 else
6920 let leader= ''
6921 endif
6922 if a:fname =~ '\a$'
6923 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6924 else
6925 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6926 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006927
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006928 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006929 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006930" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6931" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6932" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006933 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006934
6935 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006936 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006937" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006938 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006939 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006940
6941 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006942 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006943" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006944 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6945 if s:netrwmarkfilelist_{curbufnr} == []
6946 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006947" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006948 call s:NetrwUnmarkList(curbufnr,curdir)
6949 else
6950 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006951" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006953 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006954 for fname in s:netrwmarkfilelist_{curbufnr}
6955 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006956 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006957 else
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 endif
6960 let first= 0
6961 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006962" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006963 endif
6964 endif
6965
6966 else
6967 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006968" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006970" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006971 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006972 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6973" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006974
6975 " build initial markfile matching pattern
6976 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006977 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006978 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006979 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006980 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006981" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006982 endif
6983
6984 " handle global markfilelist
6985 if exists("s:netrwmarkfilelist")
6986 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6987 if index(s:netrwmarkfilelist,dname) == -1
6988 " append new filename to global markfilelist
6989 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006990" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006991 else
6992 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006993" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6994" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006995 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006996" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006997 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006998" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006999 unlet s:netrwmarkfilelist
7000 endif
7001 endif
7002 else
7003 " initialize new global-directory markfilelist
7004 let s:netrwmarkfilelist= []
7005 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007006" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007007 endif
7008
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007009 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02007010 if has("syntax") && exists("g:syntax_on") && g:syntax_on
7011 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
7012" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
7013 if exists("g:did_drchip_netrwlist_syntax")
7014 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
7015 endif
7016 else
7017" " call Decho("2match none",'~'.expand("<slnum>"))
7018 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01007019 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007020 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007021 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007022" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
7023" 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 +00007024endfun
7025
7026" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007027" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7028" mA: move the argument list to marked file list (tomflist=1)
7029" Uses the global marked file list
7030fun! s:NetrwMarkFileArgList(islocal,tomflist)
7031" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7032
7033 let svpos = winsaveview()
7034" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7035 let curdir = s:NetrwGetCurdir(a:islocal)
7036 let curbufnr = bufnr("%")
7037
7038 if a:tomflist
7039 " mA: move argument list to marked file list
7040 while argc()
7041 let fname= argv(0)
7042" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7043 exe "argdel ".fnameescape(fname)
7044 call s:NetrwMarkFile(a:islocal,fname)
7045 endwhile
7046
7047 else
7048 " ma: move marked file list to argument list
7049 if exists("s:netrwmarkfilelist")
7050
7051 " for every filename in the marked list
7052 for fname in s:netrwmarkfilelist
7053" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7054 exe "argadd ".fnameescape(fname)
7055 endfor " for every file in the marked list
7056
7057 " unmark list and refresh
7058 call s:NetrwUnmarkList(curbufnr,curdir)
7059 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7060" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7061 NetrwKeepj call winrestview(svpos)
7062 endif
7063 endif
7064
7065" call Dret("s:NetrwMarkFileArgList")
7066endfun
7067
7068" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007069" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7070" compress/decompress files using the programs
7071" in g:netrw_compress and g:netrw_uncompress,
7072" using g:netrw_compress_suffix to know which to
7073" do. By default:
7074" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007075" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007076fun! s:NetrwMarkFileCompress(islocal)
7077" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007078 let svpos = winsaveview()
7079" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007080 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007081 let curbufnr = bufnr("%")
7082
Bram Moolenaarff034192013-04-24 18:51:19 +02007083 " sanity check
7084 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007085 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007086" call Dret("s:NetrwMarkFileCompress")
7087 return
7088 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007089" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007090
Bram Moolenaar446cb832008-06-24 21:56:24 +00007091 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007092
7093 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007094 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007095 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007096" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007097 if exists("g:netrw_decompress['".sfx."']")
7098 " fname has a suffix indicating that its compressed; apply associated decompression routine
7099 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007100" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007101 let exe= netrw#WinPath(exe)
7102 if a:islocal
7103 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007104 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007105 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007106 call system(exe." ".fname)
7107 if v:shell_error
7108 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007109 endif
7110 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007111 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7112 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007113 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007114
Bram Moolenaarff034192013-04-24 18:51:19 +02007115 endif
7116 unlet sfx
7117
Bram Moolenaar446cb832008-06-24 21:56:24 +00007118 if exists("exe")
7119 unlet exe
7120 elseif a:islocal
7121 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007122 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007123 if v:shell_error
7124 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7125 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007126 else
7127 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007128 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007129 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007130 endfor " for every file in the marked list
7131
Bram Moolenaar446cb832008-06-24 21:56:24 +00007132 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007133 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007134" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7135 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007136 endif
7137" call Dret("s:NetrwMarkFileCompress")
7138endfun
7139
7140" ---------------------------------------------------------------------
7141" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7142" If no marked files, then set up directory as the
7143" target. Currently does not support copying entire
7144" directories. Uses the local-buffer marked file list.
7145" Returns 1=success (used by NetrwMarkFileMove())
7146" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007147fun! s:NetrwMarkFileCopy(islocal,...)
7148" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7149
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007150 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007151 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007152 if b:netrw_curdir !~ '/$'
7153 if !exists("b:netrw_curdir")
7154 let b:netrw_curdir= curdir
7155 endif
7156 let b:netrw_curdir= b:netrw_curdir."/"
7157 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007158
Bram Moolenaarff034192013-04-24 18:51:19 +02007159 " sanity check
7160 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007161 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007162" call Dret("s:NetrwMarkFileCopy")
7163 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007164 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007165" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007166
Bram Moolenaar446cb832008-06-24 21:56:24 +00007167 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007168 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007169" call Dret("s:NetrwMarkFileCopy 0")
7170 return 0
7171 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007172" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007173
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007174 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007175 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007176" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007177 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007178 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7179" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7180 return
7181 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007182
7183 " copy marked files while within the same directory (ie. allow renaming)
7184 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7185 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7186 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007187" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007188 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007189 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7190 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007191" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007192 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007193 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007194 let oldname = a:1
7195 else
7196 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007197" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007198 let s:recursive= 1
7199 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7200 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7201 if ret == 0
7202 break
7203 endif
7204 endfor
7205 unlet s:recursive
7206 call s:NetrwUnmarkList(curbufnr,curdir)
7207" call Dret("s:NetrwMarkFileCopy ".ret)
7208 return ret
7209 endif
7210
7211 call inputsave()
7212 let newname= input("Copy ".oldname." to : ",oldname,"file")
7213 call inputrestore()
7214 if newname == ""
7215" call Dret("s:NetrwMarkFileCopy 0")
7216 return 0
7217 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007218 let args= s:ShellEscape(oldname)
7219 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007220 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007221 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7222 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007223 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007224 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7225 let args= substitute(args,'/','\\','g')
7226 let tgt = substitute(tgt, '/','\\','g')
7227 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007228 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7229 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7230 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7231 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7232" call Decho("args <".args.">",'~'.expand("<slnum>"))
7233" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007234 if isdirectory(s:NetrwFile(args))
7235" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007236 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007237" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007238 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7239 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7240 " contents to a target. One must append the source directory name to the target to get xcopy to
7241 " do the right thing.
7242 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007243" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007244 endif
7245 else
7246 let copycmd= g:netrw_localcopycmd
7247 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007248 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007249 let copycmd = substitute(copycmd,'\s.*$','','')
7250 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007251 let copycmd = netrw#WinPath(copycmd).copycmdargs
7252 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007253 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007254 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007255" call Decho("args <".args.">",'~'.expand("<slnum>"))
7256" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7257" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7258" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007259 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007260 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007261 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007262 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 +01007263 else
7264 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7265 endif
7266" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007267 return 0
7268 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007269
7270 elseif a:islocal && !s:netrwmftgt_islocal
7271 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007272" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007273 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007274
7275 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007276 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007277" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007278 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279
7280 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007281 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007282" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007283 let curdir = getcwd()
7284 let tmpdir = s:GetTempfile("")
7285 if tmpdir !~ '/'
7286 let tmpdir= curdir."/".tmpdir
7287 endif
7288 if exists("*mkdir")
7289 call mkdir(tmpdir)
7290 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007291 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007292 if v:shell_error != 0
7293 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 +01007294" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007295 return
7296 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007297 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007298 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007299 if s:NetrwLcd(tmpdir)
7300" call Dret("s:NetrwMarkFileCopy : lcd failure")
7301 return
7302 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007303 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007304 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007305 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007306 if getcwd() == tmpdir
7307 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007308 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007309 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007310 if s:NetrwLcd(curdir)
7311" call Dret("s:NetrwMarkFileCopy : lcd failure")
7312 return
7313 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007314 if delete(tmpdir,"d")
7315 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007316 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007317 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007318 if s:NetrwLcd(curdir)
7319" call Dret("s:NetrwMarkFileCopy : lcd failure")
7320 return
7321 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007322 endif
7323 endif
7324 endif
7325
7326 " -------
7327 " cleanup
7328 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007329" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007330 " remove markings from local buffer
7331 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007332" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7333" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7334" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7335" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7336" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7337" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7338 if exists("s:recursive")
7339" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7340 else
7341" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007342 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007343 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007344 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007345 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007346 else
7347 " refresh local and targets for fast browsing
7348 if !exists("s:recursive")
7349 " remove markings from local buffer
7350" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7351 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7352 endif
7353
7354 " refresh buffers
7355 if s:netrwmftgt_islocal
7356" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7357 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7358 endif
7359 if a:islocal && s:netrwmftgt != curdir
7360" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7361 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7362 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007363 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007364
Bram Moolenaar446cb832008-06-24 21:56:24 +00007365" call Dret("s:NetrwMarkFileCopy 1")
7366 return 1
7367endfun
7368
7369" ---------------------------------------------------------------------
7370" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7371" invoke vim's diff mode on the marked files.
7372" Either two or three files can be so handled.
7373" Uses the global marked file list.
7374fun! s:NetrwMarkFileDiff(islocal)
7375" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7376 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007377
Bram Moolenaarff034192013-04-24 18:51:19 +02007378 " sanity check
7379 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007380 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007381" call Dret("s:NetrwMarkFileDiff")
7382 return
7383 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007384 let curdir= s:NetrwGetCurdir(a:islocal)
7385" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007386
Bram Moolenaara6878372014-03-22 21:02:50 +01007387 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007388 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007389 for fname in s:netrwmarkfilelist
7390 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007391 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007392" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007393 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007394 diffthis
7395 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007396 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007397" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007398 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007399 diffthis
7400 else
7401 break
7402 endif
7403 endfor
7404 call s:NetrwUnmarkList(curbufnr,curdir)
7405 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007406
Bram Moolenaar446cb832008-06-24 21:56:24 +00007407" call Dret("s:NetrwMarkFileDiff")
7408endfun
7409
7410" ---------------------------------------------------------------------
7411" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7412" Uses global markfilelist
7413fun! s:NetrwMarkFileEdit(islocal)
7414" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7415
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007416 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007417 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007418
7419 " sanity check
7420 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007421 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007422" call Dret("s:NetrwMarkFileEdit")
7423 return
7424 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007425" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007426
Bram Moolenaar446cb832008-06-24 21:56:24 +00007427 if exists("s:netrwmarkfilelist_{curbufnr}")
7428 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007429 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007430 " unmark markedfile list
7431" call s:NetrwUnmarkList(curbufnr,curdir)
7432 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007433" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007434 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007435 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007436 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007437
Bram Moolenaar446cb832008-06-24 21:56:24 +00007438" call Dret("s:NetrwMarkFileEdit")
7439endfun
7440
7441" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007442" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007443fun! s:NetrwMarkFileQFEL(islocal,qfel)
7444" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7445 call s:NetrwUnmarkAll()
7446 let curbufnr= bufnr("%")
7447
7448 if !empty(a:qfel)
7449 for entry in a:qfel
7450 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007451" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007452 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007453" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007454 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7455 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7456 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7457 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007458" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007459 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7460 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007461" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007462 endif
7463 endfor
7464 echo "(use me to edit marked files)"
7465 else
7466 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7467 endif
7468
7469" call Dret("s:NetrwMarkFileQFEL")
7470endfun
7471
7472" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007473" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7474" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7475" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7476fun! s:NetrwMarkFileExe(islocal,enbloc)
7477" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007478 let svpos = winsaveview()
7479" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007480 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007481 let curbufnr = bufnr("%")
7482
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 if a:enbloc == 0
7484 " individually apply command to files, one at a time
7485 " sanity check
7486 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7487 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7488" call Dret("s:NetrwMarkFileExe")
7489 return
7490 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007491" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007492
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007493 if exists("s:netrwmarkfilelist_{curbufnr}")
7494 " get the command
7495 call inputsave()
7496 let cmd= input("Enter command: ","","file")
7497 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007498" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007499 if cmd == ""
7500" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7501 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007502 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007503
7504 " apply command to marked files, individually. Substitute: filename -> %
7505 " If no %, then append a space and the filename to the command
7506 for fname in s:netrwmarkfilelist_{curbufnr}
7507 if a:islocal
7508 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007509 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007510 endif
7511 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007512 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007513 endif
7514 if cmd =~ '%'
7515 let xcmd= substitute(cmd,'%',fname,'g')
7516 else
7517 let xcmd= cmd.' '.fname
7518 endif
7519 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007520" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007521 let ret= system(xcmd)
7522 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007523" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007524 let ret= s:RemoteSystem(xcmd)
7525 endif
7526 if v:shell_error < 0
7527 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7528 break
7529 else
7530 echo ret
7531 endif
7532 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007533
7534 " unmark marked file list
7535 call s:NetrwUnmarkList(curbufnr,curdir)
7536
7537 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007538 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007539" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7540 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007541 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007542 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007543 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007544
7545 else " apply command to global list of files, en bloc
7546
7547 call inputsave()
7548 let cmd= input("Enter command: ","","file")
7549 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007550" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007551 if cmd == ""
7552" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7553 return
7554 endif
7555 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007556 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007557 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007558 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007559 endif
7560 if a:islocal
7561 call system(cmd)
7562 if v:shell_error < 0
7563 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7564 endif
7565 else
7566 let ret= s:RemoteSystem(cmd)
7567 endif
7568 call s:NetrwUnmarkAll()
7569
7570 " refresh the listing
7571 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007572" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7573 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007574
7575 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007576
Bram Moolenaar446cb832008-06-24 21:56:24 +00007577" call Dret("s:NetrwMarkFileExe")
7578endfun
7579
7580" ---------------------------------------------------------------------
7581" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7582" as the marked file(s) (toggles suffix presence)
7583" Uses the local marked file list.
7584fun! s:NetrwMarkHideSfx(islocal)
7585" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007586 let svpos = winsaveview()
7587" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007588 let curbufnr = bufnr("%")
7589
7590 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7591 if exists("s:netrwmarkfilelist_{curbufnr}")
7592
7593 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007594" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007595 " construct suffix pattern
7596 if fname =~ '\.'
7597 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7598 else
7599 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7600 endif
7601 " determine if its in the hiding list or not
7602 let inhidelist= 0
7603 if g:netrw_list_hide != ""
7604 let itemnum = 0
7605 let hidelist= split(g:netrw_list_hide,',')
7606 for hidepat in hidelist
7607 if sfxpat == hidepat
7608 let inhidelist= 1
7609 break
7610 endif
7611 let itemnum= itemnum + 1
7612 endfor
7613 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007614" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007615 if inhidelist
7616 " remove sfxpat from list
7617 call remove(hidelist,itemnum)
7618 let g:netrw_list_hide= join(hidelist,",")
7619 elseif g:netrw_list_hide != ""
7620 " append sfxpat to non-empty list
7621 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7622 else
7623 " set hiding list to sfxpat
7624 let g:netrw_list_hide= sfxpat
7625 endif
7626 endfor
7627
7628 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007629 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007630" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7631 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007632 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007633 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007634 endif
7635
7636" call Dret("s:NetrwMarkHideSfx")
7637endfun
7638
7639" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007640" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007641" Uses the local marked-file list.
7642fun! s:NetrwMarkFileVimCmd(islocal)
7643" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007644 let svpos = winsaveview()
7645" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007646 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007647 let curbufnr = bufnr("%")
7648
Bram Moolenaarff034192013-04-24 18:51:19 +02007649 " sanity check
7650 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007651 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007652" call Dret("s:NetrwMarkFileVimCmd")
7653 return
7654 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007655" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007656
Bram Moolenaar15146672011-10-20 22:22:38 +02007657 if exists("s:netrwmarkfilelist_{curbufnr}")
7658 " get the command
7659 call inputsave()
7660 let cmd= input("Enter vim command: ","","file")
7661 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007662" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007663 if cmd == ""
7664" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7665 return
7666 endif
7667
7668 " apply command to marked files. Substitute: filename -> %
7669 " If no %, then append a space and the filename to the command
7670 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007671" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007672 if a:islocal
7673 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007674 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007675" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007676 exe cmd
7677 exe "sil! keepalt wq!"
7678 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007679" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007680 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007681 endif
7682 endfor
7683
7684 " unmark marked file list
7685 call s:NetrwUnmarkList(curbufnr,curdir)
7686
7687 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007688 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007689" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7690 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007691 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007692 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007693 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007694
Bram Moolenaar15146672011-10-20 22:22:38 +02007695" call Dret("s:NetrwMarkFileVimCmd")
7696endfun
7697
7698" ---------------------------------------------------------------------
7699" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7700" as the marked file(s) (toggles suffix presence)
7701" Uses the local marked file list.
7702fun! s:NetrwMarkHideSfx(islocal)
7703" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007704 let svpos = winsaveview()
7705" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007706 let curbufnr = bufnr("%")
7707
7708 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7709 if exists("s:netrwmarkfilelist_{curbufnr}")
7710
7711 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007712" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007713 " construct suffix pattern
7714 if fname =~ '\.'
7715 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7716 else
7717 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7718 endif
7719 " determine if its in the hiding list or not
7720 let inhidelist= 0
7721 if g:netrw_list_hide != ""
7722 let itemnum = 0
7723 let hidelist= split(g:netrw_list_hide,',')
7724 for hidepat in hidelist
7725 if sfxpat == hidepat
7726 let inhidelist= 1
7727 break
7728 endif
7729 let itemnum= itemnum + 1
7730 endfor
7731 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007732" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007733 if inhidelist
7734 " remove sfxpat from list
7735 call remove(hidelist,itemnum)
7736 let g:netrw_list_hide= join(hidelist,",")
7737 elseif g:netrw_list_hide != ""
7738 " append sfxpat to non-empty list
7739 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7740 else
7741 " set hiding list to sfxpat
7742 let g:netrw_list_hide= sfxpat
7743 endif
7744 endfor
7745
7746 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007747 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007748" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7749 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007750 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007751 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007752 endif
7753
7754" call Dret("s:NetrwMarkHideSfx")
7755endfun
7756
7757" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007758" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7759" Uses the global markfilelist
7760fun! s:NetrwMarkFileGrep(islocal)
7761" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007762 let svpos = winsaveview()
7763" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007764 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007765 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007766
7767 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007768" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007769 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007770" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007771 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007772 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007773" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007774 let netrwmarkfilelist= "*"
7775 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007776
Bram Moolenaarff034192013-04-24 18:51:19 +02007777 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007778" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007779 call inputsave()
7780 let pat= input("Enter pattern: ","")
7781 call inputrestore()
7782 let patbang = ""
7783 if pat =~ '^!'
7784 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007785 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007786 endif
7787 if pat =~ '^\i'
7788 let pat = escape(pat,'/')
7789 let pat = '/'.pat.'/'
7790 else
7791 let nonisi = pat[0]
7792 endif
7793
7794 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007795" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007796 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007797 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007798 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007799 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007800" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7801 return
7802 endtry
7803 echo "(use :cn, :cp to navigate, :Rex to return)"
7804
7805 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007806" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7807 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007808
7809 if exists("nonisi")
7810 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007811" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007812 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007813 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007814 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007815 endif
7816
7817" call Dret("s:NetrwMarkFileGrep")
7818endfun
7819
7820" ---------------------------------------------------------------------
7821" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7822" uses the global marked file list
7823" s:netrwmfloc= 0: target directory is remote
7824" = 1: target directory is local
7825fun! s:NetrwMarkFileMove(islocal)
7826" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007827 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007828 let curbufnr = bufnr("%")
7829
7830 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007831 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007832 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007833" call Dret("s:NetrwMarkFileMove")
7834 return
7835 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007836" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007837
Bram Moolenaar446cb832008-06-24 21:56:24 +00007838 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007839 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007840" call Dret("s:NetrwMarkFileCopy 0")
7841 return 0
7842 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007844
7845 if a:islocal && s:netrwmftgt_islocal
7846 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007847" call Decho("move from local to local",'~'.expand("<slnum>"))
7848" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007849 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007850 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7851" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7852 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007853 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007854 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007855" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007856 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007857 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007858" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007859 if g:netrw_localmovecmd =~ '\s'
7860 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7861 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7862 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007863" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007864 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007865 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007866" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007867 endif
7868 else
7869 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007870" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007871 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007872 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007873 if g:netrw_keepdir
7874 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7875 let fname= b:netrw_curdir."/".fname
7876 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007877 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7878 let fname= substitute(fname,'/','\\','g')
7879 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007880" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007881 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007882 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007883 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007884 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 +01007885 else
7886 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7887 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007888 break
7889 endif
7890 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007891
7892 elseif a:islocal && !s:netrwmftgt_islocal
7893 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007894" call Decho("move from local to remote",'~'.expand("<slnum>"))
7895" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007896 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007897 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007898" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007899 for fname in mflist
7900 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7901 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7902 endfor
7903 unlet mflist
7904
7905 elseif !a:islocal && s:netrwmftgt_islocal
7906 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007907" call Decho("move from remote to local",'~'.expand("<slnum>"))
7908" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007910 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007911" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007912 for fname in mflist
7913 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7914 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7915 endfor
7916 unlet mflist
7917
7918 elseif !a:islocal && !s:netrwmftgt_islocal
7919 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007920" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7921" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007922 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007923 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007924" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007925 for fname in mflist
7926 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7927 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7928 endfor
7929 unlet mflist
7930 endif
7931
7932 " -------
7933 " cleanup
7934 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007935" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007936
7937 " remove markings from local buffer
7938 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7939
7940 " refresh buffers
7941 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007942" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007943 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007944 endif
7945 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007946" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007947 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007948 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007949 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007950" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007951 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007952 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007953
Bram Moolenaar446cb832008-06-24 21:56:24 +00007954" call Dret("s:NetrwMarkFileMove")
7955endfun
7956
7957" ---------------------------------------------------------------------
7958" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7959" using the hardcopy command. Local marked-file list only.
7960fun! s:NetrwMarkFilePrint(islocal)
7961" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7962 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007963
7964 " sanity check
7965 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007966 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007967" call Dret("s:NetrwMarkFilePrint")
7968 return
7969 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007970" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7971 let curdir= s:NetrwGetCurdir(a:islocal)
7972
Bram Moolenaar446cb832008-06-24 21:56:24 +00007973 if exists("s:netrwmarkfilelist_{curbufnr}")
7974 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007975 call s:NetrwUnmarkList(curbufnr,curdir)
7976 for fname in netrwmarkfilelist
7977 if a:islocal
7978 if g:netrw_keepdir
7979 let fname= s:ComposePath(curdir,fname)
7980 endif
7981 else
7982 let fname= curdir.fname
7983 endif
7984 1split
7985 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007986" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007987 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007988" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007989 hardcopy
7990 q
7991 endfor
7992 2match none
7993 endif
7994" call Dret("s:NetrwMarkFilePrint")
7995endfun
7996
7997" ---------------------------------------------------------------------
7998" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7999" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02008000" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00008001fun! s:NetrwMarkFileRegexp(islocal)
8002" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
8003
8004 " get the regular expression
8005 call inputsave()
8006 let regexp= input("Enter regexp: ","","file")
8007 call inputrestore()
8008
8009 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008010 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008011" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008012 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008013" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008014 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008015 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008016 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008017 else
8018 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008019 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008020 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008021" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008022
8023 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008024 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008025 if fname =~ '^'.fnameescape(curdir)
8026" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8027 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8028 else
8029" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8030 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8031 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008032 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008033
8034 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008035" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008036
8037 " convert displayed listing into a filelist
8038 let eikeep = &ei
8039 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008040 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008041 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008042" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008043 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008044 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008045 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008046 sil NetrwKeepj norm! "ap
8047 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008049 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008050 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008052 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008053 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008054 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008055 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008056 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008057 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008058 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8059 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008060 call histdel("/",-1)
8061 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008062 endif
8063 " convert regexp into the more usual glob-style format
8064 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008065" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008066 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008067 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008068 let filelist= getline(1,line("$"))
8069 q!
8070 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008071 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008072 endfor
8073 unlet filelist
8074 let @a = areg
8075 let &ei = eikeep
8076 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008077 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008078
8079" call Dret("s:NetrwMarkFileRegexp")
8080endfun
8081
8082" ---------------------------------------------------------------------
8083" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8084" Uses the local marked file list.
8085fun! s:NetrwMarkFileSource(islocal)
8086" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8087 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008088
8089 " sanity check
8090 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008091 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008092" call Dret("s:NetrwMarkFileSource")
8093 return
8094 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008095" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8096 let curdir= s:NetrwGetCurdir(a:islocal)
8097
Bram Moolenaar446cb832008-06-24 21:56:24 +00008098 if exists("s:netrwmarkfilelist_{curbufnr}")
8099 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008100 call s:NetrwUnmarkList(curbufnr,curdir)
8101 for fname in netrwmarkfilelist
8102 if a:islocal
8103 if g:netrw_keepdir
8104 let fname= s:ComposePath(curdir,fname)
8105 endif
8106 else
8107 let fname= curdir.fname
8108 endif
8109 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008110" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008111 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008112 endfor
8113 2match none
8114 endif
8115" call Dret("s:NetrwMarkFileSource")
8116endfun
8117
8118" ---------------------------------------------------------------------
8119" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8120" Uses the global markfilelist
8121fun! s:NetrwMarkFileTag(islocal)
8122" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008123 let svpos = winsaveview()
8124" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008125 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008126 let curbufnr = bufnr("%")
8127
Bram Moolenaarff034192013-04-24 18:51:19 +02008128 " sanity check
8129 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008130 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008131" call Dret("s:NetrwMarkFileTag")
8132 return
8133 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008134" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008135
Bram Moolenaar446cb832008-06-24 21:56:24 +00008136 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008137" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8138 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008139 call s:NetrwUnmarkAll()
8140
8141 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008142
8143" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8144 call system(g:netrw_ctags." ".netrwmarkfilelist)
8145 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008146 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8147 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008148
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008150 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008151 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008152 let curdir= b:netrw_curdir
8153 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008154 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008155 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008156" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008157 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008158 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008159 wq!
8160 endif
8161 2match none
8162 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008163" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8164 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008165 endif
8166
8167" call Dret("s:NetrwMarkFileTag")
8168endfun
8169
8170" ---------------------------------------------------------------------
8171" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008172" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008173" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008174" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008175" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008176fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008177" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8178 let svpos = winsaveview()
8179" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008180 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008181 let hadtgt = exists("s:netrwmftgt")
8182 if !exists("w:netrw_bannercnt")
8183 let w:netrw_bannercnt= b:netrw_bannercnt
8184 endif
8185
8186 " set up target
8187 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008189 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8190 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008192 unlet s:netrwmftgt s:netrwmftgt_islocal
8193 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008194 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008195 endif
8196 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008197" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8198 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008199" call Dret("s:NetrwMarkFileTgt : removed target")
8200 return
8201 else
8202 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008203" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008204 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008205
8206 else
8207 " get word under cursor.
8208 " * If directory, use it for the target.
8209 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008210" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008211 let curword= s:NetrwGetWord()
8212 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008213 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008214 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008215" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008216 elseif !a:islocal && tgtdir =~ '/$'
8217 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008218" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008219 else
8220 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008221" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008222 endif
8223 endif
8224 if a:islocal
8225 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8226 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008227" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008228 endif
8229 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008230 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008231 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8232 endif
8233 let s:netrwmftgt_islocal= a:islocal
8234
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008235 " need to do refresh so that the banner will be updated
8236 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008237 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008238" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008239 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008240 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008241" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008242 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008243 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8244 else
8245 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8246 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008247" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8248 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008249 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008250 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008251 endif
8252
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008253" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8254" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008255" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8256endfun
8257
8258" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008259" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8260fun! s:NetrwGetCurdir(islocal)
8261" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8262
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008263 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008264 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8265" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8266 elseif !exists("b:netrw_curdir")
8267 let b:netrw_curdir= getcwd()
8268" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8269 endif
8270
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008271" 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 +01008272 if b:netrw_curdir !~ '\<\a\{3,}://'
8273 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008274" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008275 if g:netrw_keepdir == 0
8276 call s:NetrwLcd(curdir)
8277 endif
8278 endif
8279
8280" call Dret("s:NetrwGetCurdir <".curdir.">")
8281 return b:netrw_curdir
8282endfun
8283
8284" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008285" s:NetrwOpenFile: query user for a filename and open it {{{2
8286fun! s:NetrwOpenFile(islocal)
8287" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008288 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008289 call inputsave()
8290 let fname= input("Enter filename: ")
8291 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008292" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8293
8294 " determine if Lexplore is in use
8295 if exists("t:netrw_lexbufnr")
8296 " check if t:netrw_lexbufnr refers to a netrw window
8297" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8298 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8299 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8300" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8301 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8302 exe "NetrwKeepj e ".fnameescape(fname)
8303 let @@= ykeep
8304" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8305 endif
8306 endif
8307
8308 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008309 if fname !~ '[/\\]'
8310 if exists("b:netrw_curdir")
8311 if exists("g:netrw_quiet")
8312 let netrw_quiet_keep = g:netrw_quiet
8313 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008314 let g:netrw_quiet = 1
8315 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008316 let s:rexposn_{bufnr("%")}= winsaveview()
8317" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008318 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008319 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008320 else
8321 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8322 endif
8323 if exists("netrw_quiet_keep")
8324 let g:netrw_quiet= netrw_quiet_keep
8325 else
8326 unlet g:netrw_quiet
8327 endif
8328 endif
8329 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008330 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008331 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008332 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008333" call Dret("s:NetrwOpenFile")
8334endfun
8335
8336" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008337" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8338" For the mapping to this function be made via
8339" netrwPlugin, you'll need to have had
8340" g:netrw_usetab set to non-zero.
8341fun! netrw#Shrink()
8342" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8343 let curwin = winnr()
8344 let wiwkeep = &wiw
8345 set wiw=1
8346
8347 if &ft == "netrw"
8348 if winwidth(0) > g:netrw_wiw
8349 let t:netrw_winwidth= winwidth(0)
8350 exe "vert resize ".g:netrw_wiw
8351 wincmd l
8352 if winnr() == curwin
8353 wincmd h
8354 endif
8355" call Decho("vert resize 0",'~'.expand("<slnum>"))
8356 else
8357 exe "vert resize ".t:netrw_winwidth
8358" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8359 endif
8360
8361 elseif exists("t:netrw_lexbufnr")
8362 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8363 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8364 let t:netrw_winwidth= winwidth(0)
8365 exe "vert resize ".g:netrw_wiw
8366 wincmd l
8367 if winnr() == curwin
8368 wincmd h
8369 endif
8370" call Decho("vert resize 0",'~'.expand("<slnum>"))
8371 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8372 exe "vert resize ".t:netrw_winwidth
8373" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8374 else
8375 call netrw#Lexplore(0,0)
8376 endif
8377
8378 else
8379 call netrw#Lexplore(0,0)
8380 endif
8381 let wiw= wiwkeep
8382
8383" call Dret("netrw#Shrink")
8384endfun
8385
8386" ---------------------------------------------------------------------
8387" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8388fun! s:NetSortSequence(islocal)
8389" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8390
8391 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008392 let svpos= winsaveview()
8393" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008394 call inputsave()
8395 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8396 call inputrestore()
8397
8398 " refresh the listing
8399 let g:netrw_sort_sequence= newsortseq
8400 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008401" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8402 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008403 let @@= ykeep
8404
8405" call Dret("NetSortSequence")
8406endfun
8407
8408" ---------------------------------------------------------------------
8409" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8410" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008411" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008412fun! s:NetrwUnmarkList(curbufnr,curdir)
8413" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8414
8415 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008416 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008417 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8418 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8419 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8420 call remove(s:netrwmarkfilelist,idx) " remove from global list
8421 endfor
8422 if s:netrwmarkfilelist == []
8423 unlet s:netrwmarkfilelist
8424 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008425
Bram Moolenaar446cb832008-06-24 21:56:24 +00008426 " getting rid of the local marked-file lists is easy
8427 unlet s:netrwmarkfilelist_{a:curbufnr}
8428 endif
8429 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8430 unlet s:netrwmarkfilemtch_{a:curbufnr}
8431 endif
8432 2match none
8433" call Dret("s:NetrwUnmarkList")
8434endfun
8435
8436" ---------------------------------------------------------------------
8437" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8438fun! s:NetrwUnmarkAll()
8439" call Dfunc("s:NetrwUnmarkAll()")
8440 if exists("s:netrwmarkfilelist")
8441 unlet s:netrwmarkfilelist
8442 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008443 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008444 2match none
8445" call Dret("s:NetrwUnmarkAll")
8446endfun
8447
8448" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008449" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008450fun! s:NetrwUnmarkAll2()
8451" call Dfunc("s:NetrwUnmarkAll2()")
8452 redir => netrwmarkfilelist_let
8453 let
8454 redir END
8455 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008456 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008457 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8458 for flist in netrwmarkfilelist_list
8459 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8460 unlet s:netrwmarkfilelist_{curbufnr}
8461 unlet s:netrwmarkfilemtch_{curbufnr}
8462 endfor
8463" call Dret("s:NetrwUnmarkAll2")
8464endfun
8465
8466" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008467" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8468"
8469" Marked files are in two types of lists:
8470" s:netrwmarkfilelist -- holds complete paths to all marked files
8471" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8472"
8473" Marked files suitable for use with 2match are in:
8474" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008475fun! s:NetrwUnMarkFile(islocal)
8476" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008477 let svpos = winsaveview()
8478" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008479 let curbufnr = bufnr("%")
8480
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008481 " unmark marked file list
8482 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8483 if exists("s:netrwmarkfilelist")
8484" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008485 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008486 endif
8487
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008488 let ibuf= 1
8489 while ibuf < bufnr("$")
8490 if exists("s:netrwmarkfilelist_".ibuf)
8491 unlet s:netrwmarkfilelist_{ibuf}
8492 unlet s:netrwmarkfilemtch_{ibuf}
8493 endif
8494 let ibuf = ibuf + 1
8495 endwhile
8496 2match none
8497
Bram Moolenaar446cb832008-06-24 21:56:24 +00008498" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008499"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8500call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008501" call Dret("s:NetrwUnMarkFile")
8502endfun
8503
8504" ---------------------------------------------------------------------
8505" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8506fun! s:NetrwMenu(domenu)
8507
8508 if !exists("g:NetrwMenuPriority")
8509 let g:NetrwMenuPriority= 80
8510 endif
8511
Bram Moolenaaradc21822011-04-01 18:03:16 +02008512 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008513" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8514
8515 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008516" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008517 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008518 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8522 if g:netrw_dirhistmax > 0
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8527 else
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8529 endif
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8544 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 +01008545 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 +02008546 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8553 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8555 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8556 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8558 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8559 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8560 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8561 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8562 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8563 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8564 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8565 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8566 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8567 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8568 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8569 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8570 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8571 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8572 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8573 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8574 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8575 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>'
8576 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>'
8577 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>'
8578 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8579 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>'
8580 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>'
8581 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 +01008582 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 +02008583 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8584 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008585 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008586 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8587 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008588
8589 elseif !a:domenu
8590 let s:netrwcnt = 0
8591 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008592 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008593 exe curwin."wincmd w"
8594
8595 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008596" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008597 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008598" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008599 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008600 endif
8601 endif
8602" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008603 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008604 endif
8605
8606endfun
8607
8608" ---------------------------------------------------------------------
8609" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8610" Used by the O maps (as <SID>NetrwObtain())
8611fun! s:NetrwObtain(islocal)
8612" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8613
Bram Moolenaar97d62492012-11-15 21:28:22 +01008614 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008616 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008617 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008618 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8619 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008620 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008621 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008622 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008623
8624" call Dret("NetrwObtain")
8625endfun
8626
8627" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008628" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8629" If there's only one window, then the window will first be split.
8630" Returns:
8631" choice = 0 : didn't have to choose
8632" choice = 1 : saved modified file in window first
8633" choice = 2 : didn't save modified file, opened window
8634" choice = 3 : cancel open
8635fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008636" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008637
Bram Moolenaar97d62492012-11-15 21:28:22 +01008638 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008640 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008641" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008642
8643 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008644 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008646" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8647" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8648 let curword = s:NetrwGetWord()
8649 let choice = 0
8650 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8651" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008652 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008653" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008654 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008655" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008656" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008657" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008658
Bram Moolenaar8d043172014-01-23 14:24:41 +01008659 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008660 if lastwinnr == 1
8661 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008662" 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 +02008663 " g:netrw_preview=0: preview window shown in a horizontally split window
8664 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008665 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008666 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008667 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008668" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008669 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008670 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008671 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008672 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008673" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008674 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008675 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008676 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008677" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008678
8679 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008680" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008681 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008682" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008683 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008684" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008685 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008686" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008687 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008688" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008689" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008690" call Decho("COMBAK#12: mod=".&mod)
8691
8692 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8693 " whoops -- user trying to open file in the Lexplore window.
8694 " Use Lexplore's opening-file window instead.
8695" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8696" exe g:netrw_chgwin."wincmd w"
8697 wincmd p
8698 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8699 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008700
8701 " prevwinnr: the window number of the "prev" window
8702 " prevbufnr: the buffer number of the buffer in the "prev" window
8703 " bnrcnt : the qty of windows open on the "prev" buffer
8704 let prevwinnr = winnr()
8705 let prevbufnr = bufnr("%")
8706 let prevbufname = bufname("%")
8707 let prevmod = &mod
8708 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008709" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008710 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008711" 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 +01008712" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008713
8714 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715 " and it doesn't appear in any other extant window, then ask the
8716 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008717 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008718" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008719 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008720" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008721 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008722" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008723
8724 if bnrcnt == 1 && &hidden == 0
8725 " only one copy of the modified buffer in a window, and
8726 " hidden not set, so overwriting will lose the modified file. Ask first...
8727 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008728" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008729 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008730" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008731
8732 if choice == 1
8733 " Yes -- write file & then browse
8734 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008735 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008736 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008737 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008738 exe origwin."wincmd w"
8739 let &ei = eikeep
8740 let @@ = ykeep
8741" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008742 return choice
8743 endif
8744
8745 elseif choice == 2
8746 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008747" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008748 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008749
8750 else
8751 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008752" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008753 exe origwin."wincmd w"
8754 let &ei= eikeep
8755 let @@ = ykeep
8756" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008757 return choice
8758 endif
8759 endif
8760 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008761 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008762 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008763" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008764
8765 " restore b:netrw_curdir (window split/enew may have lost it)
8766 let b:netrw_curdir= curdir
8767 if a:islocal < 2
8768 if a:islocal
8769 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8770 else
8771 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8772 endif
8773 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008774 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008775" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776 return choice
8777endfun
8778
8779" ---------------------------------------------------------------------
8780" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8781" Always assumed to be local -> remote
8782" call s:NetrwUpload(filename, target)
8783" call s:NetrwUpload(filename, target, fromdirectory)
8784fun! s:NetrwUpload(fname,tgt,...)
8785" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8786
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008787 if a:tgt =~ '^\a\{3,}://'
8788 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008789 else
8790 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8791 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008792" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008793
8794 if a:0 > 0
8795 let fromdir= a:1
8796 else
8797 let fromdir= getcwd()
8798 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008799" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008800
8801 if type(a:fname) == 1
8802 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008803" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008804 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008805" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8806 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8807" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008808 if a:tgt =~ '/$'
8809 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008810" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008811 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008812 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008813" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008814 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008816 endif
8817 q!
8818
8819 elseif type(a:fname) == 3
8820 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008821" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008822 let curdir= getcwd()
8823 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008824 if s:NetrwLcd(fromdir)
8825" call Dret("s:NetrwUpload : lcd failure")
8826 return
8827 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008828 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008829 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008830 if exists("g:netrw_port") && g:netrw_port != ""
8831 let useport= " ".g:netrw_scpport." ".g:netrw_port
8832 else
8833 let useport= ""
8834 endif
8835 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8836 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008837 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 +02008838 if s:NetrwLcd(curdir)
8839" call Dret("s:NetrwUpload : lcd failure")
8840 return
8841 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842
8843 elseif a:tgt =~ '^ftp:'
8844 call s:NetrwMethod(a:tgt)
8845
8846 if b:netrw_method == 2
8847 " handle uploading a list of files via ftp+.netrc
8848 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008849 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008850" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008851
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008852 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008853" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008854
8855 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008856 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008857" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008858 endif
8859
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008860 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008861" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008862
Bram Moolenaaradc21822011-04-01 18:03:16 +02008863 if tgtdir == ""
8864 let tgtdir= '/'
8865 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008866 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008867" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008868
8869 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008870 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8871" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008872 endfor
8873
8874 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008875 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 +00008876 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008877" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8878 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008879 endif
8880 " 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 +01008881 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008882 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008883 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8884 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8885 else
8886 bw!|q
8887 endif
8888
8889 elseif b:netrw_method == 3
8890 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8891 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008892 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008893 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008894 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008895
8896 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008897 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008898" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008899 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008900 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008901" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008902 endif
8903
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008904 if exists("g:netrw_uid") && g:netrw_uid != ""
8905 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008906 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008907" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008908 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008909 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008910 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008911" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008912 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008913 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008914" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008915 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008916 endif
8917
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008918 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008919" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008920
8921 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008922 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008923" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008924 endif
8925
8926 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008927 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008928" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008929 endif
8930
8931 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008932 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008933" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008934 endfor
8935
8936 " perform ftp:
8937 " -i : turns off interactive prompting from ftp
8938 " -n unix : DON'T use <.netrc>, even though it exists
8939 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008940 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008941 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008942 " 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 +01008943 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008944 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008945 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8946 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008947 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008948 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8949 let &debug = debugkeep
8950 let mod = 1
8951 else
8952 bw!|q
8953 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008954 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008955" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008956 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008957 endif
8958 else
8959 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8960 endif
8961 endif
8962
8963" call Dret("s:NetrwUpload")
8964endfun
8965
8966" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008967" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008968fun! s:NetrwPreview(path) range
8969" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008970" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8971" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008972 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008973 NetrwKeepj call s:NetrwOptionsSave("s:")
8974 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8975 NetrwKeepj call s:NetrwOptionsSafe(1)
8976 else
8977 NetrwKeepj call s:NetrwOptionsSafe(0)
8978 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008979 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008980" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008981 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008982" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8983 if g:netrw_preview
8984 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008985 let pvhkeep = &pvh
8986 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8987 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008988" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8989 else
8990 " horizontal split
8991 let pvhkeep = &pvh
8992 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8993 let &pvh = winheight(0) - winsz
8994" 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 +02008995 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008996 " g:netrw_preview g:netrw_alto
8997 " 1 : vert 1: top -- preview window is vertically split off and on the left
8998 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8999 " 0 : 1: top -- preview window is horizontally split off and on the top
9000 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
9001 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009002 " 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 +02009003 " the BufEnter event set up in netrwPlugin.vim
9004" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
9005 let eikeep = &ei
9006 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009007 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009008 let &ei= eikeep
9009" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009010 if exists("pvhkeep")
9011 let &pvh= pvhkeep
9012 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009013 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009014 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009015 endif
9016 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009017 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 +00009018 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009019 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009020 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009021" call Dret("NetrwPreview")
9022endfun
9023
9024" ---------------------------------------------------------------------
9025" s:NetrwRefresh: {{{2
9026fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009027" 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 +00009028 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009029 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009030" call Decho("setl ma noro",'~'.expand("<slnum>"))
9031" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009032 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009033 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9034 if !exists("w:netrw_treetop")
9035 if exists("b:netrw_curdir")
9036 let w:netrw_treetop= b:netrw_curdir
9037 else
9038 let w:netrw_treetop= getcwd()
9039 endif
9040 endif
9041 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9042 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009043
9044 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009045 let screenposn = winsaveview()
9046" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009047
9048" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9049" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9050 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009051 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009052 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009053 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009054 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009055 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009056
9057 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009058" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9059 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009060
9061 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009062 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9063 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9064" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9065 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9066 else
9067" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9068 2match none
9069 endif
9070 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071
Bram Moolenaar97d62492012-11-15 21:28:22 +01009072" restore
9073 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009074" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009075endfun
9076
9077" ---------------------------------------------------------------------
9078" s:NetrwRefreshDir: refreshes a directory by name {{{2
9079" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009080" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009081fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009082" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009083 if g:netrw_fastbrowse == 0
9084 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009085" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009086 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009087" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009088
9089 if tgtwin > 0
9090 " tgtwin is being displayed, so refresh it
9091 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009092" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009093 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009094 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009095 exe curwin."wincmd w"
9096
9097 elseif bufnr(a:dirname) > 0
9098 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009099" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9100 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009101 endif
9102
9103 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009104" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009105 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009106 endif
9107" call Dret("s:NetrwRefreshDir")
9108endfun
9109
9110" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009111" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9112" window number to do its editing in.
9113" Supports [count]C where the count, if present, is used to specify
9114" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009115fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009116" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009117 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009118" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009119 if a:1 == "" " :NetrwC win#
9120 let g:netrw_chgwin= winnr()
9121 else " :NetrwC
9122 let g:netrw_chgwin= a:1
9123 endif
9124 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009125 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009126 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009127 let g:netrw_chgwin= winnr()
9128 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009129 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009130" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009131endfun
9132
9133" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009134" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9135" What this function does is to compute a priority for the patterns
9136" in the g:netrw_sort_sequence. It applies a substitute to any
9137" "files" that satisfy each pattern, putting the priority / in
9138" front. An "*" pattern handles the default priority.
9139fun! s:NetrwSetSort()
9140" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009141 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009142 if w:netrw_liststyle == s:LONGLIST
9143 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9144 else
9145 let seqlist = g:netrw_sort_sequence
9146 endif
9147 " sanity check -- insure that * appears somewhere
9148 if seqlist == ""
9149 let seqlist= '*'
9150 elseif seqlist !~ '\*'
9151 let seqlist= seqlist.',*'
9152 endif
9153 let priority = 1
9154 while seqlist != ""
9155 if seqlist =~ ','
9156 let seq = substitute(seqlist,',.*$','','e')
9157 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9158 else
9159 let seq = seqlist
9160 let seqlist = ""
9161 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009162 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009163 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009164 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009165 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009166 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009167 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009168 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009169" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009170
9171 " sanity check
9172 if w:netrw_bannercnt > line("$")
9173 " apparently no files were left after a Hiding pattern was used
9174" call Dret("SetSort : no files left after hiding")
9175 return
9176 endif
9177 if seq == '*'
9178 let starpriority= spriority
9179 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009180 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009181 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009182 " sometimes multiple sorting patterns will match the same file or directory.
9183 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009184 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9185 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009186 endif
9187 let priority = priority + 1
9188 endwhile
9189 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009190 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9191 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009192 endif
9193
9194 " Following line associated with priority -- items that satisfy a priority
9195 " pattern get prefixed by ###/ which permits easy sorting by priority.
9196 " Sometimes files can satisfy multiple priority patterns -- only the latest
9197 " priority pattern needs to be retained. So, at this point, these excess
9198 " priority prefixes need to be removed, but not directories that happen to
9199 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009200 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9201 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009202 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009203
9204" call Dret("SetSort")
9205endfun
9206
Bram Moolenaarff034192013-04-24 18:51:19 +02009207" ---------------------------------------------------------------------
9208" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9209" Implements [count]Tb (bookhist<b>)
9210" [count]Th (bookhist<h>)
9211" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009212fun! s:NetrwSetTgt(islocal,bookhist,choice)
9213" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009214
9215 if a:bookhist == 'b'
9216 " supports choosing a bookmark as a target using a qb-generated list
9217 let choice= a:choice - 1
9218 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009219 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009220 else
9221 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9222 endif
9223
9224 elseif a:bookhist == 'h'
9225 " supports choosing a history stack entry as a target using a qb-generated list
9226 let choice= (a:choice % g:netrw_dirhistmax) + 1
9227 if exists("g:netrw_dirhist_".choice)
9228 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009229 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009230 else
9231 echomsg "Sorry, history#".a:choice." not available!"
9232 endif
9233 endif
9234
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009235 " refresh the display
9236 if !exists("b:netrw_curdir")
9237 let b:netrw_curdir= getcwd()
9238 endif
9239 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9240
Bram Moolenaarff034192013-04-24 18:51:19 +02009241" call Dret("s:NetrwSetTgt")
9242endfun
9243
Bram Moolenaar446cb832008-06-24 21:56:24 +00009244" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009245" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009246fun! s:NetrwSortStyle(islocal)
9247" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009248 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009249 let svpos= winsaveview()
9250" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009251
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009252 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 +01009253 NetrwKeepj norm! 0
9254 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009255" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9256 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009257
9258" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9259endfun
9260
9261" ---------------------------------------------------------------------
9262" s:NetrwSplit: mode {{{2
9263" =0 : net and o
9264" =1 : net and t
9265" =2 : net and v
9266" =3 : local and o
9267" =4 : local and t
9268" =5 : local and v
9269fun! s:NetrwSplit(mode)
9270" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9271
Bram Moolenaar97d62492012-11-15 21:28:22 +01009272 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009273 call s:SaveWinVars()
9274
9275 if a:mode == 0
9276 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009277 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009278 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009279" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009280 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009281 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009282 NetrwKeepj call s:RestoreWinVars()
9283 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009284 unlet s:didsplit
9285
9286 elseif a:mode == 1
9287 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009288 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009289" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009290 tabnew
9291 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009292 NetrwKeepj call s:RestoreWinVars()
9293 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009294 unlet s:didsplit
9295
9296 elseif a:mode == 2
9297 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009298 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009299 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009300" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009301 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009302 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009303 NetrwKeepj call s:RestoreWinVars()
9304 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009305 unlet s:didsplit
9306
9307 elseif a:mode == 3
9308 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009309 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009310 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009311" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009312 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009313 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009314 NetrwKeepj call s:RestoreWinVars()
9315 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009316 unlet s:didsplit
9317
9318 elseif a:mode == 4
9319 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009320 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009321 let eikeep = &ei
9322 let netrw_winnr = winnr()
9323 let netrw_line = line(".")
9324 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009325 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009326 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009327 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009328 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9329 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009330 let &ei = eikeep
9331 let netrw_curdir = s:NetrwTreeDir(0)
9332" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009333 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009334 let b:netrw_curdir = netrw_curdir
9335 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009336 NetrwKeepj call s:RestoreWinVars()
9337 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009338 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009339 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009340 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9341 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009342 let &ei= eikeep
9343 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009344 unlet s:didsplit
9345
9346 elseif a:mode == 5
9347 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009348 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009349 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009350" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009351 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009352 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009353 NetrwKeepj call s:RestoreWinVars()
9354 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009355 unlet s:didsplit
9356
9357 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009358 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009359 endif
9360
Bram Moolenaar97d62492012-11-15 21:28:22 +01009361 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009362" call Dret("s:NetrwSplit")
9363endfun
9364
9365" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009366" s:NetrwTgtMenu: {{{2
9367fun! s:NetrwTgtMenu()
9368 if !exists("s:netrw_menucnt")
9369 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009370 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009371" call Dfunc("s:NetrwTgtMenu()")
9372
9373 " the following test assures that gvim is running, has menus available, and has menus enabled.
9374 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9375 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009376" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009377 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9378 endif
9379 if !exists("s:netrw_initbookhist")
9380 call s:NetrwBookHistRead()
9381 endif
9382
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009383 " try to cull duplicate entries
9384 let tgtdict={}
9385
Bram Moolenaarff034192013-04-24 18:51:19 +02009386 " target bookmarked places
9387 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009388" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009389 let cnt= 1
9390 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009391 if has_key(tgtdict,bmd)
9392 let cnt= cnt + 1
9393 continue
9394 endif
9395 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009396 let ebmd= escape(bmd,g:netrw_menu_escape)
9397 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009398" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009399 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 +02009400 let cnt= cnt + 1
9401 endfor
9402 endif
9403
9404 " target directory browsing history
9405 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009406" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009407 let histcnt = 1
9408 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009409 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009410 if exists("g:netrw_dirhist_{histcnt}")
9411 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009412 if has_key(tgtdict,histentry)
9413 let histcnt = histcnt + 1
9414 continue
9415 endif
9416 let tgtdict[histentry] = histcnt
9417 let ehistentry = escape(histentry,g:netrw_menu_escape)
9418" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009419 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 +02009420 endif
9421 let histcnt = histcnt + 1
9422 endwhile
9423 endif
9424 endif
9425" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009426endfun
9427
9428" ---------------------------------------------------------------------
9429" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9430" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009431fun! s:NetrwTreeDir(islocal)
9432" 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 +02009433" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009434" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9435" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9436" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009437" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009438
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009439 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009440 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009441" 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 +01009442 let treedir= s:treedir
9443 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009444 unlet s:prevwinopen
9445" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009446 return treedir
9447 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009448 if exists("s:prevwinopen")
9449 unlet s:prevwinopen
9450 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009451" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009452
Bram Moolenaar8d043172014-01-23 14:24:41 +01009453 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9454 let b:netrw_curdir= getcwd()
9455 endif
9456 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009457" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009458" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009459
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009460 let s:treecurpos= winsaveview()
9461" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009462" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009463
9464 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009465" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9466" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009467" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009468
9469 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009470 let curline= substitute(getline('.'),"\t -->.*$",'','')
9471 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009472" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009473 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009474" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9475 elseif curline =~ '@$'
9476" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
9477 let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
9478" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009479 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009480" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009481 let treedir= ""
9482 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009483" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009484
9485 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009486" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9487" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009488" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009489 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009490" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009491 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009492" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9493 sil! NetrwKeepj %d _
9494" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009495 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009496" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009497" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009498 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009499" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009501" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009502 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9503" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009504" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009505
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009506 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9507" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9508" let newdir = w:netrw_treetop.'/'.potentialdir
9509" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9510" let treedir = s:NetrwTreePath(newdir)
9511" let w:netrw_treetop = newdir
9512" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9513" else
9514" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009515 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009516" endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009517 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009518" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009519
9520 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009521 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009522" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009523" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009524
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009525" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009526 return treedir
9527endfun
9528
9529" ---------------------------------------------------------------------
9530" s:NetrwTreeDisplay: recursive tree display {{{2
9531fun! s:NetrwTreeDisplay(dir,depth)
9532" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9533
9534 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009535 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009536
9537 " install ../ and shortdir
9538 if a:depth == ""
9539 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009540" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009541 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009542 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009543 if a:dir == w:netrw_treetop
9544 let shortdir= a:dir
9545 else
9546 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9547 endif
9548 call setline(line("$")+1,a:depth.shortdir)
9549 else
9550 let shortdir= substitute(a:dir,'^.*/','','e')
9551 call setline(line("$")+1,a:depth.shortdir.'/')
9552 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009553" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009554 " append a / to dir if its missing one
9555 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009556
9557 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009558 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009559" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009560
Bram Moolenaar85850f32019-07-19 22:05:51 +02009561 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9562 if g:netrw_hide == 1
9563 " hide given patterns
9564 let listhide= split(g:netrw_list_hide,',')
9565" call Decho("listhide=".string(listhide))
9566 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009567 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009568 endfor
9569
9570 elseif g:netrw_hide == 2
9571 " show given patterns (only)
9572 let listhide= split(g:netrw_list_hide,',')
9573" call Decho("listhide=".string(listhide))
9574 let entries=[]
9575 for entry in w:netrw_treedict[dir]
9576 for pat in listhide
9577 if entry =~ pat
9578 call add(entries,entry)
9579 break
9580 endif
9581 endfor
9582 endfor
9583 let w:netrw_treedict[dir]= entries
9584 endif
9585 if depth != ""
9586 " always remove "." and ".." entries when there's depth
9587 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9588 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9589 endif
9590
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009591" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009592 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009593 if dir =~ '/$'
9594 let direntry= substitute(dir.entry,'[@/]$','','e')
9595 else
9596 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9597 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009598" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009599 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009600" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009601 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009602 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009603" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9604 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9605 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9606" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009607 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009608 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009609" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009610 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009611 endif
9612 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009613" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009614
Bram Moolenaar446cb832008-06-24 21:56:24 +00009615" call Dret("NetrwTreeDisplay")
9616endfun
9617
9618" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009619" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9620fun! s:NetrwRefreshTreeDict(dir)
9621" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009622 if !exists("w:netrw_treedict")
9623" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9624 return
9625 endif
9626
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009627 for entry in w:netrw_treedict[a:dir]
9628 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9629" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9630
9631 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9632" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9633 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009634 let liststar = s:NetrwGlob(direntry,'*',1)
9635 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009636 let w:netrw_treedict[direntry] = liststar + listdotstar
9637" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9638
9639 elseif 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" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9653
9654 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009655" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009656 endif
9657 endfor
9658" call Dret("s:NetrwRefreshTreeDict")
9659endfun
9660
9661" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009662" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009663" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009664fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009665 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009666" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009667" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9668" 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>"))
9669" 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 +00009670
9671 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009672 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009673" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009674 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009675 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009676" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009677 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 +02009678" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009680 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009681" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009682 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009683 if exists("w:netrw_treetop")
9684 let s:netrw_treetop= w:netrw_treetop
9685 else
9686 let w:netrw_treetop= getcwd()
9687 let s:netrw_treetop= w:netrw_treetop
9688 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009689
Bram Moolenaar446cb832008-06-24 21:56:24 +00009690 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009691 " insure that we have a treedict, albeit empty
9692" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009693 let w:netrw_treedict= {}
9694 endif
9695
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009696 " update the dictionary for the current directory
9697" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009698" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009699 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009700 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009701" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009702 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009703
9704 " if past banner, record word
9705 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9706 let fname= expand("<cword>")
9707 else
9708 let fname= ""
9709 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009710" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9711" 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 +00009712
9713 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009714" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009715 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009716" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009717
9718 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9719 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009720" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009721 1d
9722 endwhile
9723
Bram Moolenaar13600302014-05-22 18:26:40 +02009724 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009725
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009726" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009727 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009728 endif
9729endfun
9730
9731" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009732" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009733" Normally, treetop is w:netrw_treetop, but a
9734" user of the function ( netrw#SetTreetop() )
9735" wipes that out prior to calling this function
9736fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009737" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9738 if line(".") < w:netrw_bannercnt + 2
9739 let treedir= a:treetop
9740 if treedir !~ '/$'
9741 let treedir= treedir.'/'
9742 endif
9743" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9744 return treedir
9745 endif
9746
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009747 let svpos = winsaveview()
9748" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009749 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009750" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009751 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009752" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9753 let curline= getline('.')
9754" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9755 if curline =~ '/$'
9756" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9757 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9758" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9759 elseif curline =~ '@\s\+-->'
9760" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9761 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9762 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9763" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009764 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009765" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009766 let treedir= ""
9767 endif
9768 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009769" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9770" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009771 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9772 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9773 let treedir= dirname.treedir
9774 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009775" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009776 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009777" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009778 if a:treetop =~ '/$'
9779 let treedir= a:treetop.treedir
9780 else
9781 let treedir= a:treetop.'/'.treedir
9782 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009783" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009784 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009785" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009786" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9787 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009788" call Dret("s:NetrwTreePath <".treedir.">")
9789 return treedir
9790endfun
9791
9792" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009793" s:NetrwWideListing: {{{2
9794fun! s:NetrwWideListing()
9795
9796 if w:netrw_liststyle == s:WIDELIST
9797" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9798 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009799 " cpf: characters per filename
9800 " fpl: filenames per line
9801 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009802 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009803 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009804" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009805 let b:netrw_cpf= 0
9806 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009807 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009808 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9809 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009810 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009811 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009812" call Dret("NetrwWideListing")
9813 return
9814 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009815 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009816 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009817" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009818
9819 " determine qty files per line (fpl)
9820 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9821 if w:netrw_fpl <= 0
9822 let w:netrw_fpl= 1
9823 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009824" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009825
9826 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009827 " fpc: files per column of wide listing
9828 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009829 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009830 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9831 let newcolstart = w:netrw_bannercnt + fpc
9832 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009833" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009834 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009835" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009836 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009837 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009838 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009839 while line("$") >= newcolstart
9840 if newcolend > line("$") | let newcolend= line("$") | endif
9841 let newcolqty= newcolend - newcolstart
9842 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009843 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009844 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009845 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009846 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009847 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009848 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009849 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009850 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009851 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009852 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009853" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009854 if @* != keepregstar | sil! let @* = keepregstar | endif
9855 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009856 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009857 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9858 NetrwKeepj call histdel("/",-1)
9859 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9860 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009861" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009862 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009863 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009864" 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 +00009865" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009866 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009867 else
9868 if hasmapto("w","n")
9869 sil! nunmap <buffer> w
9870 endif
9871 if hasmapto("b","n")
9872 sil! nunmap <buffer> b
9873 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009874 endif
9875
9876endfun
9877
9878" ---------------------------------------------------------------------
9879" s:PerformListing: {{{2
9880fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009881" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9882" 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 +02009883" 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>"))
9884 sil! NetrwKeepj %d _
9885" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886
Bram Moolenaar15146672011-10-20 22:22:38 +02009887 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009888" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009889 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009890
Bram Moolenaar85850f32019-07-19 22:05:51 +02009891 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009892 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009893" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009894
9895" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009896" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009897" endif " Decho
9898
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009899" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009900 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9901 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009902" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9903 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009904 endif
9905
9906 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009907 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009908
9909 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009910 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009911" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009912 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009913 if exists("g:netrw_pchk")
9914 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9915 " failure detections.
9916 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009917 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009918 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9919 endif
9920 if exists("g:netrw_pchk")
9921 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9922 else
9923 let curdir= b:netrw_curdir
9924 endif
9925 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9926 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9927 else
9928 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009929 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009930 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009931 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009932 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009933" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009934 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009935 let w:netrw_bannercnt= 1
9936 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009937" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9938" 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 +00009939
Bram Moolenaar85850f32019-07-19 22:05:51 +02009940 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009941 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009942 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009943 let sortby= sortby." reversed"
9944 endif
9945
9946 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009947 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009949 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009950" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009951 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009952 NetrwKeepj put ='\" Sorted by '.sortby
9953 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009954 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9955 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009956" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009957 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009958 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009959 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9960 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009961 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009962" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009963" 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 +00009964 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009965
Bram Moolenaar85850f32019-07-19 22:05:51 +02009966 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009967 if g:netrw_banner
9968 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009969" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009970 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009971 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009972 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009973 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009974 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009975 endif
9976 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009977 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009978" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009979 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009980 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009981 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009982
9983 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009984 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009985" 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 +01009986 if g:netrw_list_hide != "" && g:netrw_hide
9987 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009988 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009989 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009990 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009991 endif
9992 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009993 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009994 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009995
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" 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 +01009997 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009999 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010000" 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 +010010001 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +010010002 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +010010003" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010004" 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 +000010005 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010006
10007 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +010010008 if g:netrw_banner
10009 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010010 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010011" 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 +010010012" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010013" 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 +010010014 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010015
Bram Moolenaar446cb832008-06-24 21:56:24 +000010016 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010017" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010019 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010020 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010021 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010022 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010023" 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 +010010024" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10025 return
10026 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010027 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010028
10029 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010030 if !exists("w:netrw_bannercnt")
10031 let w:netrw_bannercnt= 0
10032 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010033" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10034" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10035" 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 +010010036
Bram Moolenaar5c736222010-01-06 20:54:52 +010010037 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010038" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010039" 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 +000010040 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010041 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010042 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010043 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010044" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010045
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010046 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010047 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010048" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010049 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010050
Bram Moolenaar5c736222010-01-06 20:54:52 +010010051 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010052" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010053 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010054 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010055 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010056 else
10057 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010058 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010059 endif
10060 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010061
Bram Moolenaar446cb832008-06-24 21:56:24 +000010062 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010063" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010064 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10065 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010066
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010067 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010068 " exten: sort by extension
10069 " The histdel(...,-1) calls remove the last search from the search history
10070" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010071 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10072 NetrwKeepj call histdel("/",-1)
10073 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10074 NetrwKeepj call histdel("/",-1)
10075 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10076 NetrwKeepj call histdel("/",-1)
10077 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10078" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010079 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010080 " normal direction sorting
10081 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10082 else
10083 " reverse direction sorting
10084 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10085 endif
10086 endif
10087 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10088 NetrwKeepj call histdel("/",-1)
10089
Bram Moolenaar446cb832008-06-24 21:56:24 +000010090 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010091 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010092" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010093 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010094" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010095 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010096 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010097" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010098 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010099 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010100" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010101 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10102 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010103 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010104 endif
10105
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010106 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010107" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010108 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010109 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010110 call histdel("/",-1)
10111 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010112 endif
10113 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010114" 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 +000010115
10116 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010117" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10118" 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 +010010119 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" 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 +010010121 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010122" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#3)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010123
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010124 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010125 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010126" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010127 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010128 endif
10129
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010131 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010132" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10133 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010134 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010135" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10136 else
10137" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10138" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10139" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10140" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010141 endif
10142
10143 " record previous current directory
10144 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010145" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010146
10147 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010148" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10149" 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 +010010150 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010151" 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 +020010152 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010153" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#6)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010154
10155 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010156" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010157 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010158" 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 +010010159 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010160" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010161 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10162 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010163" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010164" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010165
Bram Moolenaar8d043172014-01-23 14:24:41 +010010166 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010167" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10168" 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 +010010169" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10170 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010171 unlet s:treecurpos
10172 endif
10173
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010174" 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>"))
10175" 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 +000010176" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10177endfun
10178
10179" ---------------------------------------------------------------------
10180" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010181fun! s:SetupNetrwStatusLine(statline)
10182" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10183
10184 if !exists("s:netrw_setup_statline")
10185 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010186" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010187
10188 if !exists("s:netrw_users_stl")
10189 let s:netrw_users_stl= &stl
10190 endif
10191 if !exists("s:netrw_users_ls")
10192 let s:netrw_users_ls= &laststatus
10193 endif
10194
10195 " set up User9 highlighting as needed
10196 let keepa= @a
10197 redir @a
10198 try
10199 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010200 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010201 if &bg == "dark"
10202 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10203 else
10204 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10205 endif
10206 endtry
10207 redir END
10208 let @a= keepa
10209 endif
10210
10211 " set up status line (may use User9 highlighting)
10212 " insure that windows have a statusline
10213 " make sure statusline is displayed
10214 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010215 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010216" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010217 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010218
10219" call Dret("SetupNetrwStatusLine : stl=".&stl)
10220endfun
10221
Bram Moolenaar85850f32019-07-19 22:05:51 +020010222" =========================================
10223" Remote Directory Browsing Support: {{{1
10224" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010225
10226" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010227" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10228" This function assumes that a long listing will be received. Size, time,
10229" and reverse sorts will be requested of the server but not otherwise
10230" enforced here.
10231fun! s:NetrwRemoteFtpCmd(path,listcmd)
10232" 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 +010010233" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010234 " sanity check: {{{3
10235 if !exists("w:netrw_method")
10236 if exists("b:netrw_method")
10237 let w:netrw_method= b:netrw_method
10238 else
10239 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10240" call Dret("NetrwRemoteFtpCmd")
10241 return
10242 endif
10243 endif
10244
10245 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10246 let ffkeep= &ff
10247 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010248" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010249
10250 " clear off any older non-banner lines " {{{3
10251 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010252" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10253 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010254
10255 ".........................................
10256 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10257 " ftp + <.netrc>: Method #2
10258 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010259 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010260 endif
10261 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010262 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010263" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010264 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010265 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010266" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010267 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010268" 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>"))
10269 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 +010010270 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010271" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10272 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 +010010273 endif
10274
10275 ".........................................
10276 elseif w:netrw_method == 3 " {{{3
10277 " ftp + machine,id,passwd,filename: Method #3
10278 setl ff=unix
10279 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010280 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010281 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010282 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010283 endif
10284
10285 " handle userid and password
10286 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010287" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010288 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10289 call NetUserPass("ftp:".host)
10290 endif
10291 if exists("g:netrw_uid") && g:netrw_uid != ""
10292 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010293 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010294 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010295 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010296 endif
10297 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010298 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010299 endif
10300 endif
10301
10302 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010303 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010304 endif
10305 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010306 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010307" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010308 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010309 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010310
10311 " perform ftp:
10312 " -i : turns off interactive prompting from ftp
10313 " -n unix : DON'T use <.netrc>, even though it exists
10314 " -n win32: quit being obnoxious about password
10315 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010316" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010317 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010318" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010319" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10320" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010321 endif
10322
10323 ".........................................
10324 elseif w:netrw_method == 9 " {{{3
10325 " sftp username@machine: Method #9
10326 " s:netrw_sftp_cmd
10327 setl ff=unix
10328
10329 " restore settings
10330 let &ff= ffkeep
10331" call Dret("NetrwRemoteFtpCmd")
10332 return
10333
10334 ".........................................
10335 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010336 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010337 endif
10338
10339 " cleanup for Windows " {{{3
10340 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010341 sil! NetrwKeepj %s/\r$//e
10342 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010343 endif
10344 if a:listcmd == "dir"
10345 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010346 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10347 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10348 NetrwKeepj call histdel("/",-1)
10349 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010350 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 +010010351 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10352 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010353 endif
10354 endif
10355
10356 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10357 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010358 exe 'NetrwKeepj '.w:netrw_bannercnt
10359 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010360 endif
10361 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010362 exe 'NetrwKeepj '.w:netrw_bannercnt
10363 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010364 endif
10365
10366 " restore settings " {{{3
10367 let &ff= ffkeep
10368" call Dret("NetrwRemoteFtpCmd")
10369endfun
10370
10371" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010372" s:NetrwRemoteListing: {{{2
10373fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010374" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010375
Bram Moolenaara6878372014-03-22 21:02:50 +010010376 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10377 let w:netrw_bannercnt= s:bannercnt
10378 endif
10379 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010380 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010381 endif
10382
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010384
Bram Moolenaar446cb832008-06-24 21:56:24 +000010385 " sanity check:
10386 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010387" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010388 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010389" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010390 if !exists("g:netrw_quiet")
10391 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10392 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010393 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010394" call Dret("s:NetrwRemoteListing -1")
10395 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010396 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397
Bram Moolenaar8d043172014-01-23 14:24:41 +010010398 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010399" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010400 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010401 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010402 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 +000010403 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010404 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 +000010405 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010406 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010407
Bram Moolenaar85850f32019-07-19 22:05:51 +020010408 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010409" call Dret("s:NetrwRemoteListing -1")
10410 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010411 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010412" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010413
Bram Moolenaar446cb832008-06-24 21:56:24 +000010414 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010415" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010416 let w:netrw_method= b:netrw_method
10417 endif
10418
Bram Moolenaar13600302014-05-22 18:26:40 +020010419 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010420 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010421" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010422 let s:method = "ftp"
10423 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010424 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010425 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010426 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010427 let listcmd= g:netrw_ftp_sizelist_cmd
10428 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010429" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010430 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010431" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010432
Bram Moolenaara6878372014-03-22 21:02:50 +010010433 " report on missing file or directory messages
10434 if search('[Nn]o such file or directory\|Failed to change directory')
10435 let mesg= getline(".")
10436 if exists("w:netrw_bannercnt")
10437 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010438 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010439 setl noma
10440 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010441 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010442 call netrw#ErrorMsg(s:WARNING,mesg,96)
10443" call Dret("s:NetrwRemoteListing : -1")
10444 return -1
10445 endif
10446
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010447 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 +000010448 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010449" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010450 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010451
10452 " cleanup
10453 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010454 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10455 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010456 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010457 sil! NetrwKeepj %s/\r$//e
10458 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010460 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010462 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010463 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010464" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010465 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010466" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010467 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010468 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010469 exe "sil! NetrwKeepj ".line1
10470 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010471
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010472" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010473 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010474" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010475 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10476 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010478" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010479 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10480 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10481 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10482 NetrwKeepj call histdel("/",-1)
10483 NetrwKeepj call histdel("/",-1)
10484 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485 endif
10486 endif
10487
Bram Moolenaar13600302014-05-22 18:26:40 +020010488 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010490" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010491 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010492" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010494" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10495 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010496 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010497 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10498 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10499 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10500 NetrwKeepj call histdel("/",-1)
10501 NetrwKeepj call histdel("/",-1)
10502 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010503 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010504 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10505 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010506 endif
10507 else
10508 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010509" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010510 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010511 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010512" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10513 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10514" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010515 endif
10516 endif
10517
10518 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010519 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010520" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010521 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10522 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 endif
10524 endif
10525
10526 if w:netrw_liststyle == s:LONGLIST
10527 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010528" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010529
10530 if s:method == "ftp"
10531 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010532 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010533 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010534 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010535 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010536 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010537 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010538 sil! NetrwKeepj 1
10539 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010540 let line2= line(".")
10541 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010542 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010543 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010544 endif
10545 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010546 exe "sil! NetrwKeepj ".line1
10547 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010548 endif
10549
10550 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010551" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010552 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 +000010553 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010554" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010555 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010556 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010557 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10558 NetrwKeepj call histdel("/",-1)
10559 NetrwKeepj call histdel("/",-1)
10560 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010561 endif
10562 endif
10563
10564" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010565" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010566" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010567
10568" call Dret("s:NetrwRemoteListing 0")
10569 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010570endfun
10571
Bram Moolenaar446cb832008-06-24 21:56:24 +000010572" ---------------------------------------------------------------------
10573" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10574fun! s:NetrwRemoteRm(usrhost,path) range
10575" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010576" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010577 let svpos= winsaveview()
10578" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010579
10580 let all= 0
10581 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10582 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010583" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010584 for fname in s:netrwmarkfilelist_{bufnr("%")}
10585 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010586 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010587 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010588 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589 let all= 1
10590 endif
10591 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010592 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010593
10594 else
10595 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010596" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010597
10598 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010599 let keepsol = &l:sol
10600 setl nosol
10601 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010602
10603 " remove multiple files and directories
10604 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010605 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010606 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010607 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010608 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010609 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010610 let all= 1
10611 endif
10612 let ctr= ctr + 1
10613 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010614 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010615 endif
10616
10617 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010618" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010619 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010620" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10621 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010622
10623" call Dret("s:NetrwRemoteRm")
10624endfun
10625
10626" ---------------------------------------------------------------------
10627" s:NetrwRemoteRmFile: {{{2
10628fun! s:NetrwRemoteRmFile(path,rmfile,all)
10629" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10630
10631 let all= a:all
10632 let ok = ""
10633
10634 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10635 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010636" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010637 if !all
10638 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010639" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010640 call inputsave()
10641 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10642 call inputrestore()
10643 echohl NONE
10644 if ok == ""
10645 let ok="no"
10646 endif
10647 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010648 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010649 let all= 1
10650 endif
10651 endif
10652
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010653 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010654" 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 +000010655 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010656" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010657 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010658 if path =~ '^\a\{3,}://'
10659 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010661 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010662 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10663 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010664" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010665 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010666" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010667 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010668 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010669 let ok="q"
10670 else
10671 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10673" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10674" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010676 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010677 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010678 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010679 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010680" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010681 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010682 if v:shell_error != 0
10683 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010684 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 +010010685 else
10686 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10687 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010688 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010689 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010690 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010691" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010692 endif
10693 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010694 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010695" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010696 endif
10697
10698 else
10699 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010700" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010701 if !all
10702 call inputsave()
10703 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10704 call inputrestore()
10705 if ok == ""
10706 let ok="no"
10707 endif
10708 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010709 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010710 let all= 1
10711 endif
10712 endif
10713
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010714 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010715 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010716 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010717 else
10718 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010719 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10720" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010721 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010722" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010723
10724 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010725" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10726 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10727" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010728 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010729" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010730
10731 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010732 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010733 endif
10734 endif
10735 endif
10736
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010737 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010738" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010739 endif
10740 endif
10741
10742" call Dret("s:NetrwRemoteRmFile ".ok)
10743 return ok
10744endfun
10745
10746" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010747" s:NetrwRemoteRename: rename a remote file or directory {{{2
10748fun! s:NetrwRemoteRename(usrhost,path) range
10749" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10750
10751 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010752 let svpos = winsaveview()
10753" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010754 let ctr = a:firstline
10755 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10756
10757 " rename files given by the markfilelist
10758 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10759 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010760" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010761 if exists("subfrom")
10762 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010763" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010764 else
10765 call inputsave()
10766 let newname= input("Moving ".oldname." to : ",oldname)
10767 call inputrestore()
10768 if newname =~ '^s/'
10769 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10770 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10771 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010772" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010773 endif
10774 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010775
Bram Moolenaar446cb832008-06-24 21:56:24 +000010776 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010777 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010778 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010779 let oldname= s:ShellEscape(a:path.oldname)
10780 let newname= s:ShellEscape(a:path.newname)
10781" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010782 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010783 endif
10784
10785 endfor
10786 call s:NetrwUnMarkFile(1)
10787
10788 else
10789
10790 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010791 let keepsol= &l:sol
10792 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010793 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010794 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010795
10796 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010797" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010798
10799 call inputsave()
10800 let newname= input("Moving ".oldname." to : ",oldname)
10801 call inputrestore()
10802
10803 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10804 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10805 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010806 let oldname= s:ShellEscape(a:path.oldname)
10807 let newname= s:ShellEscape(a:path.newname)
10808" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010809 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010810 endif
10811
10812 let ctr= ctr + 1
10813 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010814 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010815 endif
10816
10817 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010818 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010819" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10820 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010821
10822" call Dret("NetrwRemoteRename")
10823endfun
10824
Bram Moolenaar85850f32019-07-19 22:05:51 +020010825" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010826" Local Directory Browsing Support: {{{1
10827" ==========================================
10828
10829" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010830" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010831" Should accept: file://localhost/etc/fstab
10832" file:///etc/fstab
10833" file:///c:/WINDOWS/clock.avi
10834" file:///c|/WINDOWS/clock.avi
10835" file://localhost/c:/WINDOWS/clock.avi
10836" file://localhost/c|/WINDOWS/clock.avi
10837" file://c:/foo.txt
10838" file:///c:/foo.txt
10839" 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 +020010840fun! netrw#FileUrlEdit(fname)
10841" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010842 let fname = a:fname
10843 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010844" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010845 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010846" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010847 endif
10848 if (has("win32") || has("win95") || has("win64") || has("win16"))
10849 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010850" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010851 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010852" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010853 endif
10854 endif
10855 let fname2396 = netrw#RFC2396(fname)
10856 let fname2396e= fnameescape(fname2396)
10857 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10858 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010859" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010860 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010861" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010862 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10863 endif
10864 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010865
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010866" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10867" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010868 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010869 exe 'NetrwKeepj keepalt edit '.plainfname
10870 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10871
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010872" 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 +020010873" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010874 exe "sil doau BufReadPost ".fname2396e
10875endfun
10876
10877" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010878" netrw#LocalBrowseCheck: {{{2
10879fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010880 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010881 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10882 "
10883 " unfortunate interaction -- split window debugging can't be used here, must use
10884 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10885 " another call to LocalBrowseCheck() when attempts to write
10886 " to the DBG buffer are made.
10887 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010888 " The &ft == "netrw" test was installed because the BufEnter event
10889 " would hit when re-entering netrw windows, creating unexpected
10890 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010891" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010892" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010893" 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 +010010894 " getting E930: Cannot use :redir inside execute
10895"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010896" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10897" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010898
Bram Moolenaar97d62492012-11-15 21:28:22 +010010899 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010900 if isdirectory(s:NetrwFile(a:dirname))
10901" 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 +010010902
Bram Moolenaar97d62492012-11-15 21:28:22 +010010903 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010904" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10905" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010906 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010907
Bram Moolenaar446cb832008-06-24 21:56:24 +000010908 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010910 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010911
Bram Moolenaar5c736222010-01-06 20:54:52 +010010912 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010913" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010914 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010915 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010916 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010917" 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 +010010918" call Dret("netrw#LocalBrowseCheck")
10919 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010920 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010921
Bram Moolenaar85850f32019-07-19 22:05:51 +020010922 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010923 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10924 " AND IF the listing style is not a tree listing
10925 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010926" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010927 let ibuf = 1
10928 let buflast = bufnr("$")
10929 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010930 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10931 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010932 endif
10933 let ibuf= ibuf + 1
10934 endwhile
10935 endif
10936 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010937" 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>"))
10938" 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 +000010939 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010940" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010941endfun
10942
10943" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010944" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010945" performed any shell command. The idea is to cause all local-browsing
10946" buffers to be refreshed after a user has executed some shell command,
10947" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010948fun! s:LocalBrowseRefresh()
10949" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010950" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10951" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010952
Bram Moolenaar446cb832008-06-24 21:56:24 +000010953 " determine which buffers currently reside in a tab
10954 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010955" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010956 return
10957 endif
10958 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010959" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010960 return
10961 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010962 if !empty(getcmdwintype())
10963 " cannot move away from cmdline window, see :h E11
10964 return
10965 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010966 if exists("s:netrw_events") && s:netrw_events == 1
10967 " s:LocalFastBrowser gets called (indirectly) from a
10968 let s:netrw_events= 2
10969" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10970 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010971 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010972 let itab = 1
10973 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010974 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010975 while itab <= tabpagenr("$")
10976 let buftablist = buftablist + tabpagebuflist()
10977 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010978 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010979 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010980" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10981" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010982 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10983 " | refresh any netrw window
10984 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010985 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010986 let ibl = 0
10987 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010988" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010989 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10990 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010991 " (ibuf not shown in a current window AND
10992 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010993" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10994 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010995 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010996" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010997 continue
10998 elseif index(tabpagebuflist(),ibuf) != -1
10999 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011000" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011001 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011002 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010011003 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
11004 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
11005 let g:netrw_quickhelp= g:netrw_quickhelp - 1
11006 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011007" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011008 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
11009 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11010 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011011 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011012 endif
11013 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011014" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011015 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011016" call Decho("restore window: win_gotoid(".curwinid.")")
11017 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011018 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011019
Bram Moolenaara6878372014-03-22 21:02:50 +010011020" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011021endfun
11022
11023" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011024" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11025"
11026" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011027" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011028" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11029" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011030" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011031"
11032" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11033" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011034" (re-using a buffer may not be as accurate)
11035"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011036" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011037" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11038" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11039" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11040" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011041fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011042" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11043" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11044" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11045" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011046
11047 " initialize browselist, a list of buffer numbers that the local browser has used
11048 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011049" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011050 let s:netrw_browselist= []
11051 endif
11052
11053 " append current buffer to fastbrowse list
11054 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011055" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011056 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011057" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011058 endif
11059
11060 " enable autocmd events to handle refreshing/removing local browser buffers
11061 " If local browse buffer is currently showing: refresh it
11062 " If local browse buffer is currently hidden : wipe it
11063 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11064 " =1 : medium speed, re-use directory listing for remote only
11065 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011066 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11067 let s:netrw_events= 1
11068 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011069 au!
11070 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011071" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011072 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011073 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011074" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011075 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011076 endif
11077 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011078
11079 " user must have changed fastbrowse to its fast setting, so remove
11080 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011081 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011082" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011083 unlet s:netrw_events
11084 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011085 au!
11086 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011087 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011088 endif
11089
Bram Moolenaar85850f32019-07-19 22:05:51 +020011090" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011091endfun
11092
11093" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011094" s:LocalListing: does the job of "ls" for local directories {{{2
11095fun! s:LocalListing()
11096" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011097" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11098" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11099" 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 +010011100
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011101" 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
11102" 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
11103" 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 +010011104
11105 " get the list of files contained in the current directory
11106 let dirname = b:netrw_curdir
11107 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011108 let filelist = s:NetrwGlob(dirname,"*",0)
11109 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011110" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011111
11112 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011113" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011114 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11115 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011116" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011117 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011118" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011119 endif
11120
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011121" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011122" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011123" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011124
11125 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11126 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11127 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011128" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11129" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011130 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011131" 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 +010011132
11133 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011134" call Decho(" ",'~'.expand("<slnum>"))
11135" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011136
11137 if getftype(filename) == "link"
11138 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011139" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011140 let pfile= filename."@"
11141
11142 elseif getftype(filename) == "socket"
11143 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011144" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011145 let pfile= filename."="
11146
11147 elseif getftype(filename) == "fifo"
11148 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011149" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011150 let pfile= filename."|"
11151
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011152 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011153 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011154" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011155 let pfile= filename."/"
11156
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011157 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011158 if (has("win32") || has("win95") || has("win64") || has("win16"))
11159 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11160 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011161" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011162 let pfile= filename."*"
11163 else
11164 " normal file
11165 let pfile= filename
11166 endif
11167 elseif executable(filename)
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
11176 else
11177 " normal file
11178 let pfile= filename
11179 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011180" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011181
11182 if pfile =~ '//$'
11183 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011184" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011185 endif
11186 let pfile= strpart(pfile,dirnamelen)
11187 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011188" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11189" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011190
11191 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011192 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11193 let sz = getfsize(filename)
11194 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11195 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011196
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011197 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011198 let sz= s:NetrwHumanReadable(sz)
11199 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011200 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011201 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011202" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011203 endif
11204
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011205 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011206 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011207 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011208" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011209" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011210 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011211 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011212" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011213 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011214 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011215
11216 elseif g:netrw_sort_by =~ "^s"
11217 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011218" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011219" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011220 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011221 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011222" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011223 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011224 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011225
11226 else
11227 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011228" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011229" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011230 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011231 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011232" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011233 endfor
11234
11235 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011236 sil! NetrwKeepj g/^$/d
11237 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011238 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011239" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011240 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11241
11242" call Dret("s:LocalListing")
11243endfun
11244
11245" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011246" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11247fun! s:NetrwLocalExecute(cmd)
11248" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11249 let ykeep= @@
11250 " sanity check
11251 if !executable(a:cmd)
11252 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11253 let @@= ykeep
11254" call Dret("s:NetrwLocalExecute")
11255 return
11256 endif
11257
11258 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011259" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011260 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011261" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011262
11263 " strip any ansi escape sequences off
11264 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11265
11266 " show user the result(s)
11267 echomsg result
11268 let @@= ykeep
11269
11270" call Dret("s:NetrwLocalExecute")
11271endfun
11272
11273" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011274" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011275fun! s:NetrwLocalRename(path) range
11276" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11277
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011278 if !exists("w:netrw_bannercnt")
11279 let w:netrw_bannercnt= b:netrw_bannercnt
11280 endif
11281
Bram Moolenaar97d62492012-11-15 21:28:22 +010011282 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011283 let ykeep = @@
11284 let ctr = a:firstline
11285 let svpos = winsaveview()
11286 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011287" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011288
11289 " rename files given by the markfilelist
11290 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11291 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011292" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011293 if exists("subfrom")
11294 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011295" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011296 else
11297 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011298 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011299 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011300 if newname =~ ''
11301 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11302 let newname = substitute(newname,'^.*','','')
11303 elseif newname =~ ''
11304 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11305 let newname = substitute(newname,'[^/]*','','')
11306 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011307 if newname =~ '^s/'
11308 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11309 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011310" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011311 let newname = substitute(oldname,subfrom,subto,'')
11312 endif
11313 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011314 if !all && filereadable(newname)
11315 call inputsave()
11316 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11317 call inputrestore()
11318 if response == "all"
11319 let all= 1
11320 elseif response != "y" && response != "yes"
11321 " refresh the directory
11322" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11323 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11324" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11325 NetrwKeepj call winrestview(svpos)
11326 let @@= ykeep
11327" call Dret("NetrwLocalRename")
11328 return
11329 endif
11330 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011331 call rename(oldname,newname)
11332 endfor
11333 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011334
Bram Moolenaar97d62492012-11-15 21:28:22 +010011335 else
11336
11337 " attempt to rename files/directories
11338 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011339 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011340
11341 " sanity checks
11342 if line(".") < w:netrw_bannercnt
11343 let ctr= ctr + 1
11344 continue
11345 endif
11346 let curword= s:NetrwGetWord()
11347 if curword == "./" || curword == "../"
11348 let ctr= ctr + 1
11349 continue
11350 endif
11351
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011352 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011353 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011354" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011355
11356 call inputsave()
11357 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11358 call inputrestore()
11359
11360 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011361" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011362
11363 let ctr= ctr + 1
11364 endwhile
11365 endif
11366
11367 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011368" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011369 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011370" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11371 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011372 let @@= ykeep
11373
11374" call Dret("NetrwLocalRename")
11375endfun
11376
11377" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011378" s:NetrwLocalRm: {{{2
11379fun! s:NetrwLocalRm(path) range
11380" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011381" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011382
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011383 if !exists("w:netrw_bannercnt")
11384 let w:netrw_bannercnt= b:netrw_bannercnt
11385 endif
11386
Bram Moolenaar446cb832008-06-24 21:56:24 +000011387 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011388 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011389 let ret = 0
11390 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011391 let svpos = winsaveview()
11392" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011393
11394 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11395 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011396" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011397 for fname in s:netrwmarkfilelist_{bufnr("%")}
11398 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011399 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011400 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011401 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011402 let all= 1
11403 endif
11404 endfor
11405 call s:NetrwUnMarkFile(1)
11406
11407 else
11408 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011409" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011410
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011411 let keepsol= &l:sol
11412 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011413 let ctr = a:firstline
11414 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011415 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011416
11417 " sanity checks
11418 if line(".") < w:netrw_bannercnt
11419 let ctr= ctr + 1
11420 continue
11421 endif
11422 let curword= s:NetrwGetWord()
11423 if curword == "./" || curword == "../"
11424 let ctr= ctr + 1
11425 continue
11426 endif
11427 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011428 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011429 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011430 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011431 let all= 1
11432 endif
11433 let ctr= ctr + 1
11434 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011435 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011436 endif
11437
11438 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011439" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011440 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011441 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011442" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11443 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011444 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011445 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011446
11447" call Dret("s:NetrwLocalRm")
11448endfun
11449
11450" ---------------------------------------------------------------------
11451" s:NetrwLocalRmFile: remove file fname given the path {{{2
11452" Give confirmation prompt unless all==1
11453fun! s:NetrwLocalRmFile(path,fname,all)
11454" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011455
Bram Moolenaar446cb832008-06-24 21:56:24 +000011456 let all= a:all
11457 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011458 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011459 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11460" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011461
11462 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11463 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011464" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011465 if !all
11466 echohl Statement
11467 call inputsave()
11468 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11469 call inputrestore()
11470 echohl NONE
11471 if ok == ""
11472 let ok="no"
11473 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011474" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011475 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011476" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011477 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011478 let all= 1
11479 endif
11480 endif
11481
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011482 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011483 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011484" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011485 endif
11486
11487 else
11488 " attempt to remove directory
11489 if !all
11490 echohl Statement
11491 call inputsave()
11492 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11493 call inputrestore()
11494 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11495 if ok == ""
11496 let ok="no"
11497 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011498 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011499 let all= 1
11500 endif
11501 endif
11502 let rmfile= substitute(rmfile,'[\/]$','','e')
11503
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011504 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar71badf92023-04-22 22:40:14 +010011505 if delete(rmfile,"d")
11506 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011507 endif
11508 endif
11509 endif
11510
11511" call Dret("s:NetrwLocalRmFile ".ok)
11512 return ok
11513endfun
11514
Bram Moolenaar85850f32019-07-19 22:05:51 +020011515" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011516" Support Functions: {{{1
11517
Bram Moolenaar488c6512005-08-11 20:09:58 +000011518" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011519" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11520" 0: marked file list of current buffer
11521" 1: marked file target
11522fun! netrw#Access(ilist)
11523 if a:ilist == 0
11524 if exists("s:netrwmarkfilelist_".bufnr('%'))
11525 return s:netrwmarkfilelist_{bufnr('%')}
11526 else
11527 return "no-list-buf#".bufnr('%')
11528 endif
11529 elseif a:ilist == 1
11530 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011531 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011532endfun
11533
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011534" ---------------------------------------------------------------------
11535" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11536fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011537 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011538endfun
11539
Bram Moolenaara6878372014-03-22 21:02:50 +010011540" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011541" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11542" I expect this function to be used in
11543" :PChkAssert netrw#Expose("netrwmarkfilelist")
11544" for example.
11545fun! netrw#Expose(varname)
11546" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011547 if exists("s:".a:varname)
11548 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011549" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011550 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011551" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011552 if type(retval) == 3
11553 let retval = copy(retval)
11554 let i = 0
11555 while i < len(retval)
11556 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11557 let i = i + 1
11558 endwhile
11559 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011560" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011561 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011562 else
11563" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011564 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011565 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011566" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011567 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011568 endif
11569
11570" call Dret("netrw#Expose ".string(retval))
11571 return retval
11572endfun
11573
11574" ---------------------------------------------------------------------
11575" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11576fun! netrw#Modify(varname,newvalue)
11577" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11578 exe "let s:".a:varname."= ".string(a:newvalue)
11579" call Dret("netrw#Modify")
11580endfun
11581
11582" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011583" netrw#RFC2396: converts %xx into characters {{{2
11584fun! netrw#RFC2396(fname)
11585" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011586 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011587" call Dret("netrw#RFC2396 ".fname)
11588 return fname
11589endfun
11590
11591" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011592" netrw#UserMaps: supports user-specified maps {{{2
11593" see :help function()
11594"
11595" g:Netrw_UserMaps is a List with members such as:
11596" [[keymap sequence, function reference],...]
11597"
11598" The referenced function may return a string,
11599" refresh : refresh the display
11600" -other- : this string will be executed
11601" or it may return a List of strings.
11602"
11603" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011604" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011605" Related functions:
11606" netrw#Expose(varname) -- see s:varname variables
11607" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11608" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11609fun! netrw#UserMaps(islocal)
11610" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11611" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11612
11613 " set up usermaplist
11614 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11615" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11616 for umap in g:Netrw_UserMaps
11617" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11618" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11619 " if umap[0] is a string and umap[1] is a string holding a function name
11620 if type(umap[0]) == 1 && type(umap[1]) == 1
11621" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11622 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11623 else
11624 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11625 endif
11626 endfor
11627 endif
11628" call Dret("netrw#UserMaps")
11629endfun
11630
11631" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011632" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11633fun! netrw#WinPath(path)
11634" call Dfunc("netrw#WinPath(path<".a:path.">)")
11635 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11636 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011637 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011638 " remove trailing slash (Win95)
11639 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11640 " remove escaped spaces
11641 let path = substitute(path, '\ ', ' ', 'g')
11642 " convert slashes to backslashes
11643 let path = substitute(path, '/', '\', 'g')
11644 else
11645 let path= a:path
11646 endif
11647" call Dret("netrw#WinPath <".path.">")
11648 return path
11649endfun
11650
11651" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011652" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11653" cb : bl2mf=0 add marked files to buffer list
11654" cB : bl2mf=1 use bufferlist to mark files
11655" (mnemonic: cb = copy (marked files) to buffer list)
11656fun! s:NetrwBadd(islocal,bl2mf)
11657" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11658 if a:bl2mf
11659 " cB: add buffer list to marked files
11660 redir => bufl
11661 ls
11662 redir END
11663 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11664 for fname in bufl
11665 call s:NetrwMarkFile(a:islocal,fname)
11666 endfor
11667 else
11668 " cb: add marked files to buffer list
11669 for fname in s:netrwmarkfilelist_{bufnr("%")}
11670" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11671 exe "badd ".fnameescape(fname)
11672 endfor
11673 let curbufnr = bufnr("%")
11674 let curdir = s:NetrwGetCurdir(a:islocal)
11675 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11676 endif
11677" call Dret("s:NetrwBadd")
11678endfun
11679
11680" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011681" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11682fun! s:ComposePath(base,subdir)
11683" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11684
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011685 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011686" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011687 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011688 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011689 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011690 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011691 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011692 endif
11693
Bram Moolenaar85850f32019-07-19 22:05:51 +020011694 " COMBAK: test on windows with changing to root directory: :e C:/
11695 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011696" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011697 let ret= a:subdir
11698
Bram Moolenaar85850f32019-07-19 22:05:51 +020011699 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011700" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011701 if a:base =~ '[/\\]$'
11702 let ret= a:base.a:subdir
11703 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011704 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011705 endif
11706
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011707 elseif a:base =~ '^\a\{3,}://'
11708" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011709 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11710 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11711 if a:subdir == '../'
11712 if curpath =~ '[^/]/[^/]\+/$'
11713 let curpath= substitute(curpath,'[^/]\+/$','','')
11714 else
11715 let curpath=""
11716 endif
11717 let ret= urlbase.curpath
11718 else
11719 let ret= urlbase.curpath.a:subdir
11720 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011721" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11722" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11723" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011724
11725 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011726" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011727 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11728 if a:base =~ '^//'
11729 " keeping initial '//' for the benefit of network share listing support
11730 let ret= '/'.ret
11731 endif
11732 let ret= simplify(ret)
11733 endif
11734
11735" call Dret("s:ComposePath ".ret)
11736 return ret
11737endfun
11738
11739" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011740" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11741" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11742fun! s:DeleteBookmark(fname)
11743" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11744 call s:MergeBookmarks()
11745
11746 if exists("g:netrw_bookmarklist")
11747 let indx= index(g:netrw_bookmarklist,a:fname)
11748 if indx == -1
11749 let indx= 0
11750 while indx < len(g:netrw_bookmarklist)
11751 if g:netrw_bookmarklist[indx] =~ a:fname
11752 call remove(g:netrw_bookmarklist,indx)
11753 let indx= indx - 1
11754 endif
11755 let indx= indx + 1
11756 endwhile
11757 else
11758 " remove exact match
11759 call remove(g:netrw_bookmarklist,indx)
11760 endif
11761 endif
11762
11763" call Dret("s:DeleteBookmark")
11764endfun
11765
11766" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011767" s:FileReadable: o/s independent filereadable {{{2
11768fun! s:FileReadable(fname)
11769" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11770
11771 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011772 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011773 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011774 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011775 endif
11776
11777" call Dret("s:FileReadable ".ret)
11778 return ret
11779endfun
11780
11781" ---------------------------------------------------------------------
11782" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11783" Places correct suffix on end of temporary filename,
11784" using the suffix provided with fname
11785fun! s:GetTempfile(fname)
11786" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11787
11788 if !exists("b:netrw_tmpfile")
11789 " get a brand new temporary filename
11790 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011791" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011792
Bram Moolenaarc236c162008-07-13 17:41:49 +000011793 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011794" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011795
Bram Moolenaar9964e462007-05-05 17:54:07 +000011796 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011797 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11798" 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 +010011799 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011800" call Dret("s:GetTempfile getcwd<".getcwd().">")
11801 return ""
11802 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011803
Bram Moolenaar9964e462007-05-05 17:54:07 +000011804 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011805 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011806" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011807
Bram Moolenaar9964e462007-05-05 17:54:07 +000011808 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011809 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011810 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011811 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011812 if !exists("+shellslash") || !&ssl
11813 let tmpfile = substitute(tmpfile,'/','\','g')
11814 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011815 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011816 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011817 endif
11818 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011819" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011820 else
11821 " re-use temporary filename
11822 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011823" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011824 endif
11825
11826 " use fname's suffix for the temporary file
11827 if a:fname != ""
11828 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011829" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011830 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011831 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011832 elseif a:fname =~ '.txz$'
11833 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011834 else
11835 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11836 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011837" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011838 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011839" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011840 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011841" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011842 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11843 endif
11844 endif
11845
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011846" 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 +000011847" call Dret("s:GetTempfile <".tmpfile.">")
11848 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011849endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011850
11851" ---------------------------------------------------------------------
11852" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011853" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011854fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011855" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011856 if s:user == ""
11857 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11858 else
11859 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11860 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011861 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011862 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011863 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011864 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011865 else
11866 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11867 endif
11868" call Dret("s:MakeSshCmd <".sshcmd.">")
11869 return sshcmd
11870endfun
11871
11872" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011873" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11874fun! s:MakeBookmark(fname)
11875" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11876
11877 if !exists("g:netrw_bookmarklist")
11878 let g:netrw_bookmarklist= []
11879 endif
11880
11881 if index(g:netrw_bookmarklist,a:fname) == -1
11882 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011883 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011884 call add(g:netrw_bookmarklist,a:fname.'/')
11885 elseif a:fname !~ '/'
11886 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11887 else
11888 call add(g:netrw_bookmarklist,a:fname)
11889 endif
11890 call sort(g:netrw_bookmarklist)
11891 endif
11892
11893" call Dret("s:MakeBookmark")
11894endfun
11895
11896" ---------------------------------------------------------------------
11897" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11898fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011899" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011900 " get bookmarks from .netrwbook file
11901 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011902 if filereadable(s:NetrwFile(savefile))
11903" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011904 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011905" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011906 NetrwKeepj call delete(savefile)
11907 endif
11908" call Dret("s:MergeBookmarks")
11909endfun
11910
11911" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011912" s:NetrwBMShow: {{{2
11913fun! s:NetrwBMShow()
11914" call Dfunc("s:NetrwBMShow()")
11915 redir => bmshowraw
11916 menu
11917 redir END
11918 let bmshowlist = split(bmshowraw,'\n')
11919 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011920 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011921 if bmshowfuncs != []
11922 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011923 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011924 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011925 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011926 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011927 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011928" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11929endfun
11930
11931" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011932" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011933fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011934 if !exists("w:netrw_liststyle")
11935 let w:netrw_liststyle= g:netrw_liststyle
11936 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011937" 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 +020011938
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011939" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11940
Bram Moolenaaradc21822011-04-01 18:03:16 +020011941 if &ft != "netrw"
11942 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11943 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011944" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011945
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011946 elseif g:netrw_cursor == 8
11947 if w:netrw_liststyle == s:WIDELIST
11948 setl cursorline
11949 setl cursorcolumn
11950 else
11951 setl cursorline
11952 endif
11953 elseif g:netrw_cursor == 7
11954 setl cursorline
11955 elseif g:netrw_cursor == 6
11956 if w:netrw_liststyle == s:WIDELIST
11957 setl cursorline
11958 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011959 elseif g:netrw_cursor == 4
11960 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011961" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011962 setl cursorline
11963 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011964
11965 elseif g:netrw_cursor == 3
11966 " thin-long-tree: cursorline, user's cursorcolumn
11967 " wide : cursorline, cursorcolumn
11968 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011969" call Decho("case g:netrw_cursor==3 and wide: 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 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011973" 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 +020011974 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011975 endif
11976
11977 elseif g:netrw_cursor == 2
11978 " thin-long-tree: cursorline, user's cursorcolumn
11979 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011980" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011981 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011982
11983 elseif g:netrw_cursor == 1
11984 " thin-long-tree: user's cursorline, user's cursorcolumn
11985 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011986 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011987" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011988 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011989 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011990" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011991 endif
11992
11993 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011994 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011995" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011996 let &l:cursorline = s:netrw_usercul
11997 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011998 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011999
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012000" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020012001" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012002endfun
12003
12004" ---------------------------------------------------------------------
12005" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
12006fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012007" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012008 if exists("s:netrw_usercul")
12009 let &l:cursorline = s:netrw_usercul
12010 endif
12011 if exists("s:netrw_usercuc")
12012 let &l:cursorcolumn = s:netrw_usercuc
12013 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012014" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012015" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12016endfun
12017
12018" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012019" s:NetrwDelete: Deletes a file. {{{2
12020" Uses Steve Hall's idea to insure that Windows paths stay
12021" acceptable. No effect on Unix paths.
12022" Examples of use: let result= s:NetrwDelete(path)
12023fun! s:NetrwDelete(path)
12024" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12025
Bram Moolenaar5c736222010-01-06 20:54:52 +010012026 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012027 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
12028 if exists("+shellslash")
12029 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012030 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012031 let result = delete(path)
12032 let &shellslash = sskeep
12033 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012034" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012035 let result= delete(path)
12036 endif
12037 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012038" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012039 let result= delete(path)
12040 endif
12041 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012042 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012043 endif
12044
12045" call Dret("s:NetrwDelete ".result)
12046 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012047endfun
12048
12049" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012050" s:NetrwBufRemover: removes a buffer that: {{{2s
12051" has buffer-id > 1
12052" is unlisted
12053" is unnamed
12054" does not appear in any window
12055fun! s:NetrwBufRemover(bufid)
12056" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12057" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12058" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12059" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12060" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12061
yasuda4dbb2662023-10-04 20:50:35 +020012062 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012063" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012064 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012065 endif
12066
12067" call Dret("s:NetrwBufRemover")
12068endfun
12069
12070" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012071" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012072fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012073" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012074" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012075
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012076 " Clean out the last buffer:
12077 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12078 " If so, delete it.
12079 call s:NetrwBufRemover(bufnr("$"))
12080
Bram Moolenaar446cb832008-06-24 21:56:24 +000012081 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012082" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012083 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12084 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12085 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12086 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12087 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12088 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12089 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12090 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12091 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12092 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12093 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12094 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12095 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12096 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12097 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12098 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12099
Bram Moolenaar85850f32019-07-19 22:05:51 +020012100 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012101" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012102 " when tree listing uses file TreeListing... a new buffer is made.
12103 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012104 " COMBAK: this causes a problem, see P43
12105" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012106 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012107 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012108 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012109" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012110 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012111
Bram Moolenaar446cb832008-06-24 21:56:24 +000012112 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012113" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012114 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12115 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12116 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12117 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12118 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12119 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12120 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12121 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12122 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12123 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12124 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12125 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12126 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12127 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12128 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12129 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12130
Bram Moolenaar5c736222010-01-06 20:54:52 +010012131 if a:0 > 0
12132 let b:netrw_curdir= a:1
12133 if b:netrw_curdir =~ '/$'
12134 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012135 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012136 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012137 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012138 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12139 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012140 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012141 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012142 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012143 endif
12144 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012145 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12146 let &l:bexpr = "netrw#BalloonHelp()"
12147 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012148
Bram Moolenaar8d043172014-01-23 14:24:41 +010012149" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012150endfun
12151
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012152" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012153" s:NetrwExe: executes a string using "!" {{{2
12154fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012155" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012156 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012157" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012158 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12159 set shell& shellcmdflag& shellxquote& shellxescape&
12160 set shellquote& shellpipe& shellredir& shellslash&
12161 exe a:cmd
12162 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12163 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012164" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012165 exe a:cmd
12166 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012167 if v:shell_error
12168 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12169 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012170" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012171endfun
12172
12173" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012174" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12175fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012176 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012177" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012178 let curbuf = bufnr("%")
12179 let curwin = winnr()
12180 let iwin = 1
12181 while iwin <= winnr("$")
12182 exe iwin."wincmd w"
12183 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12184 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12185 let winvars= w:
12186 break
12187 endif
12188 let iwin= iwin + 1
12189 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012190 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012191 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012192" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012193 for k in keys(winvars)
12194 let w:{k}= winvars[k]
12195 endfor
12196 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012197" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012198 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012199endfun
12200
Bram Moolenaara6878372014-03-22 21:02:50 +010012201" ---------------------------------------------------------------------
12202" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012203" Returns: 0=success
12204" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012205fun! s:NetrwLcd(newdir)
12206" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012207" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012208
Bram Moolenaar85850f32019-07-19 22:05:51 +020012209 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012210 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012211 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012212 catch /^Vim\%((\a\+)\)\=:E344/
12213 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12214 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012215 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012216 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12217 " forward slashes by earlier code; so check for both.
12218 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
12219 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12220 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012221 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012222 endif
12223 endif
12224 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012225 let err472= 1
12226 endtry
12227
12228 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012229 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12230 if exists("w:netrw_prvdir")
12231 let a:newdir= w:netrw_prvdir
12232 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012233 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012234" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012235 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012236" 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 +010012237 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012238 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012239" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12240 return -1
12241 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012242
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012243" call Decho("getcwd <".getcwd().">")
12244" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012245" call Dret("s:NetrwLcd 0")
12246 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012247endfun
12248
Bram Moolenaar9964e462007-05-05 17:54:07 +000012249" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012250" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12251" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12252fun! s:NetrwSaveWordPosn()
12253" call Dfunc("NetrwSaveWordPosn()")
12254 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12255" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12256endfun
12257
12258" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012259" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12260" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12261fun! s:NetrwHumanReadable(sz)
12262" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12263
12264 if g:netrw_sizestyle == 'h'
12265 if a:sz >= 1000000000
12266 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12267 elseif a:sz >= 10000000
12268 let sz = printf("%d",a:sz/1000000)."m"
12269 elseif a:sz >= 1000000
12270 let sz = printf("%.1f",a:sz/1000000.0)."m"
12271 elseif a:sz >= 10000
12272 let sz = printf("%d",a:sz/1000)."k"
12273 elseif a:sz >= 1000
12274 let sz = printf("%.1f",a:sz/1000.0)."k"
12275 else
12276 let sz= a:sz
12277 endif
12278
12279 elseif g:netrw_sizestyle == 'H'
12280 if a:sz >= 1073741824
12281 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12282 elseif a:sz >= 10485760
12283 let sz = printf("%d",a:sz/1048576)."M"
12284 elseif a:sz >= 1048576
12285 let sz = printf("%.1f",a:sz/1048576.0)."M"
12286 elseif a:sz >= 10240
12287 let sz = printf("%d",a:sz/1024)."K"
12288 elseif a:sz >= 1024
12289 let sz = printf("%.1f",a:sz/1024.0)."K"
12290 else
12291 let sz= a:sz
12292 endif
12293
12294 else
12295 let sz= a:sz
12296 endif
12297
12298" call Dret("s:NetrwHumanReadable ".sz)
12299 return sz
12300endfun
12301
12302" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012303" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12304" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12305fun! s:NetrwRestoreWordPosn()
12306" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012307 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012308" call Dret("NetrwRestoreWordPosn")
12309endfun
12310
12311" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012312" s:RestoreBufVars: {{{2
12313fun! s:RestoreBufVars()
12314" call Dfunc("s:RestoreBufVars()")
12315
12316 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12317 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12318 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12319 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12320 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12321 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12322
12323" call Dret("s:RestoreBufVars")
12324endfun
12325
12326" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012327" s:RemotePathAnalysis: {{{2
12328fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012329" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012330
Bram Moolenaara6878372014-03-22 21:02:50 +010012331 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012332 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012333 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012334 let s:user = substitute(a:dirname,dirpat,'\3','')
12335 let s:machine = substitute(a:dirname,dirpat,'\4','')
12336 let s:port = substitute(a:dirname,dirpat,'\5','')
12337 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012338 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012339 if s:machine =~ '@'
12340 let dirpat = '^\(.*\)@\(.\{-}\)$'
12341 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12342 let s:machine = substitute(s:machine,dirpat,'\2','')
12343 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012344
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012345" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12346" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12347" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12348" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12349" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12350" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012351
12352" call Dret("s:RemotePathAnalysis")
12353endfun
12354
12355" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012356" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12357" Returns status
12358" Runs system() on
12359" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012360" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012361fun! s:RemoteSystem(cmd)
12362" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12363 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012364 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 +000012365 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012366 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012367 else
12368 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12369 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12370 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012371 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012372 else
12373 let cmd= cmd.' '
12374 endif
12375 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012376" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012377 let ret= system(cmd)
12378 endif
12379" call Dret("s:RemoteSystem ".ret)
12380 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012381endfun
12382
12383" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012384" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012385fun! s:RestoreWinVars()
12386" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012387 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012388 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12389 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12390 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12391 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12392 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12393 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12394 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12395 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12396 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12397 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12398 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12399 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012400 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12401 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012402 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12403 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12404 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12405" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012406endfun
12407
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012408" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012409" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12410"
12411" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12412" is true) and a command, :Rexplore, which call this function.
12413"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012414" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012415"
12416" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012417fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012418 if exists("s:netrwdrag")
12419 return
12420 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012421" 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 +010012422" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12423" 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 +010012424
12425 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012426 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012427" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012428 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012429 unlet w:netrw_rexfile
12430" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012431 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012432" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012433" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12434" 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 +020012435 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012436
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012437 " ---------------------------
12438 " :Rex issued while in a file
12439 " ---------------------------
12440
Bram Moolenaara6878372014-03-22 21:02:50 +010012441 " record current file so :Rex can return to it from netrw
12442 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012443" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012444
12445 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012446" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012447 return
12448 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012449" 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 +020012450 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012451 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012452 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012453 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012454 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012455 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012456 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012457 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012458 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012459" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12460 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012461" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12462 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012463 if exists("s:rexposn_".bufnr('%'))
12464 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012465 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012466 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012467" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012468 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012469
Bram Moolenaar85850f32019-07-19 22:05:51 +020012470 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12471 if exists("s:explore_match")
12472 exe "2match netrwMarkFile /".s:explore_match."/"
12473 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012474 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012475
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012476" 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 +010012477" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012478endfun
12479
12480" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012481" s:SaveBufVars: save selected b: variables to s: variables {{{2
12482" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012483fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012484" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012485
12486 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12487 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12488 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12489 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12490 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12491 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12492
12493" call Dret("s:SaveBufVars")
12494endfun
12495
12496" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012497" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12498fun! s:SavePosn(posndict)
12499" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12500
Bram Moolenaar85850f32019-07-19 22:05:51 +020012501 if !exists("a:posndict[bufnr('%')]")
12502 let a:posndict[bufnr("%")]= []
12503 endif
12504" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12505 call add(a:posndict[bufnr("%")],winsaveview())
12506" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012507
12508" call Dret("s:SavePosn posndict")
12509 return a:posndict
12510endfun
12511
12512" ---------------------------------------------------------------------
12513" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12514fun! s:RestorePosn(posndict)
12515" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012516 if exists("a:posndict")
12517 if has_key(a:posndict,bufnr("%"))
12518" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12519 let posnlen= len(a:posndict[bufnr("%")])
12520 if posnlen > 0
12521 let posnlen= posnlen - 1
12522" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12523 call winrestview(a:posndict[bufnr("%")][posnlen])
12524 call remove(a:posndict[bufnr("%")],posnlen)
12525" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12526 endif
12527 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012528 endif
12529" call Dret("s:RestorePosn")
12530endfun
12531
12532" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012533" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012534fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012535" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012536 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12537 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12538 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12539 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12540 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12541 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12542 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12543 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12544 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12545 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12546 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12547 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12548 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12549 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12550 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12551 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12552 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12553 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12554" call Dret("s:SaveWinVars")
12555endfun
12556
12557" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012558" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012559" To allow separate windows to have their own activities, such as
12560" Explore **/pattern, several variables have been made window-oriented.
12561" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012562" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012563" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012564fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012565" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012566 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12567 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12568 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12569 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12570 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12571 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12572 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12573 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12574 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12575 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12576" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012577endfun
12578
12579" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012580" s:SetRexDir: set directory for :Rexplore {{{2
12581fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012582" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012583 let w:netrw_rexdir = a:dirname
12584 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012585 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012586" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12587" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012588" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012589" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012590" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012591endfun
12592
12593" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012594" s:ShowLink: used to modify thin and tree listings to show links {{{2
12595fun! s:ShowLink()
12596" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012597" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12598" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012599 if exists("b:netrw_curdir")
12600 norm! $?\a
12601 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12602 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012603" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12604" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12605" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12606 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012607 let dirlen = strlen(b:netrw_curdir)
12608 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012609" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012610 endif
12611 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012612" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12613" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012614 setl noro ma
12615 call setline(".",modline)
12616 setl ro noma nomod
12617 endif
12618" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12619endfun
12620
12621" ---------------------------------------------------------------------
12622" s:ShowStyle: {{{2
12623fun! s:ShowStyle()
12624 if !exists("w:netrw_liststyle")
12625 let liststyle= g:netrw_liststyle
12626 else
12627 let liststyle= w:netrw_liststyle
12628 endif
12629 if liststyle == s:THINLIST
12630 return s:THINLIST.":thin"
12631 elseif liststyle == s:LONGLIST
12632 return s:LONGLIST.":long"
12633 elseif liststyle == s:WIDELIST
12634 return s:WIDELIST.":wide"
12635 elseif liststyle == s:TREELIST
12636 return s:TREELIST.":tree"
12637 else
12638 return 'n/a'
12639 endif
12640endfun
12641
12642" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012643" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12644" Solution from Nicolai Weibull, vim docs (:help strlen()),
12645" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012646fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012647" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12648
12649 if v:version >= 703 && exists("*strdisplaywidth")
12650 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012651
Bram Moolenaar8d043172014-01-23 14:24:41 +010012652 elseif type(g:Align_xstrlen) == 1
12653 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12654 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012655
Bram Moolenaar8d043172014-01-23 14:24:41 +010012656 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012657 " number of codepoints (Latin a + combining circumflex is two codepoints)
12658 " (comment from TM, solution from NW)
12659 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012660
Bram Moolenaar8d043172014-01-23 14:24:41 +010012661 elseif g:Align_xstrlen == 2
12662 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012663 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12664 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012665 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012666
Bram Moolenaar8d043172014-01-23 14:24:41 +010012667 elseif g:Align_xstrlen == 3
12668 " virtual length (counting, for instance, tabs as anything between 1 and
12669 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012670 " preceded by lam, one otherwise, etc.)
12671 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012672 let modkeep= &l:mod
12673 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012674 call setline(line("."),a:x)
12675 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012676 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012677 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012678 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012679
Bram Moolenaar446cb832008-06-24 21:56:24 +000012680 else
12681 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012682 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012683 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012684" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012685 return ret
12686endfun
12687
12688" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012689" s:ShellEscape: shellescape(), or special windows handling {{{2
12690fun! s:ShellEscape(s, ...)
12691 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12692 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12693 endif
12694 let f = a:0 > 0 ? a:1 : 0
12695 return shellescape(a:s, f)
12696endfun
12697
12698" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012699" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012700fun! s:TreeListMove(dir)
12701" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012702 let curline = getline('.')
12703 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12704 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12705 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12706 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12707 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12708 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12709" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12710" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12711" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12712" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12713" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12714 " COMBAK : need to handle when on a directory
12715 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012716 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012717 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012718 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012719 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012720" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012721 elseif a:dir == '[]' && nxtline != ''
12722 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012723" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012724 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12725 if nl != 0
12726 NetrwKeepj norm! k
12727 else
12728 NetrwKeepj norm! G
12729 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012730" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012731 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012732 endif
12733
12734" call Dret("s:TreeListMove")
12735endfun
12736
12737" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012738" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12739" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12740" can't be called except via emenu. But due to locale, that menu line may not be called
12741" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12742fun! s:UpdateBuffersMenu()
12743" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012744 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012745 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012746 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012747 catch /^Vim\%((\a\+)\)\=:E/
12748 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012749 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012750 endtry
12751 endif
12752" call Dret("s:UpdateBuffersMenu")
12753endfun
12754
12755" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012756" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012757" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012758fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012759" call Dfunc("s:UseBufWinVars()")
12760 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012761 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12762 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12763 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12764 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12765 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12766 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12767 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12768 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12769 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 +000012770" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012771endfun
12772
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012773" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012774" s:UserMaps: supports user-defined UserMaps {{{2
12775" * calls a user-supplied funcref(islocal,curdir)
12776" * interprets result
12777" See netrw#UserMaps()
12778fun! s:UserMaps(islocal,funcname)
12779" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12780
12781 if !exists("b:netrw_curdir")
12782 let b:netrw_curdir= getcwd()
12783 endif
12784 let Funcref = function(a:funcname)
12785 let result = Funcref(a:islocal)
12786
12787 if type(result) == 1
12788 " if result from user's funcref is a string...
12789" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12790 if result == "refresh"
12791" call Decho("refreshing display",'~'.expand("<slnum>"))
12792 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12793 elseif result != ""
12794" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12795 exe result
12796 endif
12797
12798 elseif type(result) == 3
12799 " if result from user's funcref is a List...
12800" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12801 for action in result
12802 if action == "refresh"
12803" call Decho("refreshing display",'~'.expand("<slnum>"))
12804 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12805 elseif action != ""
12806" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12807 exe action
12808 endif
12809 endfor
12810 endif
12811
12812" call Dret("s:UserMaps")
12813endfun
12814
Bram Moolenaar85850f32019-07-19 22:05:51 +020012815" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012816" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012817" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012818let &cpo= s:keepcpo
12819unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012820
Bram Moolenaar85850f32019-07-19 22:05:51 +020012821" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012822" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012823" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012824" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012825" doing autoload/netrw.vim version v172g ~57
12826" varname<g:netrw_dirhistcnt> value=0 ~1
12827" varname<s:THINLIST> value=0 ~1
12828" varname<s:LONGLIST> value=1 ~1
12829" varname<s:WIDELIST> value=2 ~1
12830" varname<s:TREELIST> value=3 ~1
12831" varname<s:MAXLIST> value=4 ~1
12832" varname<g:netrw_use_errorwindow> value=2 ~1
12833" varname<g:netrw_http_xcmd> value=-q -O ~1
12834" varname<g:netrw_http_put_cmd> value=curl -T ~1
12835" varname<g:netrw_keepj> value=keepj ~1
12836" varname<g:netrw_rcp_cmd> value=rcp ~1
12837" varname<g:netrw_rsync_cmd> value=rsync ~1
12838" varname<g:netrw_rsync_sep> value=/ ~1
12839" varname<g:netrw_scp_cmd> value=scp -q ~1
12840" varname<g:netrw_sftp_cmd> value=sftp ~1
12841" varname<g:netrw_ssh_cmd> value=ssh ~1
12842" varname<g:netrw_alto> value=0 ~1
12843" varname<g:netrw_altv> value=1 ~1
12844" varname<g:netrw_banner> value=1 ~1
12845" varname<g:netrw_browse_split> value=0 ~1
12846" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12847" varname<g:netrw_chgwin> value=-1 ~1
12848" varname<g:netrw_clipboard> value=1 ~1
12849" varname<g:netrw_compress> value=gzip ~1
12850" varname<g:netrw_ctags> value=ctags ~1
12851" varname<g:netrw_cursor> value=2 ~1
12852" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12853" varname<g:netrw_cygdrive> value=/cygdrive ~1
12854" varname<s:didstarstar> value=0 ~1
12855" varname<g:netrw_dirhistcnt> value=0 ~1
12856" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12857" varname<g:netrw_dirhistmax> value=10 ~1
12858" varname<g:netrw_errorlvl> value=0 ~1
12859" varname<g:netrw_fastbrowse> value=1 ~1
12860" 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
12861" varname<g:netrw_ftpmode> value=binary ~1
12862" varname<g:netrw_hide> value=1 ~1
12863" varname<g:netrw_keepdir> value=1 ~1
12864" varname<g:netrw_list_hide> value= ~1
12865" varname<g:netrw_localmkdir> value=mkdir ~1
12866" varname<g:netrw_remote_mkdir> value=mkdir ~1
12867" varname<g:netrw_liststyle> value=0 ~1
12868" varname<g:netrw_markfileesc> value=*./[\~ ~1
12869" varname<g:netrw_maxfilenamelen> value=32 ~1
12870" varname<g:netrw_menu> value=1 ~1
12871" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12872" varname<g:netrw_mousemaps> value=1 ~1
12873" varname<g:netrw_retmap> value=0 ~1
12874" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12875" varname<g:netrw_preview> value=0 ~1